Panda3D
reMutexSpinlockImpl.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 reMutexSpinlockImpl.h
10  * @author rdb
11  * @date 2018-09-03
12  */
13 
14 #ifndef REMUTEXSPINLOCKIMPL_H
15 #define REMUTEXSPINLOCKIMPL_H
16 
17 #include "dtoolbase.h"
18 #include "selectThreadImpl.h"
19 
20 #ifdef MUTEX_SPINLOCK
21 
22 #include "atomicAdjust.h"
23 
24 class Thread;
25 
26 /**
27  * Uses a simple user-space spinlock to implement a mutex. It is usually not
28  * a good idea to use this implementation, unless you are building Panda for a
29  * specific application on a specific SMP machine, and you are confident that
30  * you have at least as many CPU's as you have threads.
31  */
32 class EXPCL_PANDA_PIPELINE ReMutexSpinlockImpl {
33 public:
34  constexpr ReMutexSpinlockImpl() noexcept = default;
35  ReMutexSpinlockImpl(const ReMutexSpinlockImpl &copy) = delete;
36 
37  ReMutexSpinlockImpl &operator = (const ReMutexSpinlockImpl &copy) = delete;
38 
39 public:
40  void lock();
41  bool try_lock();
42  INLINE void unlock();
43 
44 private:
45  AtomicAdjust::Pointer _locking_thread = nullptr;
46  unsigned int _counter = 0;
47 };
48 
49 
50 #include "reMutexSpinlockImpl.I"
51 
52 #endif // MUTEX_SPINLOCK
53 
54 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A trivial implementation for atomic adjustments for systems that don't require multiprogramming,...
A thread; that is, a lightweight process.
Definition: thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.