add get_ptr(), set_ptr()

This commit is contained in:
David Rose 2006-04-09 20:03:22 +00:00
parent 6f77ca5044
commit afb1520ea1
8 changed files with 118 additions and 0 deletions

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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"

View File

@ -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;
}

View File

@ -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"