subscr: Introduce subscr_purge_inactive to free unused subscribers

Introduce a method that will remove all subscribers that have a
zero use count. This is useful if someone wants to purge subscribers
from memory or wants to disable the everything in RAM feature.
This commit is contained in:
Holger Hans Peter Freyther 2010-12-22 14:31:34 +01:00
parent daee5ca7c1
commit f694d5f47a
2 changed files with 17 additions and 0 deletions

View File

@ -90,6 +90,8 @@ struct gsm_subscriber *subscr_active_by_imsi(struct gsm_network *net,
char *subscr_name(struct gsm_subscriber *subscr);
int subscr_purge_inactive(struct gsm_network *net);
/* internal */
struct gsm_subscriber *subscr_alloc(void);
extern struct llist_head active_subscribers;

View File

@ -133,3 +133,18 @@ struct gsm_subscriber *subscr_active_by_imsi(struct gsm_network *net, const char
return NULL;
}
int subscr_purge_inactive(struct gsm_network *net)
{
struct gsm_subscriber *subscr, *tmp;
int purged = 0;
llist_for_each_entry_safe(subscr, tmp, subscr_bsc_active_subscriber(), entry) {
if (subscr->net == net && subscr->use_count <= 0) {
subscr_free(subscr);
purged += 1;
}
}
return purged;
}