Panda3D
 All Classes Functions Variables Enumerations
atomicAdjustPosixImpl.h
00001 // Filename: atomicAdjustPosixImpl.h
00002 // Created by:  drose (10Feb06)
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 ATOMICADJUSTPOSIXIMPL_H
00016 #define ATOMICADJUSTPOSIXIMPL_H
00017 
00018 #include "dtoolbase.h"
00019 #include "selectThreadImpl.h"
00020 
00021 #ifdef HAVE_POSIX_THREADS
00022 
00023 #include "numeric_types.h"
00024 
00025 #include <pthread.h>
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : AtomicAdjustPosixImpl
00029 // Description : Uses POSIX to implement atomic adjustments.
00030 ////////////////////////////////////////////////////////////////////
00031 class EXPCL_DTOOL AtomicAdjustPosixImpl {
00032 public:
00033   // In Posix, "long" is generally the native word size (32- or
00034   // 64-bit), which is what we'd prefer.
00035   typedef long Integer;
00036   typedef void *Pointer;
00037 
00038   INLINE static void inc(TVOLATILE Integer &var);
00039   INLINE static bool dec(TVOLATILE Integer &var);
00040   INLINE static void add(TVOLATILE Integer &var, Integer delta);
00041   INLINE static Integer set(TVOLATILE Integer &var, Integer new_value);
00042   INLINE static Integer get(const TVOLATILE Integer &var);
00043 
00044   INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value);
00045   INLINE static Pointer get_ptr(const TVOLATILE Pointer &var);
00046 
00047   INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem, 
00048                                              Integer old_value,
00049                                              Integer new_value);
00050   
00051   INLINE static Pointer compare_and_exchange_ptr(TVOLATILE Pointer &mem, 
00052                                                  Pointer old_value,
00053                                                  Pointer new_value);
00054 
00055 private:
00056   static pthread_mutex_t _mutex;
00057 };
00058 
00059 #include "atomicAdjustPosixImpl.I"
00060 
00061 #endif  // HAVE_POSIX_THREADS
00062 
00063 #endif
 All Classes Functions Variables Enumerations