Panda3D
Loading...
Searching...
No Matches
mutexSimpleImpl.I
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file mutexSimpleImpl.I
10 * @author drose
11 * @date 2007-06-19
12 */
13
14/**
15 *
16 */
17INLINE void MutexSimpleImpl::
18lock() {
19 if (!try_lock()) {
20 do_lock();
21 }
22}
23
24/**
25 *
26 */
27INLINE bool MutexSimpleImpl::
28try_lock() {
29 if ((_flags & F_lock_count) != 0) {
30 return false;
31 }
32 _flags |= F_lock_count;
33 return true;
34}
35
36/**
37 * Releases the mutex. An immediate context switch might occur if there were
38 * waiters on the mutex.
39 */
40INLINE void MutexSimpleImpl::
41unlock() {
42 nassertv((_flags & F_lock_count) != 0);
43 _flags &= ~F_lock_count;
44
45 if (_flags & F_has_waiters) {
46 do_unlock();
47 }
48}
49
50/**
51 * Releases the mutex, without allowing a context switch to occur.
52 */
53INLINE void MutexSimpleImpl::
54unlock_quietly() {
55 nassertv((_flags & F_lock_count) != 0);
56 _flags &= ~F_lock_count;
57
58 if (_flags & F_has_waiters) {
59 do_unlock_quietly();
60 }
61}