1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include "apr.h"
18 #include "apr_atomic.h"
19
20 #include <stdlib.h>
21
apr_atomic_init(apr_pool_t * pool)22 APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *pool)
23 {
24 return APR_SUCCESS;
25 }
26
apr_atomic_add32(volatile apr_uint32_t * mem,apr_uint32_t val)27 APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
28 {
29 return atomic_xchgadd((unsigned long *)mem,(unsigned long)val);
30 }
31
apr_atomic_sub32(volatile apr_uint32_t * mem,apr_uint32_t val)32 APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
33 {
34 atomic_sub((unsigned long *)mem,(unsigned long)val);
35 }
36
apr_atomic_inc32(volatile apr_uint32_t * mem)37 APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
38 {
39 return atomic_xchgadd((unsigned long *)mem, 1);
40 }
41
apr_atomic_set32(volatile apr_uint32_t * mem,apr_uint32_t val)42 APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
43 {
44 *mem = val;
45 }
46
apr_atomic_read32(volatile apr_uint32_t * mem)47 APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
48 {
49 return *mem;
50 }
51
apr_atomic_cas32(volatile apr_uint32_t * mem,apr_uint32_t with,apr_uint32_t cmp)52 APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,apr_uint32_t cmp)
53 {
54 return atomic_cmpxchg((unsigned long *)mem,(unsigned long)cmp,(unsigned long)with);
55 }
56
apr_atomic_xchg32(volatile apr_uint32_t * mem,apr_uint32_t val)57 APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
58 {
59 return atomic_xchg((unsigned long *)mem,(unsigned long)val);
60 }
61
apr_atomic_dec32(volatile apr_uint32_t * mem)62 APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
63 {
64 return (atomic_xchgadd((unsigned long *)mem, 0xFFFFFFFF) - 1);
65 }
66
apr_atomic_casptr(volatile void ** mem,void * with,const void * cmp)67 APR_DECLARE(void *) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
68 {
69 return (void*)atomic_cmpxchg((unsigned long *)mem,(unsigned long)cmp,(unsigned long)with);
70 }
71
apr_atomic_xchgptr(volatile void ** mem,void * with)72 APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
73 {
74 return (void*)atomic_xchg((unsigned long *)mem,(unsigned long)with);
75 }
76