merged volatile memory barriers
[cacao.git] / src / threads / mutex.hpp
index e8bbce33cbae7e69926bd38176d5acd496ef0722..d4e7c6b1112148eeced9609fa176edf35e0ee0ee 100644 (file)
 # include "threads/posix/mutex-posix.hpp"
 #endif
 
+#if __cplusplus
+
+/**
+ * Helper class used to implicitly acquire and release a mutex
+ * within a method scope.
+ */
+class MutexLocker {
+private:
+       Mutex& _mutex;
+
+public:
+       MutexLocker(Mutex& mutex) : _mutex(mutex) { _mutex.lock(); }
+       ~MutexLocker()                            { _mutex.unlock(); }
+};
+
+#endif
+
 #endif /* _MUTEX_HPP */