struct pthread **pthread; sigset_t sig_to_block; int count;  if (fd_wait_read || fd_wait_write) { for (pthread = &fd_wait_read; *pthread; pthread = &((*pthread)->next)) { FD_SET((*pthread)->fd, &fd_set_read); } for (pthread = &fd_wait_write; *pthread; pthread = &((*pthread)->next)) { FD_SET((*pthread)->fd, &fd_set_write); }    sigfillset(&sig_to_block); sigprocmask(SIG_BLOCK, &sig_to_block, NULL);  machdep_unset_thread_timer(); __fd_kern_wait_timeout.tv_usec = 0; __fd_kern_wait_timeout.tv_sec = 3600;  sigprocmask(SIG_UNBLOCK, &sig_to_block, NULL);    while ((count = machdep_sys_select(dtablesize, &fd_set_read, &fd_set_write, NULL, &__fd_kern_wait_timeout)) < OK) { if (count == -EINTR) { return; } PANIC(); }  for (pthread = &fd_wait_read; count && *pthread; ) { if (FD_ISSET((*pthread)->fd, &fd_set_read)) {   (*pthread)->state = PS_RUNNING; *pthread = (*pthread)->next; count--; continue; } pthread = &((*pthread)->next); }  for (pthread = &fd_wait_write; count && *pthread; ) { if (FD_ISSET((*pthread)->fd, &fd_set_write)) { semaphore *plock;   plock = &(*pthread)->lock; if (!(SEMAPHORE_TEST_AND_SET(plock))) {  (*pthread)->state = PS_RUNNING; *pthread = (*pthread)->next; SEMAPHORE_RESET(plock); } count--; continue; } pthread = &((*pthread)->next); } } else {  sig_handler_pause(); }
if (fd_kern_select(&__fd_kern_wait_timeout))  sig_handler_pause();
void fd_kern_wait(){	struct pthread **pthread;	sigset_t sig_to_block;	int count;	if (fd_wait_read || fd_wait_write) {		for (pthread = &fd_wait_read; *pthread; pthread = &((*pthread)->next)) {			FD_SET((*pthread)->fd, &fd_set_read);		}		for (pthread = &fd_wait_write; *pthread; pthread = &((*pthread)->next)) {			FD_SET((*pthread)->fd, &fd_set_write);		}		/* Turn off interrupts for real while we set the timer.  */		sigfillset(&sig_to_block);		sigprocmask(SIG_BLOCK, &sig_to_block, NULL);		machdep_unset_thread_timer(); 		__fd_kern_wait_timeout.tv_usec = 0;		__fd_kern_wait_timeout.tv_sec = 3600;		sigprocmask(SIG_UNBLOCK, &sig_to_block, NULL);		/*		 * There is a small but finite chance that an interrupt will		 * occure between the unblock and the select. Because of this		 * sig_handler_real() sets the value of __fd_kern_wait_timeout		 * to zero causing the select to do a poll instead of a wait.		 */		while ((count = machdep_sys_select(dtablesize, &fd_set_read,		  &fd_set_write, NULL, &__fd_kern_wait_timeout)) < OK) {			if (count == -EINTR) {				return;			}			PANIC();		}			for (pthread = &fd_wait_read; count && *pthread; ) {			if (FD_ISSET((*pthread)->fd, &fd_set_read)) {				/* Get lock on thread */				(*pthread)->state = PS_RUNNING;				*pthread = (*pthread)->next;				count--;				continue;			} 			pthread = &((*pthread)->next);		}							for (pthread = &fd_wait_write; count && *pthread; ) {			if (FD_ISSET((*pthread)->fd, &fd_set_write)) {				semaphore *plock;				/* Get lock on thread */				plock = &(*pthread)->lock;				if (!(SEMAPHORE_TEST_AND_SET(plock))) {					/* Thread locked, skip it. */					(*pthread)->state = PS_RUNNING;					*pthread = (*pthread)->next;					SEMAPHORE_RESET(plock);				}				count--;				continue;			} 			pthread = &((*pthread)->next);		}	} else {		/* No threads, waiting on I/O, do a sigsuspend */		sig_handler_pause();	}}