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.
19
#include "apr_atomic.h"
23
apr_status_t apr_atomic_init(apr_pool_t *p)
28
apr_uint32_t apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
30
apr_uint32_t old, new_val;
32
old = *mem; /* old is automatically updated on cs failure */
35
} while (__cs(&old, (cs_t *)mem, new_val));
39
void apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
41
apr_uint32_t old, new_val;
43
old = *mem; /* old is automatically updated on cs failure */
46
} while (__cs(&old, (cs_t *)mem, new_val));
49
apr_uint32_t apr_atomic_inc32(volatile apr_uint32_t *mem)
51
return apr_atomic_add32(mem, 1);
54
int apr_atomic_dec32(volatile apr_uint32_t *mem)
56
apr_uint32_t old, new_val;
58
old = *mem; /* old is automatically updated on cs failure */
61
} while (__cs(&old, (cs_t *)mem, new_val));
66
apr_uint32_t apr_atomic_read32(volatile apr_uint32_t *mem)
71
void apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
76
apr_uint32_t apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t swap,
79
apr_uint32_t old = cmp;
81
__cs(&old, (cs_t *)mem, swap);
82
return old; /* old is automatically updated from mem on cs failure */
85
apr_uint32_t apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
87
apr_uint32_t old, new_val;
89
old = *mem; /* old is automatically updated on cs failure */
92
} while (__cs(&old, (cs_t *)mem, new_val));