示例#1
0
文件: cachemgr.c 项目: alhazred/onarm
int
get_clearance(int callnumber)
{
	sema_t	*table_sema = NULL;
	char	*tab;

	if (sema_trywait(&common_sema) == 0) {
		(void) thr_setspecific(lookup_state_key, NULL);
		return (0);
	}

	switch (callnumber) {
		case GETLDAPCONFIG:
			tab = "ldap";
			table_sema = &ldap_sema;
			break;
		default:
			logit("Internal Error: get_clearance\n");
			break;
	}

	if (sema_trywait(table_sema) == 0) {
		(void) thr_setspecific(lookup_state_key, (void*)1);
		return (0);
	}

	if (current_admin.debug_level >= DBG_CANT_FIND) {
		logit("get_clearance: throttling load for %s table\n", tab);
	}

	return (-1);
}
示例#2
0
/*
 * get clearance
 */
int
_nscd_get_clearance(sema_t *sema) {
	if (sema_trywait(&common_sema) == 0) {
		(void) thr_setspecific(lookup_state_key, NULL);
		return (0);
	}

	if (sema_trywait(sema) == 0) {
		(void) thr_setspecific(lookup_state_key, (void*)1);
		return (0);
	}

	return (1);
}
示例#3
0
int
sem_trywait(sem_t *sem)
{
	int	error;

	if (sem_invalid(sem))
		return (-1);
	if ((error = sema_trywait((sema_t *)sem)) != 0) {
		if (error == EBUSY)
			error = EAGAIN;
		errno = error;
		return (-1);
	}
	return (0);
}
示例#4
0
FINLINE int _sema_timedwait(
	sema_t *			pSem,
	unsigned int	msecs)
{
	int					iErr = 0;

   // If timeout is F_WAITFOREVER, do sem_wait.

   if( msecs == F_WAITFOREVER)
   {
      iErr = _sema_wait( pSem);
      return( iErr);
   }

	for( ;;)
	{
		if( (iErr = sema_trywait( pSem)) != 0)
		{
			if( iErr == EINTR)
			{
				iErr = 0;
			}

			f_sleep( f_min( msecs, 10));
			msecs -= f_min( msecs, 10);

			if( !msecs)
			{
				iErr = -1;
				goto Exit;
			}

			continue;
		}
	}

Exit:

	return( iErr);
}