From 4b676bc6f1ef6027b430e44fa24bf199d0b8b04b Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 7 Mar 2019 21:01:38 +0100 Subject: [PATCH] slotmap: Log file/line when changing state Change-Id: Idc7b350b464ddc50076f92dae592a0d5ad4d486a --- src/debug.h | 1 + src/slotmap.c | 18 ++++++++---------- src/slotmap.h | 12 ++++++++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/debug.h b/src/debug.h index 02551eb..e3994b4 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,4 +1,5 @@ #pragma once +#include enum { DMAIN, diff --git a/src/slotmap.c b/src/slotmap.c index aa03638..f4a22e1 100644 --- a/src/slotmap.c +++ b/src/slotmap.c @@ -12,6 +12,7 @@ #include #include "slotmap.h" +#include "debug.h" const struct value_string slot_map_state_name[] = { { SLMAP_S_NEW, "NEW" }, @@ -148,33 +149,30 @@ struct slotmaps *slotmap_init(void *ctx) #ifdef REMSIM_SERVER -void _slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state, - struct llist_head *new_bank_list) +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) { char mapname[64]; - printf("Slot Map %s state change: %s -> %s\n", slotmap_name(mapname, sizeof(mapname), map), + LOGPSRC(DMAIN, LOGL_INFO, file, line, "Slot Map %s state change: %s -> %s\n", + slotmap_name(mapname, sizeof(mapname), map), get_value_string(slot_map_state_name, map->state), get_value_string(slot_map_state_name, new_state)); map->state = new_state; -#ifdef REMSIM_SERVER llist_del(&map->bank_list); -#endif if (new_bank_list) llist_add_tail(&map->bank_list, new_bank_list); -#ifdef REMSIM_SERVER else INIT_LLIST_HEAD(&map->bank_list); -#endif } -void slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state, - struct llist_head *new_bank_list) +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); - _slotmap_state_change(map, new_state, new_bank_list); + _Slotmap_state_change(map, new_state, new_bank_list, file, line); pthread_rwlock_unlock(&map->maps->rwlock); } diff --git a/src/slotmap.h b/src/slotmap.h index 3eb976f..bc55f29 100644 --- a/src/slotmap.h +++ b/src/slotmap.h @@ -87,9 +87,13 @@ void _slotmap_del(struct slotmaps *maps, struct slot_mapping *map); struct slotmaps *slotmap_init(void *ctx); #ifdef REMSIM_SERVER -void _slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state, - struct llist_head *new_bank_list); +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); /* thread-safe way to change the state of given slot map */ -void slotmap_state_change(struct slot_mapping *map, enum slot_mapping_state new_state, - struct llist_head *new_bank_list); +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); +#define _slotmap_state_change(map, state, list) \ + _Slotmap_state_change(map, state, list, __FILE__, __LINE__) +#define slotmap_state_change(map, state, list) \ + Slotmap_state_change(map, state, list, __FILE__, __LINE__) #endif