aboutsummaryrefslogtreecommitdiff
path: root/include/odp/api/spec/ticketlock.h
blob: 2a14273ee2229db0f75ee11b01657c8c3728a5b0 (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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2013-2018 Linaro Limited
 */

/**
 * @file
 *
 * ODP ticketlock
 */

#ifndef ODP_API_SPEC_TICKETLOCK_H_
#define ODP_API_SPEC_TICKETLOCK_H_
#include <odp/visibility_begin.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @addtogroup odp_locks
 * @details
 * <b> Ticket lock (odp_ticketlock_t) </b>
 *
 * 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
 * if a thread may be preempted, since other threads cannot acquire the lock
 * while the thread in turn is stalled.
 * @{
 */

/**
 * @typedef odp_ticketlock_t
 * ODP ticketlock
 */

/**
 * 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

#include <odp/visibility_end.h>
#endif