TortoiseGitMerge: Updated libsvn stuff
[TortoiseGit.git] / src / TortoiseMerge / libsvn_diff / private / svn_atomic.h
blob2739b00f38c8fdd73218a3ce7a204440f623b204
1 /**
2 * @copyright
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
19 * under the License.
20 * ====================================================================
21 * @endcopyright
23 * @file svn_atomic.h
24 * @brief Macros and functions for atomic operations
27 #ifndef SVN_ATOMIC_H
28 #define SVN_ATOMIC_H
30 #include <apr_version.h>
31 #include <apr_atomic.h>
33 #include "svn_error.h"
34 #include "private/svn_dep_compat.h"
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
40 /**
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.
45 * @{
48 /** The type used by all the other atomic operations. */
49 #if APR_VERSION_AT_LEAST(1, 0, 0)
50 #define svn_atomic_t apr_uint32_t
51 #else
52 #define svn_atomic_t apr_atomic_t
53 #endif
55 /** Atomically read an #svn_atomic_t from memory. */
56 #if APR_VERSION_AT_LEAST(1, 0, 0)
57 #define svn_atomic_read(mem) apr_atomic_read32((mem))
58 #else
59 #define svn_atomic_read(mem) apr_atomic_read((mem))
60 #endif
62 /** Atomically set an #svn_atomic_t in memory. */
63 #if APR_VERSION_AT_LEAST(1, 0, 0)
64 #define svn_atomic_set(mem, val) apr_atomic_set32((mem), (val))
65 #else
66 #define svn_atomic_set(mem, val) apr_atomic_set((mem), (val))
67 #endif
69 /** Atomically increment an #svn_atomic_t. */
70 #if APR_VERSION_AT_LEAST(1, 0, 0)
71 #define svn_atomic_inc(mem) apr_atomic_inc32(mem)
72 #else
73 #define svn_atomic_inc(mem) apr_atomic_inc(mem)
74 #endif
76 /** Atomically decrement an #svn_atomic_t. */
77 #if APR_VERSION_AT_LEAST(1, 0, 0)
78 #define svn_atomic_dec(mem) apr_atomic_dec32(mem)
79 #else
80 #define svn_atomic_dec(mem) apr_atomic_dec(mem)
81 #endif
83 /**
84 * Atomic compare-and-swap.
86 * Compare the value that @a mem points to with @a cmp. If they are
87 * the same swap the value with @a with.
89 * @note svn_atomic_cas should not be combined with the other
90 * svn_atomic operations. A comment in apr_atomic.h explains
91 * that on some platforms, the CAS function is implemented in a
92 * way that is incompatible with the other atomic operations.
94 #if APR_VERSION_AT_LEAST(1, 0, 0)
95 #define svn_atomic_cas(mem, with, cmp) \
96 apr_atomic_cas32((mem), (with), (cmp))
97 #else
98 #define svn_atomic_cas(mem, with, cmp) \
99 apr_atomic_cas((mem), (with), (cmp))
100 #endif
101 /** @} */
104 * Call an initialization function in a thread-safe manner.
106 * @a global_status must be a pointer to a global, zero-initialized
107 * #svn_atomic_t. @a init_func is a pointer to the function that performs
108 * the actual initialization. @a baton and and @a pool are passed on to the
109 * init_func for its use.
111 * @since New in 1.5.
113 svn_error_t *
114 svn_atomic__init_once(volatile svn_atomic_t *global_status,
115 svn_error_t *(*init_func)(void*,apr_pool_t*),
116 void *baton,
117 apr_pool_t* pool);
119 #ifdef __cplusplus
121 #endif /* __cplusplus */
123 #endif /* SVN_ATOMIC_H */