New upstream version 18.02
[deb_dpdk.git] / lib / librte_eal / common / include / arch / x86 / rte_rwlock.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015 Intel Corporation
3  */
4
5 #ifndef _RTE_RWLOCK_X86_64_H_
6 #define _RTE_RWLOCK_X86_64_H_
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 #include "generic/rte_rwlock.h"
13 #include "rte_spinlock.h"
14
15 static inline void
16 rte_rwlock_read_lock_tm(rte_rwlock_t *rwl)
17 {
18         if (likely(rte_try_tm(&rwl->cnt)))
19                 return;
20         rte_rwlock_read_lock(rwl);
21 }
22
23 static inline void
24 rte_rwlock_read_unlock_tm(rte_rwlock_t *rwl)
25 {
26         if (unlikely(rwl->cnt))
27                 rte_rwlock_read_unlock(rwl);
28         else
29                 rte_xend();
30 }
31
32 static inline void
33 rte_rwlock_write_lock_tm(rte_rwlock_t *rwl)
34 {
35         if (likely(rte_try_tm(&rwl->cnt)))
36                 return;
37         rte_rwlock_write_lock(rwl);
38 }
39
40 static inline void
41 rte_rwlock_write_unlock_tm(rte_rwlock_t *rwl)
42 {
43         if (unlikely(rwl->cnt))
44                 rte_rwlock_write_unlock(rwl);
45         else
46                 rte_xend();
47 }
48
49 #ifdef __cplusplus
50 }
51 #endif
52
53 #endif /* _RTE_RWLOCK_X86_64_H_ */