Atomic-mutex.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #include "config.h"
00019 
00020 #ifdef OASYS_ATOMIC_MUTEX
00021 
00022 #include "Atomic-mutex.h"
00023 #include "Mutex.h"
00024 
00025 namespace oasys {
00026 
00031 Mutex g_atomic_mutex("/XXX/ATOMIC_MUTEX_UNUSED_LOGGER",
00032                      Mutex::TYPE_FAST,
00033                      true /* keep_quiet */);
00034 
00038 Mutex* atomic_mutex() { return &g_atomic_mutex; }
00039 
00040 //----------------------------------------------------------------------
00041 void
00042 atomic_add(volatile atomic_t *v, u_int32_t i)
00043 {
00044     ScopeLock l(atomic_mutex(), "atomic_add");
00045     v->value += i;
00046 }
00047 
00048 //----------------------------------------------------------------------
00049 void
00050 atomic_sub(volatile atomic_t* v, u_int32_t i)
00051 {
00052     ScopeLock l(atomic_mutex(), "atomic_sub");
00053     v->value -= i;
00054 }
00055 
00056 //----------------------------------------------------------------------
00057 void
00058 atomic_incr(volatile atomic_t* v)
00059 {
00060     ScopeLock l(atomic_mutex(), "atomic_incr");
00061     v->value++;
00062 }
00063 
00064 //----------------------------------------------------------------------
00065 void
00066 atomic_decr(volatile atomic_t* v)
00067 {
00068     ScopeLock l(atomic_mutex(), "atomic_decr");
00069     v->value--;
00070 }
00071 
00072 //----------------------------------------------------------------------
00073 bool
00074 atomic_decr_test(volatile atomic_t* v)
00075 {
00076     ScopeLock l(atomic_mutex(), "atomic_decr_test");
00077     v->value--;
00078     return (v->value == 0);
00079 }
00080 
00081 //----------------------------------------------------------------------
00082 u_int32_t
00083 atomic_cmpxchg32(volatile atomic_t* v, u_int32_t o, u_int32_t n)
00084 {
00085     ScopeLock l(atomic_mutex(), "atomic_cmpxchg32");
00086     u_int32_t ret = v->value;
00087 
00088     if (v->value == o) {
00089         v->value = n;
00090     }
00091 
00092     return ret;
00093 }
00094 
00095 //----------------------------------------------------------------------
00096 u_int32_t
00097 atomic_incr_ret(volatile atomic_t* v)
00098 {
00099     ScopeLock l(atomic_mutex(), "atomic_incr_ret");
00100     v->value++;
00101     return v->value;
00102 }
00103 
00104 //----------------------------------------------------------------------
00105 u_int32_t
00106 atomic_add_ret(volatile atomic_t* v, u_int32_t i)
00107 {
00108     ScopeLock l(atomic_mutex(), "atomic_add_ret");
00109     v->value += i;
00110     return v->value;
00111 }
00112 
00113 } // namespace oasys
00114 
00115 #endif /* OASYS_ATOMIC_MUTEX */

Generated on Sat Sep 8 08:43:23 2007 for DTN Reference Implementation by  doxygen 1.5.3