atomicity.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _GLIBCXX_ATOMICITY_H
00031 #define _GLIBCXX_ATOMICITY_H 1
00032
00033 #include <bits/c++config.h>
00034 #include <bits/gthr.h>
00035 #include <bits/atomic_word.h>
00036
00037 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
00038
00039
00040
00041
00042
00043 #ifdef _GLIBCXX_ATOMIC_BUILTINS_4
00044 static inline _Atomic_word
00045 __exchange_and_add(volatile _Atomic_word* __mem, int __val)
00046 { return __sync_fetch_and_add(__mem, __val); }
00047
00048 static inline void
00049 __atomic_add(volatile _Atomic_word* __mem, int __val)
00050 { __sync_fetch_and_add(__mem, __val); }
00051 #else
00052 _Atomic_word
00053 __attribute__ ((__unused__))
00054 __exchange_and_add(volatile _Atomic_word*, int);
00055
00056 void
00057 __attribute__ ((__unused__))
00058 __atomic_add(volatile _Atomic_word*, int);
00059 #endif
00060
00061 static inline _Atomic_word
00062 __exchange_and_add_single(_Atomic_word* __mem, int __val)
00063 {
00064 _Atomic_word __result = *__mem;
00065 *__mem += __val;
00066 return __result;
00067 }
00068
00069 static inline void
00070 __atomic_add_single(_Atomic_word* __mem, int __val)
00071 { *__mem += __val; }
00072
00073 static inline _Atomic_word
00074 __attribute__ ((__unused__))
00075 __exchange_and_add_dispatch(_Atomic_word* __mem, int __val)
00076 {
00077 #ifdef __GTHREADS
00078 if (__gthread_active_p())
00079 return __exchange_and_add(__mem, __val);
00080 else
00081 return __exchange_and_add_single(__mem, __val);
00082 #else
00083 return __exchange_and_add_single(__mem, __val);
00084 #endif
00085 }
00086
00087 static inline void
00088 __attribute__ ((__unused__))
00089 __atomic_add_dispatch(_Atomic_word* __mem, int __val)
00090 {
00091 #ifdef __GTHREADS
00092 if (__gthread_active_p())
00093 __atomic_add(__mem, __val);
00094 else
00095 __atomic_add_single(__mem, __val);
00096 #else
00097 __atomic_add_single(__mem, __val);
00098 #endif
00099 }
00100
00101 _GLIBCXX_END_NAMESPACE
00102
00103
00104
00105
00106 #ifndef _GLIBCXX_READ_MEM_BARRIER
00107 #define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("":::"memory")
00108 #endif
00109 #ifndef _GLIBCXX_WRITE_MEM_BARRIER
00110 #define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("":::"memory")
00111 #endif
00112
00113 #endif