Skip to content

Commit 3dac0cf

Browse files
committed
synch: rwlocks should belong to a lock class
This will allow us to track dependencies between mutexes and rwlocks. Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
1 parent 40193fb commit 3dac0cf

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

include/jeffpc/synch.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ struct barrier {
114114
}; \
115115
mxunlock(&mx_ctx, (l)); \
116116
} while (0)
117-
#define RWINIT(l) do { \
117+
#define RWINIT(l, lc) do { \
118118
struct lock_context rw_ctx = { \
119119
.lockname = #l, \
120120
.file = __FILE__, \
121121
.line = __LINE__, \
122122
}; \
123-
rwinit(&rw_ctx, (l)); \
123+
rwinit(&rw_ctx, (l), (lc)); \
124124
} while (0)
125125
#define RWDESTROY(l) do { \
126126
struct lock_context rw_ctx = { \
@@ -247,7 +247,8 @@ extern void mxdestroy(const struct lock_context *where, struct lock *m);
247247
extern void mxlock(const struct lock_context *where, struct lock *m);
248248
extern void mxunlock(const struct lock_context *where, struct lock *m);
249249

250-
extern void rwinit(const struct lock_context *where, struct rwlock *l);
250+
extern void rwinit(const struct lock_context *where, struct rwlock *l,
251+
struct lock_class *lc);
251252
extern void rwdestroy(const struct lock_context *where, struct rwlock *l);
252253
extern void rwlock(const struct lock_context *where, struct rwlock *l, bool wr);
253254
extern void rwunlock(const struct lock_context *where, struct rwlock *l);

synch.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,19 @@ static void verify_lock_unlock(const struct lock_context *where, struct lock *l)
588588
check_held_for_unlock(&l->info, where);
589589
}
590590

591-
static void verify_rw_init(const struct lock_context *where, struct rwlock *l)
591+
static void verify_rw_init(const struct lock_context *where, struct rwlock *l,
592+
struct lock_class *lc)
592593
{
593-
if (!l)
594+
if (!l || !lc)
594595
print_invalid_call("RWINIT", where);
595596

596597
l->info.magic = (uintptr_t) &l->info;
597598
l->info.type = SYNCH_TYPE_RW;
599+
600+
#ifdef JEFFPC_LOCK_TRACKING
601+
l->info.lc = lc;
602+
l->info.name = where->lockname;
603+
#endif
598604
}
599605

600606
static void verify_rw_destroy(const struct lock_context *where, struct rwlock *l)
@@ -776,11 +782,12 @@ void mxunlock(const struct lock_context *where, struct lock *l)
776782
where->file, where->line, strerror(ret));
777783
}
778784

779-
void rwinit(const struct lock_context *where, struct rwlock *l)
785+
void rwinit(const struct lock_context *where, struct rwlock *l,
786+
struct lock_class *lc)
780787
{
781788
int ret;
782789

783-
verify_rw_init(where, l);
790+
verify_rw_init(where, l, lc);
784791

785792
ret = pthread_rwlock_init(&l->lock, NULL);
786793
if (ret)

0 commit comments

Comments
 (0)