Panda3D
 All Classes Functions Variables Enumerations
atomicAdjustWin32Impl.h
1 // Filename: atomicAdjustWin32Impl.h
2 // Created by: drose (07Feb06)
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 ATOMICADJUSTWIN32IMPL_H
16 #define ATOMICADJUSTWIN32IMPL_H
17 
18 #include "dtoolbase.h"
19 #include "selectThreadImpl.h"
20 
21 #ifdef WIN32_VC
22 
23 #include "numeric_types.h"
24 
25 #ifndef WIN32_LEAN_AND_MEAN
26 #define WIN32_LEAN_AND_MEAN 1
27 #endif
28 #include <windows.h>
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : AtomicAdjustWin32Impl
32 // Description : Uses Windows native calls to implement atomic
33 // adjustments.
34 ////////////////////////////////////////////////////////////////////
35 class EXPCL_DTOOL AtomicAdjustWin32Impl {
36 public:
37 #ifdef _WIN64
38  // For 64-bit builds, we'd prefer to use a 64-bit integer.
39  typedef ALIGN_8BYTE LONGLONG Integer;
40  typedef void *UnalignedPointer;
41  typedef ALIGN_8BYTE UnalignedPointer Pointer;
42 #else
43  typedef ALIGN_4BYTE LONG Integer;
44  typedef void *UnalignedPointer;
45  typedef ALIGN_4BYTE UnalignedPointer Pointer;
46 #endif // _WIN64
47 
48  INLINE static void inc(TVOLATILE Integer &var);
49  INLINE static bool dec(TVOLATILE Integer &var);
50  INLINE static void add(TVOLATILE Integer &var, Integer delta);
51  INLINE static Integer set(TVOLATILE Integer &var, Integer new_value);
52  INLINE static Integer get(const TVOLATILE Integer &var);
53 
54  INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value);
55  INLINE static Pointer get_ptr(const TVOLATILE Pointer &var);
56 
57  INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem,
58  Integer old_value,
59  Integer new_value);
60 
61  INLINE static Pointer compare_and_exchange_ptr(TVOLATILE Pointer &mem,
62  Pointer old_value,
63  Pointer new_value);
64 };
65 
66 #include "atomicAdjustWin32Impl.I"
67 
68 #endif // WIN32_VC
69 
70 #endif