slotmap: Log file/line when changing state

Change-Id: Idc7b350b464ddc50076f92dae592a0d5ad4d486a
This commit is contained in:
Harald Welte 2019-03-07 21:01:38 +01:00
parent 294298c4af
commit 4b676bc6f1
3 changed files with 17 additions and 14 deletions

View File

@ -1,4 +1,5 @@
#pragma once
#include <osmocom/core/logging.h>
enum {
DMAIN,

View File

@ -12,6 +12,7 @@
#include <osmocom/core/utils.h>
#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);
}

View File

@ -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