3 * ====================================================================
4 * Copyright (c) 2006 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
19 * @brief Macros and functions for atomic operations
25 #include <apr_version.h>
26 #include <apr_atomic.h>
28 #include "svn_error.h"
29 #include "private/svn_dep_compat.h"
33 #endif /* __cplusplus */
36 * @name Macro definitions for atomic types and operations
38 * @note These are necessary because the apr_atomic API changed somewhat
39 * between apr-0.x and apr-1.x.
43 /** The type used by all the other atomic operations. */
44 #if APR_VERSION_AT_LEAST(1, 0, 0)
45 #define svn_atomic_t apr_uint32_t
47 #define svn_atomic_t apr_atomic_t
50 /** Atomically read an #svn_atomic_t from memory. */
51 #if APR_VERSION_AT_LEAST(1, 0, 0)
52 #define svn_atomic_read(mem) apr_atomic_read32((mem))
54 #define svn_atomic_read(mem) apr_atomic_read((mem))
57 /** Atomically set an #svn_atomic_t in memory. */
58 #if APR_VERSION_AT_LEAST(1, 0, 0)
59 #define svn_atomic_set(mem, val) apr_atomic_set32((mem), (val))
61 #define svn_atomic_set(mem, val) apr_atomic_set((mem), (val))
64 /** Atomically increment an #svn_atomic_t. */
65 #if APR_VERSION_AT_LEAST(1, 0, 0)
66 #define svn_atomic_inc(mem) apr_atomic_inc32(mem)
68 #define svn_atomic_inc(mem) apr_atomic_inc(mem)
71 /** Atomically decrement an #svn_atomic_t. */
72 #if APR_VERSION_AT_LEAST(1, 0, 0)
73 #define svn_atomic_dec(mem) apr_atomic_dec32(mem)
75 #define svn_atomic_dec(mem) apr_atomic_dec(mem)
79 * Atomic compare-and-swap.
81 * Compare the value that @a mem points to with @a cmp. If they are
82 * the same swap the value with @a with.
84 * @note svn_atomic_cas should not be combined with the other
85 * svn_atomic operations. A comment in apr_atomic.h explains
86 * that on some platforms, the CAS function is implemented in a
87 * way that is incompatible with the other atomic operations.
89 #if APR_VERSION_AT_LEAST(1, 0, 0)
90 #define svn_atomic_cas(mem, with, cmp) \
91 apr_atomic_cas32((mem), (with), (cmp))
93 #define svn_atomic_cas(mem, with, cmp) \
94 apr_atomic_cas((mem), (with), (cmp))
99 * Call an initialization function in a thread-safe manner.
101 * @a global_status must be a pointer to a global, zero-initialized
102 * #svn_atomic_t. @a init_func is a pointer to the function that performs
103 * the actual initialization, and @a pool is passed on to the init_func
109 svn_atomic__init_once(volatile svn_atomic_t
*global_status
,
110 svn_error_t
*(*init_func
)(apr_pool_t
*), apr_pool_t
* pool
);
114 #endif /* __cplusplus */
116 #endif /* SVN_ATOMIC_H */