xref: /dpdk/lib/eal/x86/include/rte_rwlock.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2015 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_RWLOCK_X86_64_H_
699a2dd95SBruce Richardson #define _RTE_RWLOCK_X86_64_H_
799a2dd95SBruce Richardson 
8*719834a6SMattias Rönnblom #include "generic/rte_rwlock.h"
9*719834a6SMattias Rönnblom #include "rte_spinlock.h"
10*719834a6SMattias Rönnblom 
1199a2dd95SBruce Richardson #ifdef __cplusplus
1299a2dd95SBruce Richardson extern "C" {
1399a2dd95SBruce Richardson #endif
1499a2dd95SBruce Richardson 
1599a2dd95SBruce Richardson static inline void
1699a2dd95SBruce Richardson rte_rwlock_read_lock_tm(rte_rwlock_t *rwl)
17657a98f3SDavid Marchand 	__rte_no_thread_safety_analysis
1899a2dd95SBruce Richardson {
1999a2dd95SBruce Richardson 	if (likely(rte_try_tm(&rwl->cnt)))
2099a2dd95SBruce Richardson 		return;
2199a2dd95SBruce Richardson 	rte_rwlock_read_lock(rwl);
2299a2dd95SBruce Richardson }
2399a2dd95SBruce Richardson 
2499a2dd95SBruce Richardson static inline void
2599a2dd95SBruce Richardson rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl)
26657a98f3SDavid Marchand 	__rte_no_thread_safety_analysis
2799a2dd95SBruce Richardson {
2899a2dd95SBruce Richardson 	if (unlikely(rwl->cnt))
2999a2dd95SBruce Richardson 		rte_rwlock_read_unlock(rwl);
3099a2dd95SBruce Richardson 	else
3199a2dd95SBruce Richardson 		rte_xend();
3299a2dd95SBruce Richardson }
3399a2dd95SBruce Richardson 
3499a2dd95SBruce Richardson static inline void
3599a2dd95SBruce Richardson rte_rwlock_write_lock_tm(rte_rwlock_t *rwl)
36657a98f3SDavid Marchand 	__rte_no_thread_safety_analysis
3799a2dd95SBruce Richardson {
3899a2dd95SBruce Richardson 	if (likely(rte_try_tm(&rwl->cnt)))
3999a2dd95SBruce Richardson 		return;
4099a2dd95SBruce Richardson 	rte_rwlock_write_lock(rwl);
4199a2dd95SBruce Richardson }
4299a2dd95SBruce Richardson 
4399a2dd95SBruce Richardson static inline void
4499a2dd95SBruce Richardson rte_rwlock_write_unlock_tm(rte_rwlock_t *rwl)
45657a98f3SDavid Marchand 	__rte_no_thread_safety_analysis
4699a2dd95SBruce Richardson {
4799a2dd95SBruce Richardson 	if (unlikely(rwl->cnt))
4899a2dd95SBruce Richardson 		rte_rwlock_write_unlock(rwl);
4999a2dd95SBruce Richardson 	else
5099a2dd95SBruce Richardson 		rte_xend();
5199a2dd95SBruce Richardson }
5299a2dd95SBruce Richardson 
5399a2dd95SBruce Richardson #ifdef __cplusplus
5499a2dd95SBruce Richardson }
5599a2dd95SBruce Richardson #endif
5699a2dd95SBruce Richardson 
5799a2dd95SBruce Richardson #endif /* _RTE_RWLOCK_X86_64_H_ */
58