aboutsummaryrefslogtreecommitdiffstats
path: root/lib/librte_eal/common/include/arch/x86/rte_rwlock.h
blob: eec4c7123cddd04f6986bb23e2bd8f9fc3adf2fe (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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2015 Intel Corporation
 */

#ifndef _RTE_RWLOCK_X86_64_H_
#define _RTE_RWLOCK_X86_64_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "generic/rte_rwlock.h"
#include "rte_spinlock.h"

static inline void
rte_rwlock_read_lock_tm(rte_rwlock_t *rwl)
{
	if (likely(rte_try_tm(&rwl->cnt)))
		return;
	rte_rwlock_read_lock(rwl);
}

static inline void
rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl)
{
	if (unlikely(rwl->cnt))
		rte_rwlock_read_unlock(rwl);
	else
		rte_xend();
}

static inline void
rte_rwlock_write_lock_tm(rte_rwlock_t *rwl)
{
	if (likely(rte_try_tm(&rwl->cnt)))
		return;
	rte_rwlock_write_lock(rwl);
}

static inline void
rte_rwlock_write_unlock_tm(rte_rwlock_t *rwl)
{
	if (unlikely(rwl->cnt))
		rte_rwlock_write_unlock(rwl);
	else
		rte_xend();
}

#ifdef __cplusplus
}
#endif

#endif /* _RTE_RWLOCK_X86_64_H_ */