Panda3D

Loading...
Searching...
No Matches
mutexPosixImpl.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 mutexPosixImpl.h
10 * @author drose
11 * @date 2006-02-10
12 */
13
14#ifndef MUTEXPOSIXIMPL_H
15#define MUTEXPOSIXIMPL_H
16
17#include "dtoolbase.h"
18#include "selectThreadImpl.h"
19
20#ifdef HAVE_POSIX_THREADS
21
22#include <pthread.h>
23#include <errno.h>
24#include <assert.h>
25
26/**
27 * Uses Posix threads to implement a mutex.
28 */
29 class EXPCL_DTOOL_DTOOLBASE MutexPosixImpl {
30 public:
31 constexpr MutexPosixImpl() noexcept;
32 MutexPosixImpl(const MutexPosixImpl &copy) = delete;
33 INLINE ~MutexPosixImpl();
34
35 MutexPosixImpl &operator = (const MutexPosixImpl &copy) = delete;
36
37public:
38 INLINE void lock();
39 INLINE bool try_lock();
40 INLINE void unlock();
41
42private:
43 pthread_mutex_t _lock = PTHREAD_MUTEX_INITIALIZER;
44 friend class ConditionVarPosixImpl;
45};
46
47/**
48 * Uses Posix threads to implement a reentrant mutex.
49 */
50class EXPCL_DTOOL_DTOOLBASE ReMutexPosixImpl {
51 public:
52#ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
53 constexpr ReMutexPosixImpl() noexcept;
54#else
55 INLINE ReMutexPosixImpl();
56#endif
57 ReMutexPosixImpl(const ReMutexPosixImpl &copy) = delete;
58 INLINE ~ReMutexPosixImpl();
59
60 ReMutexPosixImpl &operator = (const ReMutexPosixImpl &copy) = delete;
61
62 public:
63 INLINE void lock();
64 INLINE bool try_lock();
65 INLINE void unlock();
66
67 private:
68 pthread_mutex_t _lock;
69};
70
71#include "mutexPosixImpl.I"
72
73#endif // HAVE_POSIX_THREADS
74
75#endif
dtoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
mutexPosixImpl.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
selectThreadImpl.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.