Panda3D
lightMutexDirect.h
1 // Filename: lightMutexDirect.h
2 // Created by: drose (08Oct08)
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 LIGHTMUTEXDIRECT_H
16 #define LIGHTMUTEXDIRECT_H
17 
18 #include "pandabase.h"
19 #include "mutexImpl.h"
20 #include "mutexTrueImpl.h"
21 #include "pnotify.h"
22 
23 class Thread;
24 
25 #ifndef DEBUG_THREADS
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : LightMutexDirect
29 // Description : This class implements a lightweight Mutex by making
30 // direct calls to the underlying implementation layer.
31 // It doesn't perform any debugging operations.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_PANDA_PIPELINE LightMutexDirect {
34 protected:
35  INLINE LightMutexDirect();
36  INLINE ~LightMutexDirect();
37 private:
38  INLINE LightMutexDirect(const LightMutexDirect &copy);
39  INLINE void operator = (const LightMutexDirect &copy);
40 
41 PUBLISHED:
42  BLOCKING INLINE void acquire() const;
43  INLINE void release() const;
44  INLINE bool debug_is_locked() const;
45 
46  INLINE void set_name(const string &name);
47  INLINE void clear_name();
48  INLINE bool has_name() const;
49  INLINE string get_name() const;
50 
51  void output(ostream &out) const;
52 
53 private:
54 #ifdef DO_PSTATS
55  // When PStats is compiled in, we use the full implementation of
56  // LightMutex, even in the SIMPLE_THREADS case. We have to do this
57  // since any PStatTimer call may trigger a context switch, and any
58  // low-level context switch requires all containing mutexes to be
59  // true mutexes.
60  MutexTrueImpl _impl;
61 #else
62  MutexImpl _impl;
63 #endif // DO_PSTATS
64 };
65 
66 INLINE ostream &
67 operator << (ostream &out, const LightMutexDirect &m) {
68  m.output(out);
69  return out;
70 }
71 
72 #include "lightMutexDirect.I"
73 
74 #endif // !DEBUG_THREADS
75 
76 #endif
This class implements a lightweight Mutex by making direct calls to the underlying implementation lay...
void output(ostream &out) const
This method is declared virtual in LightMutexDebug, but non-virtual in LightMutexDirect.
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...