Change in osmo-remsim[master]: slotmap: Introduce slotmap_{rd, wr, un}lock() wrappers for lock debugging

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Mar 8 07:58:27 UTC 2019


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/13185 )

Change subject: slotmap: Introduce slotmap_{rd,wr,un}lock() wrappers for lock debugging
......................................................................

slotmap: Introduce slotmap_{rd,wr,un}lock() wrappers for lock debugging

Change-Id: I8dde90d62e673e60e026979c74074f7084490467
---
M src/slotmap.c
M src/slotmap.h
2 files changed, 28 insertions(+), 12 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/slotmap.c b/src/slotmap.c
index f4a22e1..9e16fff 100644
--- a/src/slotmap.c
+++ b/src/slotmap.c
@@ -40,14 +40,14 @@
 {
 	struct slot_mapping *map;
 
-	pthread_rwlock_rdlock(&maps->rwlock);
+	slotmaps_rdlock(maps);
 	llist_for_each_entry(map, &maps->mappings, list) {
 		if (client_slot_equals(&map->client, client)) {
-			pthread_rwlock_unlock(&maps->rwlock);
+			slotmaps_unlock(maps);
 			return map;
 		}
 	}
-	pthread_rwlock_unlock(&maps->rwlock);
+	slotmaps_unlock(maps);
 	return NULL;
 }
 
@@ -56,14 +56,14 @@
 {
 	struct slot_mapping *map;
 
-	pthread_rwlock_rdlock(&maps->rwlock);
+	slotmaps_rdlock(maps);
 	llist_for_each_entry(map, &maps->mappings, list) {
 		if (bank_slot_equals(&map->bank, bank)) {
-			pthread_rwlock_unlock(&maps->rwlock);
+			slotmaps_unlock(maps);
 			return map;
 		}
 	}
-	pthread_rwlock_unlock(&maps->rwlock);
+	slotmaps_unlock(maps);
 	return NULL;
 
 }
@@ -102,13 +102,13 @@
 	map->bank = *bank;
 	map->client = *client;
 
-	pthread_rwlock_wrlock(&maps->rwlock);
+	slotmaps_wrlock(maps);
 	llist_add_tail(&map->list, &maps->mappings);
 #ifdef REMSIM_SERVER
 	map->state = SLMAP_S_NEW;
 	INIT_LLIST_HEAD(&map->bank_list); /* to ensure llist_del() always succeeds */
 #endif
-	pthread_rwlock_unlock(&maps->rwlock);
+	slotmaps_unlock(maps);
 
 	printf("Slot Map %s added\n", slotmap_name(mapname, sizeof(mapname), map));
 
@@ -132,9 +132,9 @@
 /* thread-safe removal of a bank<->client map */
 void slotmap_del(struct slotmaps *maps, struct slot_mapping *map)
 {
-	pthread_rwlock_wrlock(&maps->rwlock);
+	slotmaps_wrlock(maps);
 	_slotmap_del(maps, map);
-	pthread_rwlock_unlock(&maps->rwlock);
+	slotmaps_unlock(maps);
 }
 
 struct slotmaps *slotmap_init(void *ctx)
@@ -171,9 +171,9 @@
 void Slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state,
 			  struct llist_head *new_bank_list, const char *file, int line)
 {
-	pthread_rwlock_wrlock(&map->maps->rwlock);
+	slotmaps_wrlock(map->maps);
 	_Slotmap_state_change(map, new_state, new_bank_list, file, line);
-	pthread_rwlock_unlock(&map->maps->rwlock);
+	slotmaps_unlock(map->maps);
 }
 
 #endif
diff --git a/src/slotmap.h b/src/slotmap.h
index bc55f29..78dfff9 100644
--- a/src/slotmap.h
+++ b/src/slotmap.h
@@ -86,6 +86,22 @@
 /* initialize the entire map collection */
 struct slotmaps *slotmap_init(void *ctx);
 
+#define slotmaps_rdlock(maps) do {		\
+	printf("%s:%u = slotmap_rdlock()\n", __FILE__, __LINE__);		\
+	pthread_rwlock_rdlock(&(maps)->rwlock);	\
+} while (0)
+
+#define slotmaps_wrlock(maps) do {		\
+	printf("%s:%u = slotmap_wrlock()\n", __FILE__, __LINE__);		\
+	pthread_rwlock_wrlock(&(maps)->rwlock);	\
+} while (0)
+
+#define slotmaps_unlock(maps) do {		\
+	printf("%s:%u = slotmap_unlock()\n", __FILE__, __LINE__);		\
+	pthread_rwlock_unlock(&(maps)->rwlock);	\
+} while (0)
+
+
 #ifdef REMSIM_SERVER
 void _Slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state,
 			   struct llist_head *new_bank_list, const char *file, int line);

-- 
To view, visit https://gerrit.osmocom.org/13185
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-remsim
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I8dde90d62e673e60e026979c74074f7084490467
Gerrit-Change-Number: 13185
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190308/d89f34f0/attachment.html>


More information about the gerrit-log mailing list