plock = &(pthread_run->lock); while (SEMAPHORE_TEST_AND_SET(plock)) { pthread_yield(); }
pthread_run->data.fd.fd = fd; SET_PF_WAIT_EVENT(pthread_run); pthread_queue_enq(&fd_wait_read, pthread_run);
int __fd_kern_readv(int fd, int flags, struct iovec *iov, int iovcnt){	semaphore *lock, *plock;	int ret;	while ((ret = machdep_sys_readv(fd, iov, iovcnt)) < 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);}