00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. 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 #ifndef APR_ATOMIC_H 00018 #define APR_ATOMIC_H 00019 00020 /** 00021 * @file apr_atomic.h 00022 * @brief APR Atomic Operations 00023 */ 00024 00025 #include "apr.h" 00026 #include "apr_pools.h" 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif 00031 00032 /** 00033 * @defgroup apr_atomic Atomic Operations 00034 * @ingroup APR 00035 * @{ 00036 */ 00037 00038 /** 00039 * this function is required on some platforms to initialize the 00040 * atomic operation's internal structures 00041 * @param p pool 00042 * @return APR_SUCCESS on successful completion 00043 * @remark Programs do NOT need to call this directly. APR will call this 00044 * automatically from apr_initialize(). 00045 * @internal 00046 */ 00047 APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p); 00048 00049 /* 00050 * Atomic operations on 32-bit values 00051 * Note: Each of these functions internally implements a memory barrier 00052 * on platforms that require it 00053 */ 00054 00055 /** 00056 * atomically read an apr_uint32_t from memory 00057 * @param mem the pointer 00058 */ 00059 APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem); 00060 00061 /** 00062 * atomically set an apr_uint32_t in memory 00063 * @param mem pointer to the object 00064 * @param val value that the object will assume 00065 */ 00066 APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val); 00067 00068 /** 00069 * atomically add 'val' to an apr_uint32_t 00070 * @param mem pointer to the object 00071 * @param val amount to add 00072 * @return old value pointed to by mem 00073 */ 00074 APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val); 00075 00076 /** 00077 * atomically subtract 'val' from an apr_uint32_t 00078 * @param mem pointer to the object 00079 * @param val amount to subtract 00080 */ 00081 APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val); 00082 00083 /** 00084 * atomically increment an apr_uint32_t by 1 00085 * @param mem pointer to the object 00086 * @return old value pointed to by mem 00087 */ 00088 APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem); 00089 00090 /** 00091 * atomically decrement an apr_uint32_t by 1 00092 * @param mem pointer to the atomic value 00093 * @return zero if the value becomes zero on decrement, otherwise non-zero 00094 */ 00095 APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem); 00096 00097 /** 00098 * compare an apr_uint32_t's value with 'cmp'. 00099 * If they are the same swap the value with 'with' 00100 * @param mem pointer to the value 00101 * @param with what to swap it with 00102 * @param cmp the value to compare it to 00103 * @return the old value of *mem 00104 */ 00105 APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with, 00106 apr_uint32_t cmp); 00107 00108 /** 00109 * exchange an apr_uint32_t's value with 'val'. 00110 * @param mem pointer to the value 00111 * @param val what to swap it with 00112 * @return the old value of *mem 00113 */ 00114 APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val); 00115 00116 /* 00117 * Atomic operations on 64-bit values 00118 * Note: Each of these functions internally implements a memory barrier 00119 * on platforms that require it 00120 */ 00121 00122 /** 00123 * atomically read an apr_uint64_t from memory 00124 * @param mem the pointer 00125 */ 00126 APR_DECLARE(apr_uint64_t) apr_atomic_read64(volatile apr_uint64_t *mem); 00127 00128 /** 00129 * atomically set an apr_uint64_t in memory 00130 * @param mem pointer to the object 00131 * @param val value that the object will assume 00132 */ 00133 APR_DECLARE(void) apr_atomic_set64(volatile apr_uint64_t *mem, apr_uint64_t val); 00134 00135 /** 00136 * atomically add 'val' to an apr_uint64_t 00137 * @param mem pointer to the object 00138 * @param val amount to add 00139 * @return old value pointed to by mem 00140 */ 00141 APR_DECLARE(apr_uint64_t) apr_atomic_add64(volatile apr_uint64_t *mem, apr_uint64_t val); 00142 00143 /** 00144 * atomically subtract 'val' from an apr_uint64_t 00145 * @param mem pointer to the object 00146 * @param val amount to subtract 00147 */ 00148 APR_DECLARE(void) apr_atomic_sub64(volatile apr_uint64_t *mem, apr_uint64_t val); 00149 00150 /** 00151 * atomically increment an apr_uint64_t by 1 00152 * @param mem pointer to the object 00153 * @return old value pointed to by mem 00154 */ 00155 APR_DECLARE(apr_uint64_t) apr_atomic_inc64(volatile apr_uint64_t *mem); 00156 00157 /** 00158 * atomically decrement an apr_uint64_t by 1 00159 * @param mem pointer to the atomic value 00160 * @return zero if the value becomes zero on decrement, otherwise non-zero 00161 */ 00162 APR_DECLARE(int) apr_atomic_dec64(volatile apr_uint64_t *mem); 00163 00164 /** 00165 * compare an apr_uint64_t's value with 'cmp'. 00166 * If they are the same swap the value with 'with' 00167 * @param mem pointer to the value 00168 * @param with what to swap it with 00169 * @param cmp the value to compare it to 00170 * @return the old value of *mem 00171 */ 00172 APR_DECLARE(apr_uint64_t) apr_atomic_cas64(volatile apr_uint64_t *mem, apr_uint64_t with, 00173 apr_uint64_t cmp); 00174 00175 /** 00176 * exchange an apr_uint64_t's value with 'val'. 00177 * @param mem pointer to the value 00178 * @param val what to swap it with 00179 * @return the old value of *mem 00180 */ 00181 APR_DECLARE(apr_uint64_t) apr_atomic_xchg64(volatile apr_uint64_t *mem, apr_uint64_t val); 00182 00183 /** 00184 * compare the pointer's value with cmp. 00185 * If they are the same swap the value with 'with' 00186 * @param mem pointer to the pointer 00187 * @param with what to swap it with 00188 * @param cmp the value to compare it to 00189 * @return the old value of the pointer 00190 */ 00191 APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp); 00192 00193 /** 00194 * exchange a pair of pointer values 00195 * @param mem pointer to the pointer 00196 * @param with what to swap it with 00197 * @return the old value of the pointer 00198 */ 00199 APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with); 00200 00201 /** @} */ 00202 00203 #ifdef __cplusplus 00204 } 00205 #endif 00206 00207 #endif /* !APR_ATOMIC_H */
1.5.6