/*
 * The lwp_scheduler thread periodically checks to see if any threads
 * are due to be resumed.  If there are, it resumes them.  Otherwise,
 * it computes the lesser of ( 1 second ) or ( the minimum time until
 * a thread need to be resumed ) and puts itself to sleep for that amount
 * of time.
 */
static void
lwp_scheduler(
	int		stackno
)
{
	time_t			now, min;
	struct timeval		interval;
	tl_t			*t;

	while ( !sglob->slurpd_shutdown ) {
		mon_enter( &sglob->tsl_mon );

		time( &now );
		min = 0L;
		if ( sglob->tsl_list != NULL ) {
			for ( t = sglob->tsl_list; t != NULL; t = t->tl_next ) {
				if (( t->tl_wake  > 0L ) && ( t->tl_wake < now )) {
					lwp_resume( t->tl_tid );
					t->tl_wake = 0L;
				}

				if (( t->tl_wake > now ) && ( t->tl_wake < min )) {
					min =  t->tl_wake;
				}
			}
		}

		mon_exit( &sglob->tsl_mon );

		interval.tv_usec = 0L;
		if ( min == 0L ) {
			interval.tv_sec = 1L;
		} else {
			interval.tv_sec = min;
		}

		lwp_sleep( &interval );
	}

	mon_enter( &sglob->tsl_mon );

	for ( t = sglob->tsl_list; t != NULL; t = t->tl_next ) {
		lwp_resume( t->tl_tid );
	}

	mon_exit( &sglob->tsl_mon );

	free_stack( stackno );
}
int thr_continue(int tid)
{
  return( lwp_resume(thread_table[tid]) );
}