xref: /dpdk/lib/eal/ppc/include/rte_spinlock.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright (C) IBM Corporation 2014.
4  */
5 
6 #ifndef _RTE_SPINLOCK_PPC_64_H_
7 #define _RTE_SPINLOCK_PPC_64_H_
8 
9 #include <rte_common.h>
10 #include <rte_pause.h>
11 #include "generic/rte_spinlock.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /* Fixme: Use intrinsics to implement the spinlock on Power architecture */
18 
19 #ifndef RTE_FORCE_INTRINSICS
20 
21 static inline void
22 rte_spinlock_lock(rte_spinlock_t *sl)
23 	__rte_no_thread_safety_analysis
24 {
25 	while (__sync_lock_test_and_set(&sl->locked, 1))
26 		while (sl->locked)
27 			rte_pause();
28 }
29 
30 static inline void
31 rte_spinlock_unlock(rte_spinlock_t *sl)
32 	__rte_no_thread_safety_analysis
33 {
34 	__sync_lock_release(&sl->locked);
35 }
36 
37 static inline int
38 rte_spinlock_trylock(rte_spinlock_t *sl)
39 	__rte_no_thread_safety_analysis
40 {
41 	return __sync_lock_test_and_set(&sl->locked, 1) == 0;
42 }
43 
44 #endif
45 
46 static inline int rte_tm_supported(void)
47 {
48 	return 0;
49 }
50 
51 static inline void
52 rte_spinlock_lock_tm(rte_spinlock_t *sl)
53 {
54 	rte_spinlock_lock(sl); /* fall-back */
55 }
56 
57 static inline int
58 rte_spinlock_trylock_tm(rte_spinlock_t *sl)
59 {
60 	return rte_spinlock_trylock(sl);
61 }
62 
63 static inline void
64 rte_spinlock_unlock_tm(rte_spinlock_t *sl)
65 {
66 	rte_spinlock_unlock(sl);
67 }
68 
69 static inline void
70 rte_spinlock_recursive_lock_tm(rte_spinlock_recursive_t *slr)
71 {
72 	rte_spinlock_recursive_lock(slr); /* fall-back */
73 }
74 
75 static inline void
76 rte_spinlock_recursive_unlock_tm(rte_spinlock_recursive_t *slr)
77 {
78 	rte_spinlock_recursive_unlock(slr);
79 }
80 
81 static inline int
82 rte_spinlock_recursive_trylock_tm(rte_spinlock_recursive_t *slr)
83 {
84 	return rte_spinlock_recursive_trylock(slr);
85 }
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif /* _RTE_SPINLOCK_PPC_64_H_ */
92