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
00035 #include "atomic_ops_init.h"
00036 #include "atomic_ops.h"
00037
00038 #if defined ATOMIC_OPS_USE_LOCK || defined ATOMIC_OPS_USE_LOCK_SET || \
00039 defined MEMBAR_USES_LOCK
00040 #include "locking.h"
00041 #endif
00042
00043 #ifdef MEMBAR_USES_LOCK
00044 gen_lock_t* __membar_lock=0;
00045 #endif
00046
00047 #ifdef ATOMIC_OPS_USE_LOCK_SET
00048 gen_lock_set_t* _atomic_lock_set=0;
00049 #elif defined ATOMIC_OPS_USE_LOCK
00050 gen_lock_t* _atomic_lock=0;
00051 #endif
00052
00053
00054
00055 int init_atomic_ops()
00056 {
00057
00058 #ifdef MEMBAR_USES_LOCK
00059 if ((__membar_lock=lock_alloc())==0){
00060 goto error;
00061 }
00062 if (lock_init(__membar_lock)==0){
00063 lock_dealloc(__membar_lock);
00064 __membar_lock=0;
00065 goto error;
00066 }
00067 _membar_lock;
00068
00069 #endif
00070 #ifdef ATOMIC_OPS_USE_LOCK_SET
00071 if ((_atomic_lock_set=lock_set_alloc(_ATOMIC_LS_SIZE))==0){
00072 goto error;
00073 }
00074 if (lock_set_init(_atomic_lock_set)==0){
00075 lock_set_dealloc(_atomic_lock_set);
00076 _atomic_lock_set=0;
00077 goto error;
00078 }
00079 #elif defined ATOMIC_OPS_USE_LOCK
00080 if ((_atomic_lock=lock_alloc())==0){
00081 goto error;
00082 }
00083 if (lock_init(_atomic_lock)==0){
00084 lock_dealloc(_atomic_lock);
00085 _atomic_lock=0;
00086 goto error;
00087 }
00088 #endif
00089 return 0;
00090 #if defined MEMBAR_USES_LOCK || defined ATOMIC_OPS_USE_LOCK || \
00091 defined ATOMIC_OPS_USE_LOCK_SET
00092 error:
00093 destroy_atomic_ops();
00094 return -1;
00095 #endif
00096 }
00097
00098
00099
00100 void destroy_atomic_ops()
00101 {
00102 #ifdef MEMBAR_USES_LOCK
00103 if (__membar_lock!=0){
00104 lock_destroy(__membar_lock);
00105 lock_dealloc(__membar_lock);
00106 __membar_lock=0;
00107 }
00108 #endif
00109 #ifdef ATOMIC_OPS_USE_LOCK_SET
00110 if (_atomic_lock_set!=0){
00111 lock_set_destroy(_atomic_lock_set);
00112 lock_set_dealloc(_atomic_lock_set);
00113 _atomic_lock_set=0;
00114 }
00115 #elif defined ATOMIC_OPS_USE_LOCK
00116 if (_atomic_lock!=0){
00117 lock_destroy(_atomic_lock);
00118 lock_dealloc(_atomic_lock);
00119 _atomic_lock=0;
00120 }
00121 #endif
00122 }