Panda3D
atomicAdjustPosixImpl.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 atomicAdjustPosixImpl.h
10  * @author drose
11  * @date 2006-02-10
12  */
13 
14 #ifndef ATOMICADJUSTPOSIXIMPL_H
15 #define ATOMICADJUSTPOSIXIMPL_H
16 
17 #include "dtoolbase.h"
18 #include "selectThreadImpl.h"
19 
20 #ifdef HAVE_POSIX_THREADS
21 
22 #include "numeric_types.h"
23 
24 #include <pthread.h>
25 
26 /**
27  * Uses POSIX to implement atomic adjustments.
28  */
29 class EXPCL_DTOOL_DTOOLBASE AtomicAdjustPosixImpl {
30 public:
31  // In Posix, "long" is generally the native word size (32- or 64-bit), which
32  // is what we'd prefer.
33  typedef long Integer;
34  typedef void *Pointer;
35 
36  INLINE static void inc(TVOLATILE Integer &var);
37  INLINE static bool dec(TVOLATILE Integer &var);
38  INLINE static Integer add(TVOLATILE Integer &var, Integer delta);
39  INLINE static Integer set(TVOLATILE Integer &var, Integer new_value);
40  INLINE static Integer get(const TVOLATILE Integer &var);
41 
42  INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value);
43  INLINE static Pointer get_ptr(const TVOLATILE Pointer &var);
44 
45  INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem,
46  Integer old_value,
47  Integer new_value);
48 
49  INLINE static Pointer compare_and_exchange_ptr(TVOLATILE Pointer &mem,
50  Pointer old_value,
51  Pointer new_value);
52 
53 private:
54  static pthread_mutex_t _mutex;
55 };
56 
57 #include "atomicAdjustPosixImpl.I"
58 
59 #endif // HAVE_POSIX_THREADS
60 
61 #endif
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.