Change in osmo-remsim[master]: slotmap: Introduce slotmap-printing function and use it

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Mar 7 20:37:47 UTC 2019


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

Change subject: slotmap: Introduce slotmap-printing function and use it
......................................................................

slotmap: Introduce slotmap-printing function and use it

... avoid code duplication

Change-Id: I6458b9d222ed9f4113c3bb1c538b4b710559c6b2
---
M src/slotmap.c
1 file changed, 13 insertions(+), 4 deletions(-)

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



diff --git a/src/slotmap.c b/src/slotmap.c
index 303f5fd..a3ae792 100644
--- a/src/slotmap.c
+++ b/src/slotmap.c
@@ -12,6 +12,14 @@
 
 #include "slotmap.h"
 
+const char *slotmap_name(char *buf, size_t buf_len, const struct slot_mapping *map)
+{
+	snprintf(buf, buf_len, "B(%u:%u) <-> C(%u:%u)",
+		 map->bank.bank_id, map->bank.slot_nr, map->client.client_id, map->client.slot_nr);
+	return buf;
+}
+
+
 /* thread-safe lookup of map by client:slot */
 struct slot_mapping *slotmap_by_client(struct slotmaps *maps, const struct client_slot *client)
 {
@@ -49,6 +57,7 @@
 int slotmap_add(struct slotmaps *maps, const struct bank_slot *bank, const struct client_slot *client)
 {
 	struct slot_mapping *map;
+	char mapname[64];
 
 	/* We assume a single thread (main thread) will ever update the mappings,
 	 * and hence we don't have any races by first grabbing + releasing the read
@@ -80,8 +89,7 @@
 	llist_add_tail(&map->list, &maps->mappings);
 	pthread_rwlock_unlock(&maps->rwlock);
 
-	printf("Added Slot Map C(%u:%u) <-> B(%u:%u)\n",
-		map->client.client_id, map->client.slot_nr, map->bank.bank_id, map->bank.slot_nr);
+	printf("Slot Map %s added\n", slotmap_name(mapname, sizeof(mapname), map));
 
 	return 0;
 }
@@ -89,8 +97,9 @@
 /* thread-safe removal of a bank<->client map */
 void slotmap_del(struct slotmaps *maps, struct slot_mapping *map)
 {
-	printf("Deleting Slot Map C(%u:%u) <-> B(%u:%u)\n",
-		map->client.client_id, map->client.slot_nr, map->bank.bank_id, map->bank.slot_nr);
+	char mapname[64];
+
+	printf("Slot Map %s deleted\n", slotmap_name(mapname, sizeof(mapname), map));
 
 	pthread_rwlock_wrlock(&maps->rwlock);
 	llist_del(&map->list);

-- 
To view, visit https://gerrit.osmocom.org/13178
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: I6458b9d222ed9f4113c3bb1c538b4b710559c6b2
Gerrit-Change-Number: 13178
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/20190307/2b5de8b7/attachment.htm>


More information about the gerrit-log mailing list