pthread_run->next = fd_wait_read; fd_wait_read = pthread_run; pthread_run->fd = fd; SEMAPHORE_RESET(lock); reschedule(PS_FDR_WAIT); } else { pthread_run->error = -ret; ret = NOTOK; break; }
if (timeout) {  struct timespec current_time; machdep_gettimeofday(&current_time); sleep_schedule(&current_time, timeout);  SET_PF_AT_CANCEL_POINT(pthread_run); pthread_resched_resume(PS_FDR_WAIT); CLEAR_PF_AT_CANCEL_POINT(pthread_run);   pthread_sched_prevent(); if (sleep_cancel(pthread_run) == NOTOK) { CLEAR_PF_DONE_EVENT(pthread_run); pthread_sched_resume(); SET_ERRNO(ETIMEDOUT); ret= NOTOK; break;
ssize_t __fd_kern_read(int fd, int flags, void *buf, size_t nbytes){	semaphore *lock, *plock;	int ret;	while ((ret = machdep_sys_read(fd, buf, nbytes)) < OK) { 		if (ret == -EWOULDBLOCK) {			/* Lock queue */			lock = &fd_wait_lock;			while (SEMAPHORE_TEST_AND_SET(lock)) {				pthread_yield();			}			/* Lock pthread */			plock = &(pthread_run->lock);			while (SEMAPHORE_TEST_AND_SET(plock)) {				pthread_yield();			}			/* queue pthread for a FDR_WAIT */			pthread_run->next = fd_wait_read;			fd_wait_read = pthread_run;			pthread_run->fd = fd;			SEMAPHORE_RESET(lock);			reschedule(PS_FDR_WAIT);		} else {			pthread_run->error = -ret;			ret = NOTOK;			break;		}	}	return(ret);}