Atomic-fake.h

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 #ifndef _OASYS_ATOMIC_FAKE_H_
00019 #define _OASYS_ATOMIC_FAKE_H_
00020 
00032 #include "../debug/DebugUtils.h"
00033 #include "../util/Singleton.h"
00034 
00035 namespace oasys {
00036 
00040 struct atomic_t {
00041     atomic_t(u_int32_t v = 0) : value(v) {}
00042 
00043     volatile u_int32_t value;
00044 };
00045 
00053 static inline void
00054 atomic_add(volatile atomic_t *v, u_int32_t i)
00055 {
00056     v->value += i;
00057 }
00058 
00065 static inline void
00066 atomic_sub(volatile atomic_t* v, u_int32_t i)
00067 {
00068     v->value -= i;
00069 }
00070 
00076 static inline void
00077 atomic_incr(volatile atomic_t* v)
00078 {
00079     v->value++;
00080 }
00081 
00088 static inline void
00089 atomic_decr(volatile atomic_t* v)
00090 {
00091     v->value--;
00092 }
00093 
00103 static inline bool
00104 atomic_decr_test(volatile atomic_t* v)
00105 {
00106     v->value--;
00107     return (v->value == 0);
00108 }
00109 
00120 static inline u_int32_t
00121 atomic_cmpxchg32(volatile atomic_t* v, u_int32_t o, u_int32_t n)
00122 {
00123     u_int32_t ret = v->value;
00124     
00125     if (v->value == o) {
00126         v->value = n;
00127     }
00128     
00129     return ret; 
00130 }
00131 
00137 static inline u_int32_t
00138 atomic_incr_ret(volatile atomic_t* v)
00139 {
00140     v->value++;
00141     return v->value;
00142 }
00143 
00150 static inline u_int32_t
00151 atomic_add_ret(volatile atomic_t* v, u_int32_t i)
00152 {
00153     v->value += i;
00154     return v->value;
00155 }
00156 
00157 } // namespace oasys
00158 
00159 #endif /* _OASYS_ATOMIC_FAKE_H_ */

Generated on Sat Sep 8 08:36:15 2007 for DTN Reference Implementation by  doxygen 1.5.3