Panda3D
atomicAdjustPosixImpl.h
1 // Filename: atomicAdjustPosixImpl.h
2 // Created by: drose (10Feb06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef ATOMICADJUSTPOSIXIMPL_H
16 #define ATOMICADJUSTPOSIXIMPL_H
17 
18 #include "dtoolbase.h"
19 #include "selectThreadImpl.h"
20 
21 #ifdef HAVE_POSIX_THREADS
22 
23 #include "numeric_types.h"
24 
25 #include <pthread.h>
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : AtomicAdjustPosixImpl
29 // Description : Uses POSIX to implement atomic adjustments.
30 ////////////////////////////////////////////////////////////////////
31 class EXPCL_DTOOL AtomicAdjustPosixImpl {
32 public:
33  // In Posix, "long" is generally the native word size (32- or
34  // 64-bit), which is what we'd prefer.
35  typedef long Integer;
36  typedef void *Pointer;
37 
38  INLINE static void inc(TVOLATILE Integer &var);
39  INLINE static bool dec(TVOLATILE Integer &var);
40  INLINE static void add(TVOLATILE Integer &var, Integer delta);
41  INLINE static Integer set(TVOLATILE Integer &var, Integer new_value);
42  INLINE static Integer get(const TVOLATILE Integer &var);
43 
44  INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value);
45  INLINE static Pointer get_ptr(const TVOLATILE Pointer &var);
46 
47  INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem,
48  Integer old_value,
49  Integer new_value);
50 
51  INLINE static Pointer compare_and_exchange_ptr(TVOLATILE Pointer &mem,
52  Pointer old_value,
53  Pointer new_value);
54 
55 private:
56  static pthread_mutex_t _mutex;
57 };
58 
59 #include "atomicAdjustPosixImpl.I"
60 
61 #endif // HAVE_POSIX_THREADS
62 
63 #endif