blob: 7924a50a7d59d8991776fad90a691f9a492d30bf (
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
98
99
100
101
102
103
104
|
/* Copyright (c) 2014-2018, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef ODP_API_SPEC_RWLOCK_H_
#define ODP_API_SPEC_RWLOCK_H_
#include <odp/visibility_begin.h>
/**
* @file
*
* ODP RW Locks
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup odp_locks ODP LOCKS
* @details
* <b> Reader / writer lock (odp_rwlock_t) </b>
*
* A reader/writer lock allows multiple simultaneous readers but only one
* writer at a time. A thread that wants write access will have to wait until
* there are no threads that want read access. This causes a risk for
* starvation. The trylock variants can be used to avoid blocking when
* the lock is not immediately available.
* @{
*/
/**
* @typedef odp_rwlock_t
* ODP reader/writer lock
*/
/**
* Initialize a reader/writer lock.
*
* @param rwlock Pointer to a reader/writer lock
*/
void odp_rwlock_init(odp_rwlock_t *rwlock);
/**
* Acquire read permission on a reader/writer lock.
*
* @param rwlock Pointer to a reader/writer lock
*/
void odp_rwlock_read_lock(odp_rwlock_t *rwlock);
/**
* Try to acquire read permission to a reader/writer lock.
*
* @param rwlock Pointer to a reader/writer lock
*
* @retval 0 Lock was not available for read access
* @retval !0 Read access to lock acquired
*/
int odp_rwlock_read_trylock(odp_rwlock_t *rwlock);
/**
* Release read permission on a reader/writer lock.
*
* @param rwlock Pointer to a reader/writer lock
*/
void odp_rwlock_read_unlock(odp_rwlock_t *rwlock);
/**
* Acquire write permission on a reader/writer lock.
*
* @param rwlock Pointer to a reader/writer lock
*/
void odp_rwlock_write_lock(odp_rwlock_t *rwlock);
/**
* Try to acquire write permission to a reader/writer lock.
*
* @param rwlock Pointer to a reader/writer lock
*
* @retval 0 Lock was not available for write access
* @retval !0 Write access to lock acquired
*/
int odp_rwlock_write_trylock(odp_rwlock_t *rwlock);
/**
* Release write permission on a reader/writer lock.
*
* @param rwlock Pointer to a reader/writer lock
*/
void odp_rwlock_write_unlock(odp_rwlock_t *rwlock);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#include <odp/visibility_end.h>
#endif /* ODP_RWLOCK_H_ */
|