mutex.h
Go to the documentation of this file.
00001 // 
00002 // Copyright (c) 2012, Benjamin Kaufmann
00003 // 
00004 // This file is part of Clasp. See http://www.cs.uni-potsdam.de/clasp/ 
00005 // 
00006 // Clasp is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // Clasp is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with Clasp; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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


clasp
Author(s): Benjamin Kaufmann
autogenerated on Thu Aug 27 2015 12:41:39