3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
20 * ====================================================================
24 * @brief Macros and functions for atomic operations
30 #include <apr_version.h>
31 #include <apr_atomic.h>
33 #include "svn_error.h"
34 #include "private/svn_dep_compat.h"
38 #endif /* __cplusplus */
41 * @name Macro definitions for atomic types and operations
43 * @note These are necessary because the apr_atomic API changed somewhat
44 * between apr-0.x and apr-1.x.
48 /** The type used by all the other atomic operations. */
49 #define svn_atomic_t apr_uint32_t
51 /** Atomically read an #svn_atomic_t from memory. */
52 #define svn_atomic_read(mem) apr_atomic_read32((mem))
54 /** Atomically set an #svn_atomic_t in memory. */
55 #define svn_atomic_set(mem, val) apr_atomic_set32((mem), (val))
57 /** Atomically increment an #svn_atomic_t. */
58 #define svn_atomic_inc(mem) apr_atomic_inc32(mem)
60 /** Atomically decrement an #svn_atomic_t. */
61 #define svn_atomic_dec(mem) apr_atomic_dec32(mem)
64 * Atomic compare-and-swap.
66 * Compare the value that @a mem points to with @a cmp. If they are
67 * the same swap the value with @a with.
69 * @note svn_atomic_cas should not be combined with the other
70 * svn_atomic operations. A comment in apr_atomic.h explains
71 * that on some platforms, the CAS function is implemented in a
72 * way that is incompatible with the other atomic operations.
74 #define svn_atomic_cas(mem, with, cmp) \
75 apr_atomic_cas32((mem), (with), (cmp))
79 * Call an initialization function in a thread-safe manner.
81 * @a global_status must be a pointer to a global, zero-initialized
82 * #svn_atomic_t. @a init_func is a pointer to the function that performs
83 * the actual initialization. @a baton and and @a pool are passed on to the
84 * init_func for its use.
89 svn_atomic__init_once(volatile svn_atomic_t *global_status,
90 svn_error_t *(*init_func)(void*,apr_pool_t*),
96 #endif /* __cplusplus */
98 #endif /* SVN_ATOMIC_H */