Panda3D
 All Classes Functions Variables Enumerations
mutexSimpleImpl.I
1 // Filename: mutexSimpleImpl.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: MutexSimpleImpl::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE MutexSimpleImpl::
22 MutexSimpleImpl() {
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: MutexSimpleImpl::Destructor
27 // Access: Public
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 INLINE MutexSimpleImpl::
31 ~MutexSimpleImpl() {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: MutexSimpleImpl::acquire
36 // Access: Public
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 INLINE void MutexSimpleImpl::
40 acquire() {
41  if (!try_acquire()) {
42  do_acquire();
43  }
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: MutexSimpleImpl::try_acquire
48 // Access: Public
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 INLINE bool MutexSimpleImpl::
52 try_acquire() {
53  if ((_flags & F_lock_count) != 0) {
54  return false;
55  }
56  _flags |= F_lock_count;
57  return true;
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: MutexSimpleImpl::release
62 // Access: Public
63 // Description: Releases the mutex. An immediate context switch
64 // might occur if there were waiters on the mutex.
65 ////////////////////////////////////////////////////////////////////
66 INLINE void MutexSimpleImpl::
67 release() {
68  nassertv((_flags & F_lock_count) != 0);
69  _flags &= ~F_lock_count;
70 
71  if (_flags & F_has_waiters) {
72  do_release();
73  }
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: MutexSimpleImpl::release_quietly
78 // Access: Public
79 // Description: Releases the mutex, without allowing a context switch
80 // to occur.
81 ////////////////////////////////////////////////////////////////////
82 INLINE void MutexSimpleImpl::
83 release_quietly() {
84  nassertv((_flags & F_lock_count) != 0);
85  _flags &= ~F_lock_count;
86 
87  if (_flags & F_has_waiters) {
88  do_release_quietly();
89  }
90 }