Panda3D
lightReMutexHolder.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 lightReMutexHolder.I
10  * @author drose
11  * @date 2008-10-08
12  */
13 
14 /**
15  *
16  */
17 INLINE LightReMutexHolder::
18 LightReMutexHolder(const LightReMutex &mutex) {
19 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
20  _mutex = &mutex;
21  _mutex->acquire();
22 #endif
23 }
24 
25 /**
26  * This variant on the constructor accepts the current thread as a parameter,
27  * if it is already known, as an optimization.
28  */
29 INLINE LightReMutexHolder::
30 LightReMutexHolder(const LightReMutex &mutex, Thread *current_thread) {
31 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
32  _mutex = &mutex;
33  _mutex->acquire(current_thread);
34 #endif
35 }
36 
37 /**
38  * If the LightReMutexHolder constructor is given a pointer to a LightReMutex
39  * object (instead of an actual object), it will first check to see if the
40  * pointer is NULL, and allocate a new LightReMutex if it is. This is
41  * intended as a convenience for functions that may need to reference a
42  * LightReMutex at static init time, when it is impossible to guarantee
43  * ordering of initializers.
44  */
45 INLINE LightReMutexHolder::
46 LightReMutexHolder(LightReMutex *&mutex) {
47 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
48  if (mutex == nullptr) {
49  mutex = new LightReMutex;
50  }
51  _mutex = mutex;
52  _mutex->acquire();
53 #endif
54 }
55 
56 /**
57  *
58  */
59 INLINE LightReMutexHolder::
60 ~LightReMutexHolder() {
61 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
62  _mutex->release();
63 #endif
64 }
A lightweight reentrant mutex.
Definition: lightReMutex.h:30
A thread; that is, a lightweight process.
Definition: thread.h:46
void acquire() const
Grabs the lightReMutex if it is available.