Panda3D
Loading...
Searching...
No Matches
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 */
17INLINE LightReMutexHolder::
18LightReMutexHolder(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 */
29INLINE LightReMutexHolder::
30LightReMutexHolder(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 */
45INLINE LightReMutexHolder::
46LightReMutexHolder(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 */
59INLINE LightReMutexHolder::
60~LightReMutexHolder() {
61#if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
62 _mutex->release();
63#endif
64}
void acquire() const
Grabs the lightReMutex if it is available.
A lightweight reentrant mutex.
A thread; that is, a lightweight process.
Definition thread.h:46