示例#1
0
static int cfg_lock_helper(str *lkey, int mode)
{
	unsigned int pos;
	pos = core_case_hash(lkey, 0, _cfg_lock_size);

	LM_DBG("cfg_lock mode %d on %u\n", mode, pos);

	if(mode==0) {
		/* Lock */
		lock_set_get(_cfg_lock_set, pos);
	} else if (mode == 1) {
		/* Unlock */
		lock_set_release(_cfg_lock_set, pos);
	} else {
		int res;
		/* Trylock */
		res = lock_set_try(_cfg_lock_set, pos);
		if (res != 0) {
			LM_DBG("Failed to trylock \n");
			/* Failed to lock */
			return -1;
		}
		LM_DBG("Succeeded with trylock \n");
		/* Succeeded in locking */
		return 1;
	}
	return 1;
}
示例#2
0
static int cfg_lock_helper(str *lkey, int mode)
{
	unsigned int pos;

	if(_cfg_lock_set==NULL) {
		LM_ERR("lock set not initialized (attempt to do op: %d on: %.*s) -"
				" see param lock_set_size\n",
				mode, lkey->len, lkey->s);
		return -1;
	}
	pos = core_case_hash(lkey, 0, _cfg_lock_size);

	LM_DBG("cfg_lock mode %d on %u (%.*s)\n", mode, pos, lkey->len, lkey->s);

	if(mode==0) {
		/* Lock */
		lock_set_get(_cfg_lock_set, pos);
	} else if (mode == 1) {
		/* Unlock */
		lock_set_release(_cfg_lock_set, pos);
	} else {
		int res;
		/* Trylock */
		res = lock_set_try(_cfg_lock_set, pos);
		if (res != 0) {
			LM_DBG("Failed to trylock \n");
			/* Failed to lock */
			return -1;
		}
		LM_DBG("Succeeded with trylock \n");
		/* Succeeded in locking */
		return 1;
	}
	return 1;
}