Panda3D
Loading...
Searching...
No Matches
lightMutexHolder.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 lightMutexHolder.I
10 * @author drose
11 * @date 2008-10-08
12 */
13
14/**
15 *
16 */
17INLINE LightMutexHolder::
18LightMutexHolder(const LightMutex &mutex) {
19#if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
20 _mutex = &mutex;
21 _mutex->acquire();
22#endif
23}
24
25/**
26 * If the LightMutexHolder constructor is given a pointer to a LightMutex
27 * object (instead of an actual object), it will first check to see if the
28 * pointer is NULL, and allocate a new LightMutex if it is. This is intended
29 * as a convenience for functions that may need to reference a LightMutex at
30 * static init time, when it is impossible to guarantee ordering of
31 * initializers.
32 */
33INLINE LightMutexHolder::
34LightMutexHolder(LightMutex *&mutex) {
35#if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
36 if (mutex == nullptr) {
37 mutex = new LightMutex;
38 }
39 _mutex = mutex;
40 _mutex->acquire();
41#endif
42}
43
44/**
45 *
46 */
47INLINE LightMutexHolder::
48~LightMutexHolder() {
49#if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
50 _mutex->release();
51#endif
52}
void acquire() const
Grabs the lightMutex if it is available.
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition lightMutex.h:41