diff options
author | jaszha03 <jason.zhang2@arm.com> | 2019-06-12 16:01:19 -0500 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2019-07-30 16:22:03 +0000 |
commit | f25e7cfa5c615e1972d5823b65ca579f951d68a5 (patch) | |
tree | 47c4e91b45710d861081d1933e2e8cbe3f56fe42 /src/vppinfra/lock.h | |
parent | 6b03ab73116a7746f9480ea00c3924dcecb2799f (diff) |
vppinfra: refactor use of CLIB_MEMORY_BARRIER ()
All instances of test_and_set locks used the following sequence
to release the locks:
CLIB_MEMORY_BARRIER ();
p->lock = 0; // p is a generic struct with a TAS lock
Use clib_atomic_release to generate more efficient assembly code.
Type: refactor
Change-Id: Idca3a38b1cf43578108bdd1afe83b6ebc17a4c68
Signed-off-by: Jason Zhang <jason.zhang2@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Lijian Zhang <Lijian.Zhang@arm.com>
Diffstat (limited to 'src/vppinfra/lock.h')
-rw-r--r-- | src/vppinfra/lock.h | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/vppinfra/lock.h b/src/vppinfra/lock.h index 337c5a3f0ad..59ab0e33c51 100644 --- a/src/vppinfra/lock.h +++ b/src/vppinfra/lock.h @@ -89,9 +89,8 @@ static_always_inline void clib_spinlock_unlock (clib_spinlock_t * p) { CLIB_LOCK_DBG_CLEAR (p); - /* Make sure all writes are complete before releasing the lock */ - CLIB_MEMORY_BARRIER (); - (*p)->lock = 0; + /* Make sure all reads/writes are complete before releasing the lock */ + clib_atomic_release (&(*p)->lock); } static_always_inline void @@ -147,9 +146,7 @@ clib_rwlock_reader_lock (clib_rwlock_t * p) while (clib_atomic_test_and_set (&(*p)->writer_lock)) CLIB_PAUSE (); } - CLIB_MEMORY_BARRIER (); - (*p)->n_readers_lock = 0; - + clib_atomic_release (&(*p)->n_readers_lock); CLIB_LOCK_DBG (p); } @@ -165,12 +162,9 @@ clib_rwlock_reader_unlock (clib_rwlock_t * p) (*p)->n_readers -= 1; if ((*p)->n_readers == 0) { - CLIB_MEMORY_BARRIER (); - (*p)->writer_lock = 0; + clib_atomic_release (&(*p)->writer_lock); } - - CLIB_MEMORY_BARRIER (); - (*p)->n_readers_lock = 0; + clib_atomic_release (&(*p)->n_readers_lock); } always_inline void @@ -185,8 +179,7 @@ always_inline void clib_rwlock_writer_unlock (clib_rwlock_t * p) { CLIB_LOCK_DBG_CLEAR (p); - CLIB_MEMORY_BARRIER (); - (*p)->writer_lock = 0; + clib_atomic_release (&(*p)->writer_lock); } #endif |