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