]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: use faster locks for the spin locks
authorWilly Tarreau <w@1wt.eu>
Mon, 6 Nov 2017 00:03:26 +0000 (01:03 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 Nov 2017 10:20:11 +0000 (11:20 +0100)
The spin locks used to rely on W locks, which involve a loop waiting
for readers to leave, and this doesn't happen here. It's more efficient
to use S locks instead, which are also mutually exclusive and do not
have this loop. This saves one test per spinlock and a few tens of
bytes allowing certain functions to be inlined.

include/common/hathreads.h

index 853c9f16749c7b51060f3f80fa44048b95ea674c..0a9098dbe682b203c65d1593a2625e0cf1651655 100644 (file)
@@ -191,9 +191,9 @@ extern struct lock_stat lock_stats[LOCK_LABELS];
 
 #define __SPIN_INIT(l)         ({ (*l) = 0; })
 #define __SPIN_DESTROY(l)      ({ (*l) = 0; })
-#define __SPIN_LOCK(l)         pl_take_w(l)
-#define __SPIN_TRYLOCK(l)      !pl_try_w(l)
-#define __SPIN_UNLOCK(l)       pl_drop_w(l)
+#define __SPIN_LOCK(l)         pl_take_s(l)
+#define __SPIN_TRYLOCK(l)      !pl_try_s(l)
+#define __SPIN_UNLOCK(l)       pl_drop_s(l)
 
 #define __HA_RWLOCK_T          unsigned long
 
@@ -552,9 +552,9 @@ static inline void __spin_unlock(enum lock_label lbl, struct ha_spinlock *l,
 
 #define SPIN_INIT(l)         ({ (*l) = 0; })
 #define SPIN_DESTROY(l)      ({ (*l) = 0; })
-#define SPIN_LOCK(lbl, l)    pl_take_w(l)
-#define SPIN_TRYLOCK(lbl, l) !pl_try_w(l)
-#define SPIN_UNLOCK(lbl, l)  pl_drop_w(l)
+#define SPIN_LOCK(lbl, l)    pl_take_s(l)
+#define SPIN_TRYLOCK(lbl, l) !pl_try_s(l)
+#define SPIN_UNLOCK(lbl, l)  pl_drop_s(l)
 
 #define HA_RWLOCK_T            unsigned long