Panda3D
reMutexDirect.h
1 // Filename: reMutexDirect.h
2 // Created by: drose (13Feb06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef REMUTEXDIRECT_H
16 #define REMUTEXDIRECT_H
17 
18 #include "pandabase.h"
19 #include "mutexTrueImpl.h"
20 #include "conditionVarImpl.h"
21 
22 class Thread;
23 
24 #ifndef DEBUG_THREADS
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : ReMutexDirect
28 // Description : This class implements a standard reMutex by making
29 // direct calls to the underlying implementation layer.
30 // It doesn't perform any debugging operations.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_PANDA_PIPELINE ReMutexDirect {
33 protected:
34  INLINE ReMutexDirect();
35  INLINE ~ReMutexDirect();
36 private:
37  INLINE ReMutexDirect(const ReMutexDirect &copy);
38  INLINE void operator = (const ReMutexDirect &copy);
39 
40 PUBLISHED:
41  BLOCKING INLINE void acquire() const;
42  BLOCKING INLINE void acquire(Thread *current_thread) const;
43  BLOCKING INLINE bool try_acquire() const;
44  BLOCKING INLINE bool try_acquire(Thread *current_thread) const;
45  INLINE void elevate_lock() const;
46  INLINE void release() const;
47 
48  INLINE bool debug_is_locked() const;
49 
50  INLINE void set_name(const string &name);
51  INLINE void clear_name();
52  INLINE bool has_name() const;
53  INLINE string get_name() const;
54 
55  void output(ostream &out) const;
56 
57 private:
58 #ifdef HAVE_REMUTEXTRUEIMPL
59  ReMutexImpl _impl;
60 
61 #else
62  // If we don't have a reentrant mutex, we have to hand-roll one.
63  INLINE void do_acquire();
64  void do_acquire(Thread *current_thread);
65  INLINE bool do_try_acquire();
66  bool do_try_acquire(Thread *current_thread);
67  void do_elevate_lock();
68  void do_release();
69 
70  Thread *_locking_thread;
71  int _lock_count;
72 
73  MutexTrueImpl _lock_impl;
74  ConditionVarImpl _cvar_impl;
75 #endif // HAVE_REMUTEXTRUEIMPL
76 
77  friend class LightReMutexDirect;
78 };
79 
80 INLINE ostream &
81 operator << (ostream &out, const ReMutexDirect &m) {
82  m.output(out);
83  return out;
84 }
85 
86 #include "reMutexDirect.I"
87 
88 #endif // !DEBUG_THREADS
89 
90 #endif
This class implements a standard lightReMutex by making direct calls to the underlying implementation...
void output(ostream &out) const
This method is declared virtual in MutexDebug, but non-virtual in ReMutexDirect.
This class implements a standard reMutex by making direct calls to the underlying implementation laye...
Definition: reMutexDirect.h:32
A thread; that is, a lightweight process.
Definition: thread.h:51
A fake mutex implementation for single-threaded applications that don&#39;t need any synchronization cont...