slotmap: Add _slotmap_del() for callers that already have a lock

Change-Id: Id05872c3676d0afe4c7abe74677fee62b4f03e53
This commit is contained in:
Harald Welte 2019-03-07 10:08:25 +01:00
parent c86568359c
commit 294298c4af
2 changed files with 9 additions and 3 deletions

View File

@ -115,21 +115,26 @@ struct slot_mapping *slotmap_add(struct slotmaps *maps, const struct bank_slot *
} }
/* thread-safe removal of a bank<->client map */ /* thread-safe removal of a bank<->client map */
void slotmap_del(struct slotmaps *maps, struct slot_mapping *map) void _slotmap_del(struct slotmaps *maps, struct slot_mapping *map)
{ {
char mapname[64]; char mapname[64];
printf("Slot Map %s deleted\n", slotmap_name(mapname, sizeof(mapname), map)); printf("Slot Map %s deleted\n", slotmap_name(mapname, sizeof(mapname), map));
pthread_rwlock_wrlock(&maps->rwlock);
llist_del(&map->list); llist_del(&map->list);
#ifdef REMSIM_SERVER #ifdef REMSIM_SERVER
llist_del(&map->bank_list); llist_del(&map->bank_list);
#endif #endif
pthread_rwlock_unlock(&maps->rwlock);
talloc_free(map); talloc_free(map);
} }
/* thread-safe removal of a bank<->client map */
void slotmap_del(struct slotmaps *maps, struct slot_mapping *map)
{
pthread_rwlock_wrlock(&maps->rwlock);
_slotmap_del(maps, map);
pthread_rwlock_unlock(&maps->rwlock);
}
struct slotmaps *slotmap_init(void *ctx) struct slotmaps *slotmap_init(void *ctx)
{ {

View File

@ -81,6 +81,7 @@ struct slot_mapping *slotmap_add(struct slotmaps *maps, const struct bank_slot *
/* thread-safe removal of a bank<->client map */ /* thread-safe removal of a bank<->client map */
void slotmap_del(struct slotmaps *maps, struct slot_mapping *map); void slotmap_del(struct slotmaps *maps, struct slot_mapping *map);
void _slotmap_del(struct slotmaps *maps, struct slot_mapping *map);
/* initialize the entire map collection */ /* initialize the entire map collection */
struct slotmaps *slotmap_init(void *ctx); struct slotmaps *slotmap_init(void *ctx);