FreeBSD/contrib/sendmail/libmilter/worker.c
/*
**  MI_POOL_CONTROLLER_INIT -- Launch the worker pool controller
**		Must be called before starting sessions.
**
**	Parameters:
**		none
**
**	Returns:
**		MI_SUCCESS/MI_FAILURE
*/
- Launch the worker pool controller
Must be called before starting sessions.

none


- Launch the worker pool controller Must be called before starting sessions . none
int
mi_pool_controller_init()
{
	sthread_t tid;
	int r, i;
	if (Tskmgr.tm_signature == TM_SIGNATURE)
		return MI_SUCCESS;
	SM_TAILQ_INIT(&WRK_CTX_HEAD);
	Tskmgr.tm_tid = (sthread_t) -1;
	Tskmgr.tm_nb_workers = 0;
	Tskmgr.tm_nb_idle = 0;
	if (pipe(Tskmgr.tm_p) != 0)
	{
		smi_log(SMI_LOG_ERR, "can't create event pipe: %s",
			sm_errstring(errno));
		return MI_FAILURE;
	}
	r = nonblocking(WR_PIPE, "WR_PIPE");
	if (r != MI_SUCCESS)
		return r;
	r = nonblocking(RD_PIPE, "RD_PIPE");
	if (r != MI_SUCCESS)
		return r;
	(void) smutex_init(&Tskmgr.tm_w_mutex);
	(void) scond_init(&Tskmgr.tm_w_cond);
	if ((r = thread_create(&tid, mi_pool_controller, (void *) NULL)) != 0)
	{
		smi_log(SMI_LOG_ERR, "can't create controller thread: %s",
			sm_errstring(r));
		return MI_FAILURE;
	}
	Tskmgr.tm_tid = tid;
	Tskmgr.tm_signature = TM_SIGNATURE;
	for (i = 0; i < MIN_WORKERS; i++)
	{
		if ((r = thread_create(&tid, mi_worker, (void *) NULL)) != 0)
		{
			smi_log(SMI_LOG_ERR, "can't create workers crew: %s",
				sm_errstring(r));
			return MI_FAILURE;
		}
	}
	return MI_SUCCESS;
}
int mi_pool_controller_init ( ) { sthread_t tid ; int r , i ; if ( Tskmgr . tm_signature == TM_SIGNATURE ) return MI_SUCCESS ; SM_TAILQ_INIT ( & WRK_CTX_HEAD ) ; Tskmgr . tm_tid = ( sthread_t ) - 1 ; Tskmgr . tm_nb_workers = 0 ; Tskmgr . tm_nb_idle = 0 ; if ( pipe ( Tskmgr . tm_p ) != 0 ) { smi_log ( SMI_LOG_ERR , " " , sm_errstring ( errno ) ) ; return MI_FAILURE ; } r = nonblocking ( WR_PIPE , " " ) ; if ( r != MI_SUCCESS ) return r ; r = nonblocking ( RD_PIPE , " " ) ; if ( r != MI_SUCCESS ) return r ; ( void ) smutex_init ( & Tskmgr . tm_w_mutex ) ; ( void ) scond_init ( & Tskmgr . tm_w_cond ) ; if ( ( r = thread_create ( & tid , mi_pool_controller , ( void * ) NULL ) ) != 0 ) { smi_log ( SMI_LOG_ERR , " " , sm_errstring ( r ) ) ; return MI_FAILURE ; } Tskmgr . tm_tid = tid ; Tskmgr . tm_signature = TM_SIGNATURE ; for ( i = 0 ; i < MIN_WORKERS ; i ++ ) { if ( ( r = thread_create ( & tid , mi_worker , ( void * ) NULL ) ) != 0 ) { smi_log ( SMI_LOG_ERR , " " , sm_errstring ( r ) ) ; return MI_FAILURE ; } } return MI_SUCCESS ; }
MI_POOL_CONTROLLER_INIT -- Launch the worker pool controller
Must be called before starting sessions.
MI_POOL_CONTROLLER_INIT -- Launch the worker pool controller Must be called before starting sessions .
/* Launch the pool controller */ /* Create the pool of workers */