Panda3D
atomicAdjustI386Impl.h
1 // Filename: atomicAdjustI386Impl.h
2 // Created by: drose (01Apr06)
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 ATOMICADJUSTI386IMPL_H
16 #define ATOMICADJUSTI386IMPL_H
17 
18 #include "dtoolbase.h"
19 #include "selectThreadImpl.h"
20 
21 #if (defined(__i386__) || defined(_M_IX86)) && !defined(__APPLE__)
22 
23 #include "numeric_types.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : AtomicAdjustI386Impl
27 // Description : Uses assembly-language calls to atomically increment
28 // and decrement. Although this class is named i386, it
29 // actually uses instructions that are specific to 486
30 // and higher.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_DTOOL AtomicAdjustI386Impl {
33 public:
34  typedef ALIGN_4BYTE PN_int32 Integer;
35  typedef void *UnalignedPointer;
36  typedef ALIGN_4BYTE UnalignedPointer 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 
56 #include "atomicAdjustI386Impl.I"
57 
58 #endif // __i386__
59 
60 #endif