Example #1
0
void			free(void *ptr)
{
	t_block		*block;
	t_zone		*zone;

	if (!ptr)
		return ;
	pthread_mutex_lock(&g_mutex);
	block = (t_block *)(ptr - HEADER_SIZE);
	if (!block->parent)
	{
		pthread_mutex_unlock(&g_mutex);
		return ;
	}
	block->flag = FREE;
	zone = block->parent;
	zone->blocks_used--;
	zone->size_free += block->size + HEADER_SIZE;
	if (zone->blocks_used <= 0 || zone->type == LARGE_INDEX)
		free_zone(zone);
	else
		defrag(block);
	ptr = NULL;
	pthread_mutex_unlock(&g_mutex);
}
Example #2
0
/* remove an existing country and all its indications, country must exist.
 * Also, all countries which are an alias for the specified country are removed. */
int cw_unregister_indication_country(const char *country)
{
	struct tone_zone *tz, *pz = NULL, *tmp;
	int res = -1;

	if (cw_mutex_lock(&tzlock))
    {
		cw_log(LOG_WARNING, "Unable to lock tone_zones list\n");
		return -1;
	}
	tz = tone_zones;
	while (tz)
    {
		if (country == NULL
            ||
		    (strcasecmp(country, tz->country) == 0
            ||
		     strcasecmp(country, tz->alias) == 0))
        {
			/* tone_zone found, remove */
			tmp = tz->next;
			if (pz)
				pz->next = tmp;
			else
				tone_zones = tmp;
			/* if we are unregistering the default country, w'll notice */
			if (tz == current_tonezone) {
				cw_log(LOG_NOTICE,"Removed default indication country '%s'\n",tz->country);
				current_tonezone = NULL;
			}
			if (option_verbose > 2)
				cw_verbose(VERBOSE_PREFIX_3 "Unregistered indication country '%s'\n",tz->country);
			free_zone(tz);
			if (tone_zones == tz)
				tone_zones = tmp;
			tz = tmp;
			res = 0;
		}
		else {
			/* next zone please */
			pz = tz;
			tz = tz->next;
		}
	}
	cw_mutex_unlock(&tzlock);
	return res;
}
Example #3
0
/* add a new country, if country exists, it will be replaced. */
int cw_register_indication_country(struct tone_zone *zone)
{
	struct tone_zone *tz,*pz;

	if (cw_mutex_lock(&tzlock))
    {
		cw_log(LOG_WARNING, "Unable to lock tone_zones list\n");
		return -1;
	}
	for (pz = NULL, tz = tone_zones;  tz;  pz = tz, tz = tz->next)
    {
		if (strcasecmp(zone->country,tz->country) == 0)
        {
			/* tone_zone already there, replace */
			zone->next = tz->next;
			if (pz)
				pz->next = zone;
			else
				tone_zones = zone;
			/* if we are replacing the default zone, re-point it */
			if (tz == current_tonezone)
				current_tonezone = zone;
			/* now free the previous zone */
			free_zone(tz);
			cw_mutex_unlock(&tzlock);
			return 0;
		}
	}
	/* country not there, add */
	zone->next = NULL;
	if (pz)
		pz->next = zone;
	else
		tone_zones = zone;
	cw_mutex_unlock(&tzlock);

	if (option_verbose > 2)
		cw_verbose(VERBOSE_PREFIX_3 "Registered indication country '%s'\n",zone->country);
	return 0;
}