1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
22
* @brief APR Atomic Operations
26
#include "apr_pools.h"
33
* @defgroup apr_atomic Atomic Operations
39
* this function is required on some platforms to initialize the
40
* atomic operation's internal structures
42
* @return APR_SUCCESS on successful completion
44
APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p);
47
* Atomic operations on 32-bit values
48
* Note: Each of these functions internally implements a memory barrier
49
* on platforms that require it
53
* atomically read an apr_uint32_t from memory
54
* @param mem the pointer
56
APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem);
59
* atomically set an apr_uint32_t in memory
60
* @param mem pointer to the object
61
* @param val value that the object will assume
63
APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val);
66
* atomically add 'val' to an apr_uint32_t
67
* @param mem pointer to the object
68
* @param val amount to add
69
* @return old value pointed to by mem
71
APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val);
74
* atomically subtract 'val' from an apr_uint32_t
75
* @param mem pointer to the object
76
* @param val amount to subtract
78
APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val);
81
* atomically increment an apr_uint32_t by 1
82
* @param mem pointer to the object
83
* @return old value pointed to by mem
85
APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem);
88
* atomically decrement an apr_uint32_t by 1
89
* @param mem pointer to the atomic value
90
* @return zero if the value becomes zero on decrement, otherwise non-zero
92
APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem);
95
* compare an apr_uint32_t's value with 'cmp'.
96
* If they are the same swap the value with 'with'
97
* @param mem pointer to the value
98
* @param with what to swap it with
99
* @param cmp the value to compare it to
100
* @return the old value of *mem
102
APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
106
* exchange an apr_uint32_t's value with 'val'.
107
* @param mem pointer to the value
108
* @param val what to swap it with
109
* @return the old value of *mem
111
APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val);
114
* compare the pointer's value with cmp.
115
* If they are the same swap the value with 'with'
116
* @param mem pointer to the pointer
117
* @param with what to swap it with
118
* @param cmp the value to compare it to
119
* @return the old value of the pointer
121
APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp);
129
#endif /* !APR_ATOMIC_H */