Skip to content

Commit e4e9ab3

Browse files
author
Peter Zijlstra
committed
seqlock: Fold seqcount_LOCKNAME_init() definition
Manual repetition is boring and error prone. Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
1 parent a8772dc commit e4e9ab3

File tree

1 file changed

+14
-47
lines changed

1 file changed

+14
-47
lines changed

include/linux/seqlock.h

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ static inline void seqcount_lockdep_reader_access(const seqcount_t *s)
143143
__SEQ_LOCK(.lock = (assoc_lock)) \
144144
}
145145

146-
#define seqcount_locktype_init(s, assoc_lock) \
147-
do { \
148-
seqcount_init(&(s)->seqcount); \
149-
__SEQ_LOCK((s)->lock = (assoc_lock)); \
150-
} while (0)
151-
152146
/**
153147
* SEQCNT_SPINLOCK_ZERO - static initializer for seqcount_spinlock_t
154148
* @name: Name of the seqcount_spinlock_t instance
@@ -157,14 +151,6 @@ do { \
157151
#define SEQCNT_SPINLOCK_ZERO(name, lock) \
158152
SEQCOUNT_LOCKTYPE_ZERO(name, lock)
159153

160-
/**
161-
* seqcount_spinlock_init - runtime initializer for seqcount_spinlock_t
162-
* @s: Pointer to the seqcount_spinlock_t instance
163-
* @lock: Pointer to the associated spinlock
164-
*/
165-
#define seqcount_spinlock_init(s, lock) \
166-
seqcount_locktype_init(s, lock)
167-
168154
/**
169155
* SEQCNT_RAW_SPINLOCK_ZERO - static initializer for seqcount_raw_spinlock_t
170156
* @name: Name of the seqcount_raw_spinlock_t instance
@@ -173,14 +159,6 @@ do { \
173159
#define SEQCNT_RAW_SPINLOCK_ZERO(name, lock) \
174160
SEQCOUNT_LOCKTYPE_ZERO(name, lock)
175161

176-
/**
177-
* seqcount_raw_spinlock_init - runtime initializer for seqcount_raw_spinlock_t
178-
* @s: Pointer to the seqcount_raw_spinlock_t instance
179-
* @lock: Pointer to the associated raw_spinlock
180-
*/
181-
#define seqcount_raw_spinlock_init(s, lock) \
182-
seqcount_locktype_init(s, lock)
183-
184162
/**
185163
* SEQCNT_RWLOCK_ZERO - static initializer for seqcount_rwlock_t
186164
* @name: Name of the seqcount_rwlock_t instance
@@ -189,14 +167,6 @@ do { \
189167
#define SEQCNT_RWLOCK_ZERO(name, lock) \
190168
SEQCOUNT_LOCKTYPE_ZERO(name, lock)
191169

192-
/**
193-
* seqcount_rwlock_init - runtime initializer for seqcount_rwlock_t
194-
* @s: Pointer to the seqcount_rwlock_t instance
195-
* @lock: Pointer to the associated rwlock
196-
*/
197-
#define seqcount_rwlock_init(s, lock) \
198-
seqcount_locktype_init(s, lock)
199-
200170
/**
201171
* SEQCNT_MUTEX_ZERO - static initializer for seqcount_mutex_t
202172
* @name: Name of the seqcount_mutex_t instance
@@ -205,14 +175,6 @@ do { \
205175
#define SEQCNT_MUTEX_ZERO(name, lock) \
206176
SEQCOUNT_LOCKTYPE_ZERO(name, lock)
207177

208-
/**
209-
* seqcount_mutex_init - runtime initializer for seqcount_mutex_t
210-
* @s: Pointer to the seqcount_mutex_t instance
211-
* @lock: Pointer to the associated mutex
212-
*/
213-
#define seqcount_mutex_init(s, lock) \
214-
seqcount_locktype_init(s, lock)
215-
216178
/**
217179
* SEQCNT_WW_MUTEX_ZERO - static initializer for seqcount_ww_mutex_t
218180
* @name: Name of the seqcount_ww_mutex_t instance
@@ -222,15 +184,7 @@ do { \
222184
SEQCOUNT_LOCKTYPE_ZERO(name, lock)
223185

224186
/**
225-
* seqcount_ww_mutex_init - runtime initializer for seqcount_ww_mutex_t
226-
* @s: Pointer to the seqcount_ww_mutex_t instance
227-
* @lock: Pointer to the associated ww_mutex
228-
*/
229-
#define seqcount_ww_mutex_init(s, lock) \
230-
seqcount_locktype_init(s, lock)
231-
232-
/**
233-
* typedef seqcount_LOCKNAME_t - sequence counter with spinlock associated
187+
* typedef seqcount_LOCKNAME_t - sequence counter with LOCKTYPR associated
234188
* @seqcount: The real sequence counter
235189
* @lock: Pointer to the associated spinlock
236190
*
@@ -240,6 +194,12 @@ do { \
240194
* that the write side critical section is properly serialized.
241195
*/
242196

197+
/**
198+
* seqcount_LOCKNAME_init() - runtime initializer for seqcount_LOCKNAME_t
199+
* @s: Pointer to the seqcount_LOCKNAME_t instance
200+
* @lock: Pointer to the associated LOCKTYPE
201+
*/
202+
243203
/*
244204
* SEQCOUNT_LOCKTYPE() - Instantiate seqcount_LOCKNAME_t and helpers
245205
* @locktype: actual typename
@@ -253,6 +213,13 @@ typedef struct seqcount_##lockname { \
253213
__SEQ_LOCK(locktype *lock); \
254214
} seqcount_##lockname##_t; \
255215
\
216+
static __always_inline void \
217+
seqcount_##lockname##_init(seqcount_##lockname##_t *s, locktype *lock) \
218+
{ \
219+
seqcount_init(&s->seqcount); \
220+
__SEQ_LOCK(s->lock = lock); \
221+
} \
222+
\
256223
static __always_inline seqcount_t * \
257224
__seqcount_##lockname##_ptr(seqcount_##lockname##_t *s) \
258225
{ \

0 commit comments

Comments
 (0)