From a15cf65c44d5c224169c32ef5495b68c758134b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 18 May 2014 16:08:14 +0200 Subject: Imported Upstream version 3.3.0.2 --- libcult/cult/sched/lock.hxx | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 libcult/cult/sched/lock.hxx (limited to 'libcult/cult/sched/lock.hxx') diff --git a/libcult/cult/sched/lock.hxx b/libcult/cult/sched/lock.hxx new file mode 100644 index 0000000..1ecf3fb --- /dev/null +++ b/libcult/cult/sched/lock.hxx @@ -0,0 +1,58 @@ +// file : cult/sched/lock.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Boris Kolpackov +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef CULT_SCHED_LOCK_HXX +#define CULT_SCHED_LOCK_HXX + +#include + +namespace Cult +{ + namespace Sched + { + class Lock: public NonCopyable + { + public: + ~Lock () + { + unlock (); + } + + template + Lock (X& x) + : x_ (reinterpret_cast(&x)), + unlock_ (&unlock), + locked_ (true) + { + x.lock (); + } + + Void + unlock () + { + if (locked_) + { + unlock_ (x_); + locked_ = false; + } + } + + private: + template + static Void + unlock (Void* p) + { + reinterpret_cast (p)->unlock (); + } + + private: + Void* x_; + Void (*unlock_) (Void*); + Boolean locked_; + }; + } +} + +#endif // CULT_SCHED_LOCK_HXX -- cgit v1.2.3