lock = &(fd_table[i]->lock); while (SEMAPHORE_TEST_AND_SET(lock)) { continue;
if (fd_check_entry(i) == OK) { mutex = &(fd_table[i]->mutex); if (pthread_mutex_trylock(mutex)) { continue; } if (fd_table[i]->count || fd_table[i]->r_owner || fd_table[i]->w_owner) { pthread_mutex_unlock(mutex); continue; } if (fd_table[i]->type == FD_NT) {  if ((machdep_sys_fcntl(i, F_GETFL, NULL)) >= OK) {  pthread_mutex_unlock(mutex); continue; } } fd_table[i]->count++; pthread_mutex_unlock(mutex); return(i);
int fd_allocate(){	semaphore *lock;	int i;	for (i = 0; i < dtablesize; i++) {		lock = &(fd_table[i]->lock);		while (SEMAPHORE_TEST_AND_SET(lock)) {			continue;		}		if (fd_table[i]->count || fd_table[i]->r_owner		  || fd_table[i]->w_owner) {			SEMAPHORE_RESET(lock);			continue;		}		if (fd_table[i]->type == FD_NT) {			/* Test to see if the kernel version is in use */			/* If so continue; */		}		fd_table[i]->count++;		SEMAPHORE_RESET(lock);		return(i);	}	pthread_run->error = ENFILE;	return(NOTOK);}