Browse Source

add get_ptr(), set_ptr()

David Rose 19 years ago
parent
commit
afb1520ea1

+ 27 - 0
dtool/src/dtoolbase/atomicAdjustDummyImpl.I

@@ -66,6 +66,33 @@ get(const PN_int32 &var) {
   return var;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: AtomicAdjustDummyImpl::set_ptr
+//       Access: Public, Static
+//  Description: Atomically changes the indicated variable and
+//               returns the original value.
+////////////////////////////////////////////////////////////////////
+INLINE void *AtomicAdjustDummyImpl::
+set_ptr(void *&var, void *new_value) {
+  void *orig_value = var;
+  var = new_value;
+  return orig_value;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AtomicAdjustDummyImpl::get_ptr
+//       Access: Public, Static
+//  Description: Atomically retrieves the snapshot value of the
+//               indicated variable.  This is the only guaranteed safe
+//               way to retrieve the value that other threads might be
+//               asynchronously setting, incrementing, or decrementing
+//               (via other AtomicAjust methods).
+////////////////////////////////////////////////////////////////////
+INLINE void *AtomicAdjustDummyImpl::
+get_ptr(void * const &var) {
+  return var;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: AtomicAdjustDummyImpl::compare_and_exchange
 //       Access: Public, Static

+ 3 - 0
dtool/src/dtoolbase/atomicAdjustDummyImpl.h

@@ -42,6 +42,9 @@ public:
   INLINE static PN_int32 set(PN_int32 &var, PN_int32 new_value);
   INLINE static PN_int32 get(const PN_int32 &var);
 
+  INLINE static void *set_ptr(void *&var, void *new_value);
+  INLINE static void *get_ptr(void * const &var);
+
   INLINE static PN_int32 compare_and_exchange(PN_int32 &mem, 
                                               PN_int32 old_value,
                                               PN_int32 new_value);

+ 27 - 0
dtool/src/dtoolbase/atomicAdjustI386Impl.I

@@ -76,6 +76,33 @@ get(const PN_int32 &var) {
   return var;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: AtomicAdjustI386Impl::set_ptr
+//       Access: Public, Static
+//  Description: Atomically changes the indicated variable and
+//               returns the original value.
+////////////////////////////////////////////////////////////////////
+INLINE void *AtomicAdjustI386Impl::
+set_ptr(void *&var, void *new_value) {
+  void *orig_value = var;
+  var = new_value;
+  return orig_value;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AtomicAdjustI386Impl::get_ptr
+//       Access: Public, Static
+//  Description: Atomically retrieves the snapshot value of the
+//               indicated variable.  This is the only guaranteed safe
+//               way to retrieve the value that other threads might be
+//               asynchronously setting, incrementing, or decrementing
+//               (via other AtomicAjust methods).
+////////////////////////////////////////////////////////////////////
+INLINE void *AtomicAdjustI386Impl::
+get_ptr(void * const &var) {
+  return var;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: AtomicAdjustI386Impl::compare_and_exchange
 //       Access: Public, Static

+ 3 - 0
dtool/src/dtoolbase/atomicAdjustI386Impl.h

@@ -43,6 +43,9 @@ public:
   INLINE static PN_int32 set(PN_int32 &var, PN_int32 new_value);
   INLINE static PN_int32 get(const PN_int32 &var);
 
+  INLINE static void *set_ptr(void *&var, void *new_value);
+  INLINE static void *get_ptr(void * const &var);
+
   INLINE static PN_int32 compare_and_exchange(volatile PN_int32 &mem, 
                                               PN_int32 old_value,
                                               PN_int32 new_value);

+ 25 - 0
dtool/src/dtoolbase/atomicAdjustNsprImpl.I

@@ -63,3 +63,28 @@ INLINE PN_int32 AtomicAdjustNsprImpl::
 get(const PN_int32 &var) {
   return var;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: AtomicAdjustNsprImpl::set_ptr
+//       Access: Public, Static
+//  Description: Atomically changes the indicated variable and
+//               returns the original value.
+////////////////////////////////////////////////////////////////////
+INLINE void *AtomicAdjustNsprImpl::
+set_ptr(void *&var, void *new_value) {
+  return PR_AtomicSet((PN_int32 *)&var, (PN_int32)new_value);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AtomicAdjustNsprImpl::get_ptr
+//       Access: Public, Static
+//  Description: Atomically retrieves the snapshot value of the
+//               indicated variable.  This is the only guaranteed safe
+//               way to retrieve the value that other threads might be
+//               asynchronously setting, incrementing, or decrementing
+//               (via other AtomicAjust methods).
+////////////////////////////////////////////////////////////////////
+INLINE void *AtomicAdjustNsprImpl::
+get_ptr(void * const &var) {
+  return var;
+}

+ 3 - 0
dtool/src/dtoolbase/atomicAdjustNsprImpl.h

@@ -38,6 +38,9 @@ public:
   INLINE static bool dec(PN_int32 &var);
   INLINE static PN_int32 set(PN_int32 &var, PN_int32 new_value);
   INLINE static PN_int32 get(const PN_int32 &var);
+
+  INLINE static void *set_ptr(void *&var, void *new_value);
+  INLINE static void *get_ptr(void * const &var);
 };
 
 #include "atomicAdjustNsprImpl.I"

+ 27 - 0
dtool/src/dtoolbase/atomicAdjustWin32Impl.I

@@ -63,3 +63,30 @@ INLINE PN_int32 AtomicAdjustWin32Impl::
 get(const PN_int32 &var) {
   return var;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: AtomicAdjustWin32Impl::set_ptr
+//       Access: Public, Static
+//  Description: Atomically changes the indicated variable and
+//               returns the original value.
+////////////////////////////////////////////////////////////////////
+INLINE void *AtomicAdjustWin32Impl::
+set_ptr(void *&var, void *new_value) {
+  void *orig_value = var;
+  var = new_value;
+  return orig_value;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AtomicAdjustWin32Impl::get_ptr
+//       Access: Public, Static
+//  Description: Atomically retrieves the snapshot value of the
+//               indicated variable.  This is the only guaranteed safe
+//               way to retrieve the value that other threads might be
+//               asynchronously setting, incrementing, or decrementing
+//               (via other AtomicAjust methods).
+////////////////////////////////////////////////////////////////////
+INLINE void *AtomicAdjustWin32Impl::
+get_ptr(void * const &var) {
+  return var;
+}

+ 3 - 0
dtool/src/dtoolbase/atomicAdjustWin32Impl.h

@@ -39,6 +39,9 @@ public:
   INLINE static bool dec(PN_int32 &var);
   INLINE static PN_int32 set(PN_int32 &var, PN_int32 new_value);
   INLINE static PN_int32 get(const PN_int32 &var);
+
+  INLINE static void *set_ptr(void *&var, void *new_value);
+  INLINE static void *get_ptr(void * const &var);
 };
 
 #include "atomicAdjustWin32Impl.I"