blob: 93a66b7b96ee634913d2bb20036d2f728c16b2df (
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
|
/* Copyright (c) 2013, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* @file
*
* ODP ticketlock
*/
#ifndef ODP_TICKETLOCK_H_
#define ODP_TICKETLOCK_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <odp_std_types.h>
#include <odp_atomic.h>
/** @addtogroup odp_synchronizers
* Operations on ticket locks.
* Acquiring a ticket lock happens in two phases. First the threads takes a
* ticket. Second it waits (spins) until it is its turn.
* Ticket locks are believed to be more fair than spin locks.
* Ticket locks shall not be used in the presence of preemption.
* @{
*/
/**
* ODP ticket lock
*/
typedef struct odp_ticketlock_t {
odp_atomic_u32_t next_ticket; /**< @private Next ticket */
odp_atomic_u32_t cur_ticket; /**< @private Current ticket */
} odp_ticketlock_t;
/**
* Initialize ticket lock.
*
* @param tklock Pointer to a ticket lock
*/
void odp_ticketlock_init(odp_ticketlock_t *tklock);
/**
* Acquire ticket lock.
*
* @param tklock Pointer to a ticket lock
*/
void odp_ticketlock_lock(odp_ticketlock_t *tklock);
/**
* Try to acquire ticket lock.
*
* @param tklock Pointer to a ticket lock
*
* @retval 1 lock acquired
* @retval 0 lock not acquired
*/
int odp_ticketlock_trylock(odp_ticketlock_t *tklock);
/**
* Release ticket lock.
*
* @param tklock Pointer to a ticket lock
*/
void odp_ticketlock_unlock(odp_ticketlock_t *tklock);
/**
* Check if ticket lock is locked.
*
* @param tklock Pointer to a ticket lock
*
* @retval 1 the lock is busy (locked)
* @retval 0 the lock is available (unlocked)
*/
int odp_ticketlock_is_locked(odp_ticketlock_t *tklock);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif
|