Panda3D

atomicAdjustWin32Impl.h

00001 // Filename: atomicAdjustWin32Impl.h
00002 // Created by:  drose (07Feb06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef ATOMICADJUSTWIN32IMPL_H
00016 #define ATOMICADJUSTWIN32IMPL_H
00017 
00018 #include "dtoolbase.h"
00019 #include "selectThreadImpl.h"
00020 
00021 #ifdef WIN32_VC
00022 
00023 #include "numeric_types.h"
00024 #define WIN32_LEAN_AND_MEAN
00025 #include <windows.h>
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : AtomicAdjustWin32Impl
00029 // Description : Uses Windows native calls to implement atomic
00030 //               adjustments.
00031 ////////////////////////////////////////////////////////////////////
00032 class EXPCL_DTOOL AtomicAdjustWin32Impl {
00033 public:
00034 #ifdef _WIN64
00035   // For 64-bit builds, we'd prefer to use a 64-bit integer.
00036   typedef ALIGN_8BYTE LONGLONG Integer;
00037   typedef void *UnalignedPointer;
00038   typedef ALIGN_8BYTE UnalignedPointer Pointer;
00039 #else
00040   typedef ALIGN_4BYTE LONG Integer;
00041   typedef void *UnalignedPointer;
00042   typedef ALIGN_4BYTE UnalignedPointer Pointer;
00043 #endif  // _WIN64
00044 
00045   INLINE static void inc(TVOLATILE Integer &var);
00046   INLINE static bool dec(TVOLATILE Integer &var);
00047   INLINE static void add(TVOLATILE Integer &var, Integer delta);
00048   INLINE static Integer set(TVOLATILE Integer &var, Integer new_value);
00049   INLINE static Integer get(const TVOLATILE Integer &var);
00050 
00051   INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value);
00052   INLINE static Pointer get_ptr(const TVOLATILE Pointer &var);
00053 
00054   INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem, 
00055                                              Integer old_value,
00056                                              Integer new_value);
00057   
00058   INLINE static Pointer compare_and_exchange_ptr(TVOLATILE Pointer &mem, 
00059                                                  Pointer old_value,
00060                                                  Pointer new_value);
00061 };
00062 
00063 #include "atomicAdjustWin32Impl.I"
00064 
00065 #endif  // WIN32_VC
00066 
00067 #endif
 All Classes Functions Variables Enumerations