1251875Speter/* Licensed to the Apache Software Foundation (ASF) under one or more
2251875Speter * contributor license agreements.  See the NOTICE file distributed with
3251875Speter * this work for additional information regarding copyright ownership.
4251875Speter * The ASF licenses this file to You under the Apache License, Version 2.0
5251875Speter * (the "License"); you may not use this file except in compliance with
6251875Speter * the License.  You may obtain a copy of the License at
7251875Speter *
8251875Speter *     http://www.apache.org/licenses/LICENSE-2.0
9251875Speter *
10251875Speter * Unless required by applicable law or agreed to in writing, software
11251875Speter * distributed under the License is distributed on an "AS IS" BASIS,
12251875Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13251875Speter * See the License for the specific language governing permissions and
14251875Speter * limitations under the License.
15251875Speter */
16251875Speter
17251875Speter#include "apr_arch_atomic.h"
18251875Speter
19251875Speter#ifdef USE_ATOMICS_SOLARIS
20251875Speter
21251875Speter#include <atomic.h>
22251875Speter
23251875SpeterAPR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
24251875Speter{
25362181Sdim#if defined (NEED_ATOMICS_GENERIC64)
26362181Sdim    return apr__atomic_generic64_init(p);
27362181Sdim#else
28251875Speter    return APR_SUCCESS;
29362181Sdim#endif
30251875Speter}
31251875Speter
32251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
33251875Speter{
34251875Speter    return *mem;
35251875Speter}
36251875Speter
37251875SpeterAPR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
38251875Speter{
39251875Speter    *mem = val;
40251875Speter}
41251875Speter
42251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
43251875Speter{
44251875Speter    return atomic_add_32_nv(mem, val) - val;
45251875Speter}
46251875Speter
47251875SpeterAPR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
48251875Speter{
49251875Speter    atomic_add_32(mem, -val);
50251875Speter}
51251875Speter
52251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
53251875Speter{
54251875Speter    return atomic_inc_32_nv(mem) - 1;
55251875Speter}
56251875Speter
57251875SpeterAPR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
58251875Speter{
59251875Speter    return atomic_dec_32_nv(mem);
60251875Speter}
61251875Speter
62251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
63251875Speter                                           apr_uint32_t cmp)
64251875Speter{
65251875Speter    return atomic_cas_32(mem, cmp, with);
66251875Speter}
67251875Speter
68251875SpeterAPR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
69251875Speter{
70251875Speter    return atomic_swap_32(mem, val);
71251875Speter}
72251875Speter
73251875SpeterAPR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
74251875Speter{
75251875Speter    return atomic_cas_ptr(mem, (void*) cmp, with);
76251875Speter}
77251875Speter
78251875SpeterAPR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
79251875Speter{
80251875Speter    return atomic_swap_ptr(mem, with);
81251875Speter}
82251875Speter
83251875Speter#endif /* USE_ATOMICS_SOLARIS */
84