Panda3D
Loading...
Searching...
No Matches
mutexDirect.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 mutexDirect.h
10 * @author drose
11 * @date 2006-02-13
12 */
13
14#ifndef MUTEXDIRECT_H
15#define MUTEXDIRECT_H
16
17#include "pandabase.h"
18#include "mutexTrueImpl.h"
19#include "pnotify.h"
20
21class Thread;
22
23#ifndef DEBUG_THREADS
24
25/**
26 * This class implements a standard mutex by making direct calls to the
27 * underlying implementation layer. It doesn't perform any debugging
28 * operations.
29 */
30class EXPCL_PANDA_PIPELINE MutexDirect {
31protected:
32 MutexDirect() = default;
33 MutexDirect(const MutexDirect &copy) = delete;
34 ~MutexDirect() = default;
35
36 void operator = (const MutexDirect &copy) = delete;
37
38public:
39 INLINE void lock();
40 INLINE bool try_lock();
41 INLINE void unlock();
42
43PUBLISHED:
44 BLOCKING INLINE void acquire() const;
45 BLOCKING INLINE bool try_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
56private:
57 mutable MutexTrueImpl _impl;
58
59 friend class ConditionVarDirect;
60 friend class ConditionVarFullDirect;
61};
62
63INLINE std::ostream &
64operator << (std::ostream &out, const MutexDirect &m) {
65 m.output(out);
66 return out;
67}
68
69#include "mutexDirect.I"
70
71#endif // !DEBUG_THREADS
72
73#endif
This class implements a standard mutex by making direct calls to the underlying implementation layer.
Definition mutexDirect.h:30
std::string get_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
void set_name(const std::string &name)
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition mutexDirect.I:98
void output(std::ostream &out) const
This method is declared virtual in MutexDebug, but non-virtual in MutexDirect.
void clear_name()
The mutex name is only defined when compiling in DEBUG_THREADS mode.
bool try_lock()
Alias for try_acquire() to match C++11 semantics.
Definition mutexDirect.I:29
void release() const
Releases the mutex.
Definition mutexDirect.I:78
bool has_name() const
The mutex name is only defined when compiling in DEBUG_THREADS mode.
void acquire() const
Grabs the mutex if it is available.
Definition mutexDirect.I:55
bool debug_is_locked() const
Returns true if the current thread has locked the Mutex, false otherwise.
Definition mutexDirect.I:90
void unlock()
Alias for release() to match C++11 semantics.
Definition mutexDirect.I:39
bool try_acquire() const
Returns immediately, with a true value indicating the mutex has been acquired, and false indicating i...
Definition mutexDirect.I:65
void lock()
Alias for acquire() to match C++11 semantics.
Definition mutexDirect.I:19
A thread; that is, a lightweight process.
Definition thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.