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
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.
17 #include "apr_arch_atomic.h"
19 #ifdef USE_ATOMICS_S390
21 APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
26 APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
31 APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
36 static APR_INLINE apr_uint32_t atomic_add(volatile apr_uint32_t *mem, apr_uint32_t val)
38 apr_uint32_t prev = *mem, temp;
40 asm volatile ("loop_%=:\n"
45 : "+d" (prev), "+d" (temp), "=Q" (*mem)
46 : "d" (val), "m" (*mem)
52 APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
54 return atomic_add(mem, val);
57 APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
59 return atomic_add(mem, 1);
62 static APR_INLINE apr_uint32_t atomic_sub(volatile apr_uint32_t *mem, apr_uint32_t val)
64 apr_uint32_t prev = *mem, temp;
66 asm volatile ("loop_%=:\n"
71 : "+d" (prev), "+d" (temp), "=Q" (*mem)
72 : "d" (val), "m" (*mem)
78 APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
83 APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
85 return atomic_sub(mem, 1);
88 APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
91 asm volatile (" cs %0,%2,%1\n"
92 : "+d" (cmp), "=Q" (*mem)
93 : "d" (with), "m" (*mem)
99 APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
101 apr_uint32_t prev = *mem;
103 asm volatile ("loop_%=:\n"
106 : "+d" (prev), "=Q" (*mem)
107 : "d" (val), "m" (*mem)
113 APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
115 void *prev = (void *) cmp;
116 #if APR_SIZEOF_VOIDP == 4
117 asm volatile (" cs %0,%2,%1\n"
118 : "+d" (prev), "=Q" (*mem)
119 : "d" (with), "m" (*mem)
121 #elif APR_SIZEOF_VOIDP == 8
122 asm volatile (" csg %0,%2,%1\n"
123 : "+d" (prev), "=Q" (*mem)
124 : "d" (with), "m" (*mem)
127 #error APR_SIZEOF_VOIDP value not supported
132 APR_DECLARE(void*) apr_atomic_xchgptr(volatile void **mem, void *with)
134 void *prev = (void *) *mem;
135 #if APR_SIZEOF_VOIDP == 4
136 asm volatile ("loop_%=:\n"
139 : "+d" (prev), "=Q" (*mem)
140 : "d" (with), "m" (*mem)
142 #elif APR_SIZEOF_VOIDP == 8
143 asm volatile ("loop_%=:\n"
146 : "+d" (prev), "=Q" (*mem)
147 : "d" (with), "m" (*mem)
150 #error APR_SIZEOF_VOIDP value not supported
155 #endif /* USE_ATOMICS_S390 */