aboutsummaryrefslogtreecommitdiff
path: root/include/odp/api/rwlock_recursive.h
blob: 10b2f79ba8288a9404837a0d9acf6478c6b48acc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Copyright (c) 2015, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

/**
 * @file
 *
 * ODP recursive read/write lock
 */

#ifndef ODP_API_RWLOCK_RECURSIVE_H_
#define ODP_API_RWLOCK_RECURSIVE_H_

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @addtogroup odp_locks
 * @details
 * <b> Recursive reader/writer lock (odp_rwlock_recursive_t) </b>
 *
 * This is recursive version of the reader/writer lock.
 * A thread can read- or write-acquire a recursive read-write lock multiple
 * times without a deadlock. To release the lock, the thread must unlock it
 * the same number of times. Recursion is supported only for a pure series of
 * read or write lock calls. Read and write lock calls must not be mixed when
 * recursing.
 *
 * For example, these are supported...
 *   * read_lock(); read_lock(); read_unlock(); read_unlock();
 *   * write_lock(); write_lock(); write_unlock(); write_unlock();
 *
 * ... but this is not supported.
 *   * read_lock(); write_lock(); write_unlock(); read_unlock();
 * @{
 */

/**
 * @typedef odp_rwlock_recursive_t
 * Recursive rwlock
 */

/**
 * Initialize recursive rwlock
 *
 * @param lock    Pointer to a lock
 */
void odp_rwlock_recursive_init(odp_rwlock_recursive_t *lock);

/**
 * Acquire recursive rwlock for reading
 *
 * This call allows the thread to acquire the same lock multiple times for
 * reading. The lock cannot be acquired for writing while holding it
 * for reading.
 *
 * @param lock    Pointer to a lock
 */
void odp_rwlock_recursive_read_lock(odp_rwlock_recursive_t *lock);

/**
 * Release recursive rwlock after reading
 *
 * @param lock    Pointer to a lock
 */
void odp_rwlock_recursive_read_unlock(odp_rwlock_recursive_t *lock);

/**
 * Acquire recursive rwlock for writing
 *
 * This call allows the thread to acquire the same lock multiple times for
 * writing. The lock cannot be acquired for reading while holding it
 * for writing.
 *
 * @param lock    Pointer to a lock
 */
void odp_rwlock_recursive_write_lock(odp_rwlock_recursive_t *lock);

/**
 * Release recursive rwlock after writing
 *
 * @param lock    Pointer to a lock
 */
void odp_rwlock_recursive_write_unlock(odp_rwlock_recursive_t *lock);

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif