Panda3D
 All Classes Functions Variables Enumerations
mutexSimpleImpl.h
1 // Filename: mutexSimpleImpl.h
2 // Created by: drose (19Jun07)
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 MUTEXSIMPLEIMPL_H
16 #define MUTEXSIMPLEIMPL_H
17 
18 #include "pandabase.h"
19 #include "selectThreadImpl.h"
20 
21 #ifdef THREAD_SIMPLE_IMPL
22 
23 #include "blockerSimple.h"
24 #include "threadSimpleImpl.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : MutexSimpleImpl
28 // Description : This is the mutex implementation for the simple,
29 // simulated threads case. It's designed to be as
30 // lightweight as possible, of course. This
31 // implementation simply yields the thread when the
32 // mutex would block.
33 //
34 // We can't define this class in dtoolbase along with
35 // the other mutex implementations, because this
36 // implementation requires knowing about the
37 // SimpleThreadManager. This complicates the
38 // MutexDirect and MutexDebug definitions (we have to
39 // define a MutexImpl, for code before pipeline to
40 // use--which maps to MutexDummyImpl--and a
41 // MutexTrueImpl, for code after pipeline to use--which
42 // maps to this class, MutexSimpleImpl).
43 ////////////////////////////////////////////////////////////////////
44 class EXPCL_PANDA_PIPELINE MutexSimpleImpl : public BlockerSimple {
45 public:
46  INLINE MutexSimpleImpl();
47  INLINE ~MutexSimpleImpl();
48 
49  INLINE void acquire();
50  INLINE bool try_acquire();
51  INLINE void release();
52  INLINE void release_quietly();
53 
54 private:
55  void do_acquire();
56  void do_release();
57  void do_release_quietly();
58 
59  friend class ThreadSimpleManager;
60 };
61 
62 #include "mutexSimpleImpl.I"
63 
64 #endif // THREAD_SIMPLE_IMPL
65 
66 #endif