Panda3D

atomicAdjustDummyImpl.I

00001 // Filename: atomicAdjustDummyImpl.I
00002 // Created by:  drose (09Aug02)
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 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: AtomicAdjustDummyImpl::inc
00018 //       Access: Public, Static
00019 //  Description: Atomically increments the indicated variable.
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE void AtomicAdjustDummyImpl::
00022 inc(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
00023   ++var;
00024 }
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: AtomicAdjustDummyImpl::dec
00028 //       Access: Public, Static
00029 //  Description: Atomically decrements the indicated variable and
00030 //               returns true if the new value is nonzero, false if it
00031 //               is zero.
00032 ////////////////////////////////////////////////////////////////////
00033 INLINE bool AtomicAdjustDummyImpl::
00034 dec(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
00035   return (--var) != 0;
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: AtomicAdjustDummyImpl::add
00040 //       Access: Public, Static
00041 //  Description: Atomically computes var += delta.  It is legal for
00042 //               delta to be negative.
00043 ////////////////////////////////////////////////////////////////////
00044 INLINE void AtomicAdjustDummyImpl::
00045 add(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer delta) {
00046   var += delta;
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: AtomicAdjustDummyImpl::set
00051 //       Access: Public, Static
00052 //  Description: Atomically changes the indicated variable and
00053 //               returns the original value.
00054 ////////////////////////////////////////////////////////////////////
00055 INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
00056 set(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer new_value) {
00057   Integer orig_value = var;
00058   var = new_value;
00059   return orig_value;
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: AtomicAdjustDummyImpl::get
00064 //       Access: Public, Static
00065 //  Description: Atomically retrieves the snapshot value of the
00066 //               indicated variable.  This is the only guaranteed safe
00067 //               way to retrieve the value that other threads might be
00068 //               asynchronously setting, incrementing, or decrementing
00069 //               (via other AtomicAjust methods).
00070 ////////////////////////////////////////////////////////////////////
00071 INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
00072 get(const TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
00073   return var;
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: AtomicAdjustDummyImpl::set_ptr
00078 //       Access: Public, Static
00079 //  Description: Atomically changes the indicated variable and
00080 //               returns the original value.
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE void *AtomicAdjustDummyImpl::
00083 set_ptr(void * TVOLATILE &var, void *new_value) {
00084   void *orig_value = var;
00085   var = new_value;
00086   return orig_value;
00087 }
00088 
00089 ////////////////////////////////////////////////////////////////////
00090 //     Function: AtomicAdjustDummyImpl::get_ptr
00091 //       Access: Public, Static
00092 //  Description: Atomically retrieves the snapshot value of the
00093 //               indicated variable.  This is the only guaranteed safe
00094 //               way to retrieve the value that other threads might be
00095 //               asynchronously setting, incrementing, or decrementing
00096 //               (via other AtomicAjust methods).
00097 ////////////////////////////////////////////////////////////////////
00098 INLINE void *AtomicAdjustDummyImpl::
00099 get_ptr(void * const TVOLATILE &var) {
00100   return var;
00101 }
00102 
00103 ////////////////////////////////////////////////////////////////////
00104 //     Function: AtomicAdjustDummyImpl::compare_and_exchange
00105 //       Access: Public, Static
00106 //  Description: Atomic compare and exchange.  
00107 //
00108 //               If mem is equal to old_value, store new_value in mem.
00109 //               In either case, return the original value of mem.
00110 //               The caller can test for success by comparing
00111 //               return_value == old_value.
00112 ////////////////////////////////////////////////////////////////////
00113 INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
00114 compare_and_exchange(TVOLATILE AtomicAdjustDummyImpl::Integer &mem, AtomicAdjustDummyImpl::Integer old_value,
00115                      AtomicAdjustDummyImpl::Integer new_value) {
00116   Integer orig_value = mem;
00117   if (mem == old_value) {
00118     mem = new_value;
00119   }
00120   return orig_value;
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function: AtomicAdjustDummyImpl::compare_and_exchange_ptr
00125 //       Access: Public, Static
00126 //  Description: Atomic compare and exchange.  
00127 //
00128 //               As above, but works on pointers instead of integers.
00129 ////////////////////////////////////////////////////////////////////
00130 INLINE void *AtomicAdjustDummyImpl::
00131 compare_and_exchange_ptr(void * TVOLATILE &mem, void *old_value,
00132                          void *new_value) {
00133   void *orig_value = mem;
00134   if (mem == old_value) {
00135     mem = new_value;
00136   }
00137   return orig_value;
00138 }
 All Classes Functions Variables Enumerations