Change the format of the revprops block sent in svnserve for
[svn.git] / subversion / include / private / svn_atomic.h
blobd1039d1764538e460f0c72a83b6b175a581bfa10
1 /**
2 * @copyright
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 * ====================================================================
16 * @endcopyright
18 * @file svn_atomic.h
19 * @brief Macros and functions for atomic operations
22 #ifndef SVN_ATOMIC_H
23 #define SVN_ATOMIC_H
25 #include <apr_version.h>
26 #include <apr_atomic.h>
28 #include "svn_error.h"
29 #include "private/svn_dep_compat.h"
31 #ifdef __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
35 /**
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.
40 * @{
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
46 #else
47 #define svn_atomic_t apr_atomic_t
48 #endif
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))
53 #else
54 #define svn_atomic_read(mem) apr_atomic_read((mem))
55 #endif
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))
60 #else
61 #define svn_atomic_set(mem, val) apr_atomic_set((mem), (val))
62 #endif
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)
67 #else
68 #define svn_atomic_inc(mem) apr_atomic_inc(mem)
69 #endif
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)
74 #else
75 #define svn_atomic_dec(mem) apr_atomic_dec(mem)
76 #endif
78 /**
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))
92 #else
93 #define svn_atomic_cas(mem, with, cmp) \
94 apr_atomic_cas((mem), (with), (cmp))
95 #endif
96 /** @} */
98 /**
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
104 * for its use.
106 * @since New in 1.5.
108 svn_error_t *
109 svn_atomic__init_once(volatile svn_atomic_t *global_status,
110 svn_error_t *(*init_func)(apr_pool_t*), apr_pool_t* pool);
112 #ifdef __cplusplus
114 #endif /* __cplusplus */
116 #endif /* SVN_ATOMIC_H */