void *__paused_thread(void *req) { LPVOID (*funk)(void *arg); THREAD *thread; struct thread_conditional *tc = (struct thread_conditional *)(req); tc->thread->id = gettid(); signal(SIGTERM, __thread_cancelled); pthread_mutex_lock(&tc->suspend_mutex); while(tc->engine_running == FALSE) { pthread_cond_wait(&tc->suspend_cond, &tc->suspend_mutex); } pthread_mutex_unlock(&tc->suspend_mutex); funk = tc->funk; thread = tc->thread; free(tc); if(event_poll(thread->sigterm, 0) == TRUE) { /* * In some cases, we might want to stop a thread before it does anything :/ */ return NULL; } return funk(thread); }
static bool input_poll(int32_t ms) { if (embedded_mode) { EventSource input_sources[] = { signal_event_source(), NULL }; return event_poll(ms, input_sources); } EventSource input_sources[] = { rstream_event_source(read_stream), NULL }; return input_ready() || event_poll(ms, input_sources) || input_ready(); }
void MouseGetDelta (int *dx, int *dy) { #ifdef FAST_EVENTPOLL if (gameOpts->legacy.bInput) event_poll (SDL_MOUSEEVENTMASK); //polled in main/KConfig.c:read_bm_all() #else if (!bFastPoll) event_poll (SDL_MOUSEEVENTMASK); //polled in main/KConfig.c:read_bm_all() #endif *dx = mouseData.dx; *dy = mouseData.dy; mouseData.dx = 0; mouseData.dy = 0; }
//------------------------------------------------------------------------------ // Returns 1 if this button is currently down int MouseButtonState (int button) { int h; #ifndef FAST_EVENTPOLL if (!bFastPoll) event_poll(SDL_MOUSEEVENTMASK); //polled in main/KConfig.c:read_bm_all() #else if (gameOpts->legacy.bInput) event_poll(SDL_MOUSEEVENTMASK); //polled in main/KConfig.c:read_bm_all() #endif h = mouseData.buttons [button].rotated; mouseData.buttons [button].rotated = 0; return mouseData.buttons [button].pressed || h; }
/// Releases job control resources and terminates running jobs void job_teardown(void) { // 20 tries will give processes about 1 sec to exit cleanly uint32_t remaining_tries = 20; bool all_dead = true; int i; Job *job; // Politely ask each job to terminate for (i = 0; i < MAX_RUNNING_JOBS; i++) { if ((job = table[i]) != NULL) { all_dead = false; uv_process_kill(&job->proc, SIGTERM); } } if (all_dead) { return; } os_delay(10, 0); // Right now any exited process are zombies waiting for us to acknowledge // their status with `wait` or handling SIGCHLD. libuv does that // automatically (and then calls `exit_cb`) but we have to give it a chance // by running the loop one more time event_poll(0); // Prepare to start shooting for (i = 0; i < MAX_RUNNING_JOBS; i++) { job = table[i]; // Still alive while (job && is_alive(job) && remaining_tries--) { os_delay(50, 0); // Acknowledge child exits event_poll(0); // It's possible that the event_poll call removed the job from the table, // reset 'job' so the next iteration won't run in that case. job = table[i]; } if (job && is_alive(job)) { uv_process_kill(&job->proc, SIGKILL); } } // Last run to ensure all children were removed event_poll(0); }
DWORD sniffer_thread(THREAD *thread) { int fd; fd_set rfds; struct timeval tv; int count; CaptureJob *j = (CaptureJob *)(thread->parameter1); fd = pcap_get_selectable_fd(j->pcap); dprintf("pcap @ %p, selectable fd is %d", j->pcap, fd); while(event_poll(thread->sigterm, 0) == FALSE && j->active) { tv.tv_sec = 0; tv.tv_usec = 5000; FD_ZERO(&rfds); FD_SET(pcap_get_selectable_fd(j->pcap), &rfds); select(fd+1, &rfds, NULL, NULL, &tv); count = pcap_dispatch(j->pcap, 100, packet_handler, (u_char *)(j)); if (-1 == count) dprintf("pcap error: %s", pcap_geterr(j->pcap)); if(count <= 0) continue; if(count) dprintf("dispatched %d packets", count); } dprintf("and we're done"); return 0; }
void mouse_get_pos_z( int *x, int *y, int *z ) { event_poll(); *x=Mouse.x; *y=Mouse.y; *z=Mouse.z; }
// Process the first event in queue, sending to the appropriate handler // This is the new object-oriented system // Uses the old system for now, but this may change void event_process(void) { d_event event; window *wind = window_get_front(); timer_update(); event_poll(); // send input events first // Doing this prevents problems when a draw event can create a newmenu, // such as some network menus when they report a problem if (window_get_front() != wind) return; event.type = EVENT_WINDOW_DRAW; // then draw all visible windows wind = window_get_first(); while (wind != NULL) { window *prev = window_get_prev(wind); if (window_is_visible(wind)) window_send_event(wind, &event); if (!window_exists(wind)) { if (!prev) // well there isn't a previous window ... break; // ... just bail out - we've done everything for this frame we can. wind = window_get_next(prev); // the current window seemed to be closed. so take the next one from the previous which should be able to point to the one after the current closed } else wind = window_get_next(wind); } gr_flip(); }
char getch(void) { char ret = 0; EVENT_t ev = event_poll(&ret, 1, EVENT_NONE); while (ev != EVENT_TEXT_ENTERED) { if (ev == EVENT_NONE) { waitForEvent(0); } ev = event_poll(&ret, 1, EVENT_NONE); } return (ret); }
void test_operator_reset (void) { EventOperator *oper1, *oper2, *oper3, *oper4, *oper5; Event *event1, *event2; /* Check that we can reset all of the operators in the tree, * discarding any events that were referenced or blocked and setting * all the values back to FALSE. */ TEST_FUNCTION ("event_operator_reset"); oper1 = event_operator_new (NULL, EVENT_OR, NULL, NULL); oper2 = event_operator_new (NULL, EVENT_AND, NULL, NULL); oper3 = event_operator_new (NULL, EVENT_MATCH, "foo", NULL); oper4 = event_operator_new (NULL, EVENT_MATCH, "bar", NULL); oper5 = event_operator_new (NULL, EVENT_MATCH, "baz", NULL); nih_tree_add (&oper1->node, &oper2->node, NIH_TREE_LEFT); nih_tree_add (&oper2->node, &oper3->node, NIH_TREE_LEFT); nih_tree_add (&oper2->node, &oper4->node, NIH_TREE_RIGHT); nih_tree_add (&oper1->node, &oper5->node, NIH_TREE_RIGHT); event1 = event_new (NULL, "foo", NULL); event2 = event_new (NULL, "bar", NULL); event_operator_handle (oper1, event1, NULL); event_operator_handle (oper1, event2, NULL); TEST_EQ (oper1->value, TRUE); TEST_EQ (oper2->value, TRUE); TEST_EQ (oper3->value, TRUE); TEST_EQ_P (oper3->event, event1); TEST_EQ (oper4->value, TRUE); TEST_EQ (oper4->event, event2); TEST_EQ (oper5->value, FALSE); TEST_EQ (event1->blockers, 1); TEST_EQ (event2->blockers, 1); event_operator_reset (oper1); TEST_EQ (oper1->value, FALSE); TEST_EQ (oper2->value, FALSE); TEST_EQ (oper3->value, FALSE); TEST_EQ_P (oper3->event, NULL); TEST_EQ (oper4->value, FALSE); TEST_EQ (oper4->event, NULL); TEST_EQ (oper5->value, FALSE); TEST_EQ (event1->blockers, 0); TEST_EQ (event2->blockers, 0); nih_free (oper1); nih_free (oper2); nih_free (oper3); nih_free (oper4); nih_free (oper5); event_poll (); }
/** * @brief Main entry point. */ int main (void) { event_t evt; /* Disable watchdog timer since it doesn't always get reset on restart. */ wdt_disable(); /* Initialize the MCU. */ init(); /* Online. */ printf( "Exocore Apollo online...\n" ); /* Start fsm. */ fsm_start(); for (;;) { /* Atomic test to see if has anything to do. */ cli(); /* Handle events. */ while (event_poll(&evt)) { sei(); /* Reenable interrupts. */ fsm( &evt ); cli(); /* Disable for next check. */ } /* Atomic sleep as specified on the documentation. */ sleep_enable(); sei(); sleep_cpu(); sleep_disable(); } }
int key_checkch() { int is_one_waiting = 0; event_poll(SDL_KEYDOWNMASK | SDL_KEYUPMASK); if (key_data.keytail!=key_data.keyhead) is_one_waiting = 1; return is_one_waiting; }
void mouse_get_delta( int *dx, int *dy ) { event_poll(); *dx = Mouse.delta_x; *dy = Mouse.delta_y; Mouse.delta_x = 0; Mouse.delta_y = 0; }
int key_checkch() { int is_one_waiting = 0; event_poll(); if (key_data.keytail!=key_data.keyhead) is_one_waiting = 1; return is_one_waiting; }
int KeyCheckChar() { int is_one_waiting = 0; event_poll(); if (key_data.keytail!=key_data.keyhead) is_one_waiting = 1; return is_one_waiting; }
int KeyPeekKey (void) { int key = 0; event_poll (SDL_KEYDOWNMASK | SDL_KEYUPMASK); if (keyData.nKeyTail != keyData.nKeyHead) key = keyData.keyBuffer [keyData.nKeyHead]; return key; }
static bool input_poll(int32_t ms) { EventSource input_sources[] = { rstream_event_source(read_stream), NULL }; return input_ready() || event_poll(ms, input_sources) || input_ready(); }
ubyte keyFlags (int scancode) { #ifndef FAST_EVENTPOLL if (!bFastPoll) event_poll(SDL_KEYDOWNMASK | SDL_KEYUPMASK); #endif if ((scancode<0)|| (scancode>255)) return 0; return key_data.keys[scancode].flags; }
int key_peekkey() { int key = 0; event_poll(); if (key_data.keytail!=key_data.keyhead) key = key_data.keybuffer[key_data.keyhead]; return key; }
int key_peekkey() { int key = 0; event_poll(SDL_KEYDOWNMASK | SDL_KEYUPMASK); if (key_data.keytail!=key_data.keyhead) key = key_data.keybuffer[key_data.keyhead]; return key; }
void MouseGetPosZ (int *x, int *y, int *z) { #ifndef FAST_EVENTPOLL if (!bFastPoll) event_poll(SDL_MOUSEEVENTMASK); //polled in main/KConfig.c:read_bm_all() #endif *x=mouseData.x; *y=mouseData.y; *z=mouseData.z; }
void mouse_get_delta_z( int *dx, int *dy, int *dz ) { event_poll(); *dx = Mouse.delta_x; *dy = Mouse.delta_y; *dz = Mouse.delta_z; Mouse.delta_x = 0; Mouse.delta_y = 0; Mouse.delta_z = 0; }
// Returns how many times this button has went down since last call int mouse_button_down_count(int button) { int count; event_poll(); count = Mouse.buttons[button].num_downs; Mouse.buttons[button].num_downs = 0; return count; }
unsigned int key_upCount(int scancode) { int n; event_poll(); if ((scancode<0)|| (scancode>255)) return 0; n = key_data.keys[scancode].upcount; key_data.keys[scancode].upcount = 0; return n; }
/* * The servers main dispatch loop for incoming requests using SSL over TCP */ static DWORD server_dispatch( Remote * remote ) { LONG result = ERROR_SUCCESS; Packet * packet = NULL; THREAD * cpt = NULL; dprintf( "[DISPATCH] entering server_dispatch( 0x%08X )", remote ); // Bring up the scheduler subsystem. result = scheduler_initialize( remote ); if( result != ERROR_SUCCESS ) return result; while( TRUE ) { if( event_poll( serverThread->sigterm, 0 ) ) { dprintf( "[DISPATCH] server dispatch thread signaled to terminate..." ); break; } result = server_socket_poll( remote, 100 ); if( result > 0 ) { result = packet_receive( remote, &packet ); if( result != ERROR_SUCCESS ) { dprintf( "[DISPATCH] packet_receive returned %d, exiting dispatcher...", result ); break; } cpt = thread_create( command_process_thread, remote, packet ); if( cpt ) { dprintf( "[DISPATCH] created command_process_thread 0x%08X, handle=0x%08X", cpt, cpt->handle ); thread_run( cpt ); } } else if( result < 0 ) { dprintf( "[DISPATCH] server_socket_poll returned %d, exiting dispatcher...", result ); break; } } dprintf( "[DISPATCH] calling scheduler_destroy..." ); scheduler_destroy(); dprintf( "[DISPATCH] calling command_join_threads..." ); command_join_threads(); dprintf( "[DISPATCH] leaving server_dispatch." ); return result; }
void FlushInput (void) { int b = gameOpts->legacy.bInput; gameOpts->legacy.bInput = 1; event_poll (SDL_ALLEVENTS); gameOpts->legacy.bInput = b; KeyFlush (); MouseFlush (); JoyFlush (); }
int joy_get_button_state( int btn ) { if (!num_joysticks) return 0; if(btn >= Joystick.n_buttons) return 0; event_poll(); return Joystick.buttons[btn].state; }
int JoyGetButtonState (int nButton) { if (!gameStates.input.nJoysticks) return 0; if (nButton >= JOY_MAX_BUTTONS) return 0; #ifndef FAST_EVENTPOLL if (gameOpts->legacy.bInput) event_poll(SDL_JOYEVENTMASK); //polled in main/KConfig.c:read_bm_all() #endif return joyInfo.buttons [nButton].state; }
//------------------------------------------------------------------------------ // Returns how many times this button has went down since last call int MouseButtonDownCount (int button) { int count; #ifndef FAST_EVENTPOLL if (!bFastPoll) event_poll(SDL_MOUSEEVENTMASK); //polled in main/KConfig.c:read_bm_all() #endif count = mouseData.buttons [button].numDowns; mouseData.buttons [button].numDowns = 0; return count; }
void MouseFlush (void) // clears all mouse events... { int i; fix xCurTime; event_poll (SDL_MOUSEEVENTMASK); xCurTime = TimerGetFixedSeconds (); memset (&mouseData, 0, sizeof (mouseData)); for (i = 0; i < MOUSE_MAX_BUTTONS; i++) mouseData.buttons [i].xTimeWentDown = xCurTime; SDL_GetMouseState (&mouseData.x, &mouseData.y); // necessary because polling only gives us the delta. }