svn_atomic.h revision 299742
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
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
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
22 *
23 * @file svn_atomic.h
24 * @brief Macros and functions for atomic operations
25 */
26
27#ifndef SVN_ATOMIC_H
28#define SVN_ATOMIC_H
29
30#include <apr_version.h>
31#include <apr_atomic.h>
32
33#include "svn_error.h"
34#include "private/svn_dep_compat.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif /* __cplusplus */
39
40/**
41 * @name Macro definitions for atomic types and operations
42 *
43 * @note These are necessary because the apr_atomic API changed somewhat
44 *       between apr-0.x and apr-1.x.
45 * @{
46 */
47
48/** The type used by all the other atomic operations. */
49#define svn_atomic_t apr_uint32_t
50
51/** Atomically read an #svn_atomic_t from memory. */
52#define svn_atomic_read(mem) apr_atomic_read32((mem))
53
54/** Atomically set an #svn_atomic_t in memory. */
55#define svn_atomic_set(mem, val) apr_atomic_set32((mem), (val))
56
57/** Atomically increment an #svn_atomic_t. */
58#define svn_atomic_inc(mem) apr_atomic_inc32(mem)
59
60/** Atomically decrement an #svn_atomic_t. */
61#define svn_atomic_dec(mem) apr_atomic_dec32(mem)
62
63/**
64 * Atomic compare-and-swap.
65 *
66 * Compare the value that @a mem points to with @a cmp. If they are
67 * the same swap the value with @a with.
68 *
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.
73 */
74#define svn_atomic_cas(mem, with, cmp) \
75    apr_atomic_cas32((mem), (with), (cmp))
76/** @} */
77
78/**
79 * Call an initialization function in a thread-safe manner.
80 *
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.
85 *
86 * @since New in 1.5.
87 */
88svn_error_t *
89svn_atomic__init_once(volatile svn_atomic_t *global_status,
90                      svn_error_t *(*init_func)(void*,apr_pool_t*),
91                      void *baton,
92                      apr_pool_t* pool);
93
94#ifdef __cplusplus
95}
96#endif /* __cplusplus */
97
98#endif /* SVN_ATOMIC_H */
99