void rwsched_dispatch_main_until(rwsched_tasklet_ptr_t sched_tasklet, double sec, uint32_t *exitnow) { // Validate input paraemters RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t); rwsched_instance_ptr_t instance = sched_tasklet->instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); struct timeval start_tv; gettimeofday(&start_tv, NULL); struct timeval now_tv = start_tv; int evfd = dispatch_get_main_queue_eventfd_np(); RW_ASSERT(evfd >= 0); int flags = fcntl(evfd, F_GETFL); flags |= O_NONBLOCK; fcntl(evfd, F_SETFL, flags); while (seconds_elapsed(&start_tv, &now_tv) < sec) { if (exitnow && *exitnow) break; int secleft = MAX(0, (sec - seconds_elapsed(&start_tv, &now_tv))); struct pollfd pfd = { .fd = evfd, .events = POLLIN, .revents = 0 }; if (0 < poll(&pfd, 1, secleft * 1000)) { uint64_t evct = 0; int rval = 0; rval = read(evfd, &evct, sizeof(evct)); if (rval == 8) { dispatch_main_queue_drain_np(); } } gettimeofday(&now_tv, NULL); } } void rwsched_dispatch_main_iteration(rwsched_tasklet_ptr_t sched_tasklet) { // Validate input paraemters RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t); rwsched_instance_t *instance = sched_tasklet->instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); dispatch_main_queue_drain_np(); }
LEVEL * level_update(LEVEL *level, SHIP *ship, bool keys[], ALLEGRO_TIMER *timer) { int64_t time_count = al_get_timer_count(timer); uint8_t next_saucer = abs(level->number + (-LEVEL_MAX)) * 1.3; /* is it time to introduce a new saucer? */ if(!level->saucer) if(seconds_elapsed(time_count - level->saucer_seen) > next_saucer) level->saucer = saucer_new(SAUCER_LARGE, level->number, timer); if(level->saucer) { level->saucer = saucer_update(level->saucer, ship, timer); level->saucer_seen = time_count; /* saucer missiles */ if(!level->saucer->missile->active) saucer_fire(level->saucer, ship, timer); } asteroid_update_list(level->asteroids); return level; }
void processNormalKeys(unsigned char key, int x, int y) { if (key == 't') { key_pressed = MOVETAN; } else if (key == 'm') { key_pressed = MOVEPOS; } else if (key == 'r') { key_pressed = ROTATETAN; } else if (key == 'n') { next_thread(); } else if (key == 'b') { prev_thread(); } else if (key == 'v') { findThreadInIms(); glutPostRedisplay(); } else if (key == 'z') { /* Step */ if (thread_vision.hasInit) { if (!thread_vision.isDone()) { thread_vision.generateNextSetOfHypoths(); showThread(thread_vision.curr_thread()); } else { cout << "Search already finished" << endl; } } else { // Taken from start of findThreadInIms(); thread_vision_searched = true; thread_vision.set_max_length(MAX_LENGTH_VIS); thread_vision.clear_display(); updateIms(_start_pt, _start_tan, _end_pt, _end_tan); thread_vision.clearStartData(); thread_vision.addStartData(_start_pt, _start_tan); thread_vision.initThreadSearch(); //cout << "Thread Vision not initialized. Press 'v' to init" << endl; } } else if (key == 'q') { cout << "Flip to prev hypoth" << endl; thread_vision.prev_hypoth(); showThread(thread_vision.curr_thread()); } else if (key == 'w') { cout << "Flip to next hypoth" << endl; thread_vision.next_hypoth(); showThread(thread_vision.curr_thread()); } else if (key == '1' && key <= '1' + NUM_THREADS_DISPLAY) { show_threads[((int)key-'1')] = !show_threads[((int)key-'1')]; // } else if (key == 's') { // /* Save current trajectory */ // cout << "Saving...\n"; // cout << "Please enter destination file name (without extension): "; // char *dstFileName = new char[256]; // cin >> dstFileName; // char *fullPath = new char[256]; // sprintf(fullPath, "%s%s", "saved_threads/", dstFileName); // // traj_recorder.setFileName(fullPath); // // Thread *newThread = glThreads[currentThread]->getThread(); // Thread copiedThread(*newThread); // traj_recorder.add_thread_to_list(copiedThread); // traj_recorder.write_threads_to_file(); } /* Run through all threads, generate guess, save image in test_images */ else if (key == 'p') { thread_ind = -1; while (true) { next_thread(); DrawStuff(); cout << endl << "testing thread " << thread_ind << endl << endl; start_timer(); findThreadInIms(); glutPostRedisplay(); stop_timer(); wait(2); thread_differences[thread_ind] = thread_difference(glThreads[truthThread]->getThread(), thread_vision.curr_thread()); generation_times[thread_ind] = seconds_elapsed(); printf("thread %2d |\t runtime (s): %05.3f | difference: %05.3f\n", thread_ind, generation_times[thread_ind], thread_differences[thread_ind]); DrawStuff(); save_opengl_image(); if (thread_ind == NUM_THREADS-1) break; } cout << endl << "-------------------" << endl; cout << "PERFORMANCE SUMMARY" << endl; cout << "-------------------" << endl; for (int i = 1; i < NUM_THREADS; i++) { printf("thread %2d |\t runtime (s): %05.3f | difference: %05.3f\n", i, generation_times[i], thread_differences[i]); } } else if (key == 27) { exit(0); } lastx_R = x; lasty_R = y; }