clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mutex.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2012, Benjamin Kaufmann
3 //
4 // This file is part of Clasp. See http://www.cs.uni-potsdam.de/clasp/
5 //
6 // Clasp is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // Clasp is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Clasp; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 
21 #ifndef CLASP_UTIL_MUTEX_H_INCLUDED
22 #define CLASP_UTIL_MUTEX_H_INCLUDED
23 
24 #if WITH_THREADS
25 #if _WIN32||_WIN64
26 #define WIN32_LEAN_AND_MEAN // exclude APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets.
27 #define NOMINMAX // do not let windows.h define macros min and max
28 #endif
29 
30 #include <tbb/mutex.h>
31 #include <tbb/spin_mutex.h>
32 #if defined(TBB_IMPLEMENT_CPP0X)
33 #define RESTORE_TBB_IMPLEMENT_CPP0X TBB_IMPLEMENT_CPP0X
34 #undef TBB_IMPLEMENT_CPP0X
35 #endif
36 #define TBB_IMPLEMENT_CPP0X 0
37 #include <tbb/compat/condition_variable>
38 #undef TBB_IMPLEMENT_CPP0X
39 #if defined(RESTORE_TBB_IMPLEMENT_CPP0X)
40 #define TBB_IMPLEMENT_CPP0X RESTORE_TBB_IMPLEMENT_CPP0X
41 #undef RESTORE_TBB_IMPLEMENT_CPP0X
42 #endif
43 namespace Clasp {
44  using tbb::mutex;
45  using tbb::spin_mutex;
46  using tbb::interface5::condition_variable;
47  using tbb::interface5::lock_guard;
48  using tbb::interface5::unique_lock;
50  using tbb::interface5::defer_lock_t;
51 }
52 #else
53 namespace no_multi_threading {
54 class NullMutex {
55 public:
56  NullMutex() {}
57  void lock() {}
58  bool try_lock() { return true; }
59  void unlock() {}
60 private:
61  NullMutex(const NullMutex&);
62  NullMutex& operator=(const NullMutex&);
63 };
64 typedef NullMutex mutex;
66 template<typename M>
67 class lock_guard {
68 public:
69  typedef M mutex_type;
70  explicit lock_guard(mutex_type& m) : pm(m) {m.lock();}
71  ~lock_guard() { pm.unlock(); }
72 private:
73  lock_guard(const lock_guard&);
74  lock_guard& operator=(const lock_guard&);
75  mutex_type& pm;
76 };
77 }
78 namespace Clasp {
82 }
83 #endif
84 
85 #endif
~lock_guard()
Definition: mutex.h:71
bool try_lock()
Definition: mutex.h:58
Definition: mutex.h:54
void swap(Literal &l, Literal &r)
Definition: literal.h:188
NullMutex mutex
Definition: mutex.h:64
Definition: mutex.h:67
NullMutex spin_mutex
Definition: mutex.h:65
lock_guard(mutex_type &m)
Definition: mutex.h:70
void unlock()
Definition: mutex.h:59
void lock()
Definition: mutex.h:57
M mutex_type
Definition: mutex.h:69
NullMutex()
Definition: mutex.h:56