static void wait_result() { if (!tool_ip) { //printf("Calling BBA syscall without dc-load client attached !\n"); syscall_retval = -1; return; } int fc = ta_state.frame_counter; waiting_thd = thd_current; do { //thd_pass(); sem_wait_timed(result_sema, 500); if (!escape_loop && ta_state.frame_counter - fc > 60) { tool_ip = 0; printf("BBA syscall timed out !\n" "Please reconnect the dc-load client.\n"); syscall_retval = -1; waiting_thd = NULL; return; } } while (!escape_loop); waiting_thd = NULL; escape_loop = 0; }
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) { int retval; if ( ! sem ) { SDL_SetError("Passed a NULL semaphore"); return -1; } /* A timeout of 0 is an easy case */ if ( timeout == 0 ) { return SDL_SemTryWait(sem); } retval = sem_wait_timed(&sem->sem,timeout); if (retval==-1) retval= SDL_MUTEX_TIMEDOUT; return retval; }
int conio_input_getline(int block, char *dst, int dstcnt) { cb_sem_data_t *t, *l; /* assert_msg( block != 0, "non-blocking I/O not supported yet" ); */ if (!block && cb_queue == NULL) return -1; /* Did we quit already? */ if (cb_dead) return -1; /* Wait for some input to be ready */ if (block > 0) { if (sem_wait_timed(cb_sem, block) < 0) return -1; } else { if (sem_wait(cb_sem) < 0) return -1; } /* Grab the mutex and retrieve the line */ sem_wait(cb_mutex); assert( cb_queue != NULL ); for (l=NULL, t=(cb_sem_data_t *)cb_queue; t->next; t=t->next) l=t; assert( t->next == NULL ); if (l != NULL) { assert( l->next == t ); l->next = NULL; } else { cb_queue = NULL; } sem_signal(cb_mutex); strncpy(dst, t->line, dstcnt-1); dst[dstcnt-1] = '\0'; free(t); return 0; }