mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
MINOR: threads: add new macros to declare self-initializing locks
Using __decl_spinlock(), __decl_rwlock(), __decl_aligned_spinlock() and __decl_aligned_rwlock(), one can now simply declare a spinlock or an rwlock which will automatically be initialized at boot time by calling the ha_spin_init() or ha_rwlock_init() callback. The "aligned" variants enforce a 64-byte alignment on the lock.
This commit is contained in:
parent
a8ae77da61
commit
90fa97b65e
@ -23,6 +23,7 @@
|
|||||||
#define _COMMON_HATHREADS_H
|
#define _COMMON_HATHREADS_H
|
||||||
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
|
#include <common/initcall.h>
|
||||||
|
|
||||||
/* Note about all_threads_mask :
|
/* Note about all_threads_mask :
|
||||||
* - with threads support disabled, this symbol is defined as zero (0UL).
|
* - with threads support disabled, this symbol is defined as zero (0UL).
|
||||||
@ -43,6 +44,10 @@ enum { tid_bit = 1UL };
|
|||||||
enum { tid = 0 };
|
enum { tid = 0 };
|
||||||
|
|
||||||
#define __decl_hathreads(decl)
|
#define __decl_hathreads(decl)
|
||||||
|
#define __decl_spinlock(lock)
|
||||||
|
#define __decl_aligned_spinlock(lock)
|
||||||
|
#define __decl_rwlock(lock)
|
||||||
|
#define __decl_aligned_rwlock(lock)
|
||||||
|
|
||||||
#define HA_ATOMIC_CAS(val, old, new) ({((*val) == (*old)) ? (*(val) = (new) , 1) : (*(old) = *(val), 0);})
|
#define HA_ATOMIC_CAS(val, old, new) ({((*val) == (*old)) ? (*(val) = (new) , 1) : (*(old) = *(val), 0);})
|
||||||
#define HA_ATOMIC_ADD(val, i) ({*(val) += (i);})
|
#define HA_ATOMIC_ADD(val, i) ({*(val) += (i);})
|
||||||
@ -168,6 +173,26 @@ static inline unsigned long thread_isolated()
|
|||||||
|
|
||||||
#define __decl_hathreads(decl) decl
|
#define __decl_hathreads(decl) decl
|
||||||
|
|
||||||
|
/* declare a self-initializing spinlock */
|
||||||
|
#define __decl_spinlock(lock) \
|
||||||
|
HA_SPINLOCK_T (lock); \
|
||||||
|
INITCALL1(STG_LOCK, ha_spin_init, &(lock))
|
||||||
|
|
||||||
|
/* declare a self-initializing spinlock, aligned on a cache line */
|
||||||
|
#define __decl_aligned_spinlock(lock) \
|
||||||
|
HA_SPINLOCK_T (lock) __attribute__((aligned(64))); \
|
||||||
|
INITCALL1(STG_LOCK, ha_spin_init, &(lock))
|
||||||
|
|
||||||
|
/* declare a self-initializing rwlock */
|
||||||
|
#define __decl_rwlock(lock) \
|
||||||
|
HA_RWLOCK_T (lock); \
|
||||||
|
INITCALL1(STG_LOCK, ha_rwlock_init, &(lock))
|
||||||
|
|
||||||
|
/* declare a self-initializing rwlock, aligned on a cache line */
|
||||||
|
#define __decl_aligned_rwlock(lock) \
|
||||||
|
HA_RWLOCK_T (lock) __attribute__((aligned(64))); \
|
||||||
|
INITCALL1(STG_LOCK, ha_rwlock_init, &(lock))
|
||||||
|
|
||||||
/* TODO: thread: For now, we rely on GCC builtins but it could be a good idea to
|
/* TODO: thread: For now, we rely on GCC builtins but it could be a good idea to
|
||||||
* have a header file regrouping all functions dealing with threads. */
|
* have a header file regrouping all functions dealing with threads. */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user