Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CLASP_UTIL_MUTEX_H_INCLUDED
00022 #define CLASP_UTIL_MUTEX_H_INCLUDED
00023
00024 #if WITH_THREADS
00025 #if _WIN32||_WIN64
00026 #define WIN32_LEAN_AND_MEAN // exclude APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets.
00027 #define NOMINMAX // do not let windows.h define macros min and max
00028 #endif
00029
00030 #include <tbb/mutex.h>
00031 #include <tbb/spin_mutex.h>
00032 #if defined(TBB_IMPLEMENT_CPP0X)
00033 #define RESTORE_TBB_IMPLEMENT_CPP0X TBB_IMPLEMENT_CPP0X
00034 #undef TBB_IMPLEMENT_CPP0X
00035 #endif
00036 #define TBB_IMPLEMENT_CPP0X 0
00037 #include <tbb/compat/condition_variable>
00038 #undef TBB_IMPLEMENT_CPP0X
00039 #if defined(RESTORE_TBB_IMPLEMENT_CPP0X)
00040 #define TBB_IMPLEMENT_CPP0X RESTORE_TBB_IMPLEMENT_CPP0X
00041 #undef RESTORE_TBB_IMPLEMENT_CPP0X
00042 #endif
00043 namespace Clasp {
00044 using tbb::mutex;
00045 using tbb::spin_mutex;
00046 using tbb::interface5::condition_variable;
00047 using tbb::interface5::lock_guard;
00048 using tbb::interface5::unique_lock;
00049 using tbb::interface5::swap;
00050 using tbb::interface5::defer_lock_t;
00051 }
00052 #else
00053 namespace no_multi_threading {
00054 class NullMutex {
00055 public:
00056 NullMutex() {}
00057 void lock() {}
00058 bool try_lock() { return true; }
00059 void unlock() {}
00060 private:
00061 NullMutex(const NullMutex&);
00062 NullMutex& operator=(const NullMutex&);
00063 };
00064 typedef NullMutex mutex;
00065 typedef NullMutex spin_mutex;
00066 template<typename M>
00067 class lock_guard {
00068 public:
00069 typedef M mutex_type;
00070 explicit lock_guard(mutex_type& m) : pm(m) {m.lock();}
00071 ~lock_guard() { pm.unlock(); }
00072 private:
00073 lock_guard(const lock_guard&);
00074 lock_guard& operator=(const lock_guard&);
00075 mutex_type& pm;
00076 };
00077 }
00078 namespace Clasp {
00079 using no_multi_threading::mutex;
00080 using no_multi_threading::lock_guard;
00081 using no_multi_threading::spin_mutex;
00082 }
00083 #endif
00084
00085 #endif