Panda3D

Loading...
Searching...
No Matches
lightMutexDirect.h
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 lightMutexDirect.h
10 * @author drose
11 * @date 2008-10-08
12 */
13
14#ifndef LIGHTMUTEXDIRECT_H
15#define LIGHTMUTEXDIRECT_H
16
17#include "pandabase.h"
18#include "mutexImpl.h"
19#include "mutexTrueImpl.h"
20#include "pnotify.h"
21
22 class Thread;
23
24#ifndef DEBUG_THREADS
25
26/**
27 * This class implements a lightweight Mutex by making direct calls to the
28 * underlying implementation layer. It doesn't perform any debugging
29 * operations.
30 */
31 class EXPCL_PANDA_PIPELINE LightMutexDirect {
32 protected:
33 LightMutexDirect() = default;
34 LightMutexDirect(const LightMutexDirect &copy) = delete;
35 ~LightMutexDirect() = default;
36
37 void operator = (const LightMutexDirect &copy) = delete;
38
39 public:
40 INLINE void lock();
41 INLINE bool try_lock();
42 INLINE void unlock();
43
44PUBLISHED:
45 BLOCKING INLINE void acquire() const;
46 INLINE void release() const;
47 INLINE bool debug_is_locked() const;
48
49 INLINE void set_name(const std::string &name);
50 INLINE void clear_name();
51 INLINE bool has_name() const;
52 INLINE std::string get_name() const;
53
54 void output(std::ostream &out) const;
55
56 private:
57#ifdef DO_PSTATS
58 // When PStats is compiled in, we use the full implementation of LightMutex,
59 // even in the SIMPLE_THREADS case. We have to do this since any PStatTimer
60 // call may trigger a context switch, and any low-level context switch
61 // requires all containing mutexes to be true mutexes.
62 mutable MutexTrueImpl _impl;
63#else
64 mutable MutexImpl _impl;
65#endif // DO_PSTATS
66};
67
68INLINE std::ostream &
69operator << (std::ostream &out, const LightMutexDirect &m) {
70 m.output(out);
71 return out;
72}
73
74#include "lightMutexDirect.I"
75
76#endif // !DEBUG_THREADS
77
78#endif
LightMutexDirect
This class implements a lightweight Mutex by making direct calls to the underlying implementation lay...
Definition lightMutexDirect.h:31
LightMutexDirect::has_name
bool has_name() const
The lightMutex name is only defined when compiling in DEBUG_THREADS mode.
Definition lightMutexDirect.I:103
LightMutexDirect::debug_is_locked
bool debug_is_locked() const
Returns true if the current thread has locked the LightMutex, false otherwise.
Definition lightMutexDirect.I:81
LightMutexDirect::clear_name
void clear_name()
The lightMutex name is only defined when compiling in DEBUG_THREADS mode.
Definition lightMutexDirect.I:96
LightMutexDirect::unlock
void unlock()
Alias for release() to match C++11 semantics.
Definition lightMutexDirect.I:39
LightMutexDirect::lock
void lock()
Alias for acquire() to match C++11 semantics.
Definition lightMutexDirect.I:19
LightMutexDirect::set_name
void set_name(const std::string &name)
The lightMutex name is only defined when compiling in DEBUG_THREADS mode.
Definition lightMutexDirect.I:89
LightMutexDirect::release
void release() const
Releases the lightMutex.
Definition lightMutexDirect.I:69
LightMutexDirect::output
void output(std::ostream &out) const
This method is declared virtual in LightMutexDebug, but non-virtual in LightMutexDirect.
Definition lightMutexDirect.cxx:23
LightMutexDirect::get_name
std::string get_name() const
The lightMutex name is only defined when compiling in DEBUG_THREADS mode.
Definition lightMutexDirect.I:111
LightMutexDirect::acquire
void acquire() const
Grabs the lightMutex if it is available.
Definition lightMutexDirect.I:56
LightMutexDirect::try_lock
bool try_lock()
Alias for try_acquire() to match C++11 semantics.
Definition lightMutexDirect.I:29
Thread
A thread; that is, a lightweight process.
Definition thread.h:46
lightMutexDirect.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
mutexImpl.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
mutexTrueImpl.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.