Code Review
/
deb_dpdk.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
New upstream version 18.11.2
[deb_dpdk.git]
/
lib
/
librte_eal
/
common
/
include
/
generic
/
rte_spinlock.h
diff --git
a/lib/librte_eal/common/include/generic/rte_spinlock.h
b/lib/librte_eal/common/include/generic/rte_spinlock.h
index
c4c3fc3
..
87ae7a4
100644
(file)
--- a/
lib/librte_eal/common/include/generic/rte_spinlock.h
+++ b/
lib/librte_eal/common/include/generic/rte_spinlock.h
@@
-61,9
+61,14
@@
rte_spinlock_lock(rte_spinlock_t *sl);
static inline void
rte_spinlock_lock(rte_spinlock_t *sl)
{
static inline void
rte_spinlock_lock(rte_spinlock_t *sl)
{
- while (__sync_lock_test_and_set(&sl->locked, 1))
- while(sl->locked)
+ int exp = 0;
+
+ while (!__atomic_compare_exchange_n(&sl->locked, &exp, 1, 0,
+ __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) {
+ while (__atomic_load_n(&sl->locked, __ATOMIC_RELAXED))
rte_pause();
rte_pause();
+ exp = 0;
+ }
}
#endif
}
#endif
@@
-80,7
+85,7
@@
rte_spinlock_unlock (rte_spinlock_t *sl);
static inline void
rte_spinlock_unlock (rte_spinlock_t *sl)
{
static inline void
rte_spinlock_unlock (rte_spinlock_t *sl)
{
- __
sync_lock_release(&sl->locked
);
+ __
atomic_store_n(&sl->locked, 0, __ATOMIC_RELEASE
);
}
#endif
}
#endif
@@
-99,7
+104,10
@@
rte_spinlock_trylock (rte_spinlock_t *sl);
static inline int
rte_spinlock_trylock (rte_spinlock_t *sl)
{
static inline int
rte_spinlock_trylock (rte_spinlock_t *sl)
{
- return __sync_lock_test_and_set(&sl->locked,1) == 0;
+ int exp = 0;
+ return __atomic_compare_exchange_n(&sl->locked, &exp, 1,
+ 0, /* disallow spurious failure */
+ __ATOMIC_ACQUIRE, __ATOMIC_RELAXED);
}
#endif
}
#endif
@@
-113,7
+121,7
@@
rte_spinlock_trylock (rte_spinlock_t *sl)
*/
static inline int rte_spinlock_is_locked (rte_spinlock_t *sl)
{
*/
static inline int rte_spinlock_is_locked (rte_spinlock_t *sl)
{
- return
sl->locked
;
+ return
__atomic_load_n(&sl->locked, __ATOMIC_ACQUIRE)
;
}
/**
}
/**