static void testBlocked (void) { std::string s_one("one"); std::string s_two("two"); std::string s_three("three"); std::string s_four("three"); const int delay = 10; event_func* f_oneFour = (event_func*)0xCAFED00D; event_func* f_twoThree = (event_func*)0xB16B00B5; ScheduleEventPtr one = Schedule_Event(3, f_oneFour, delayCheckBlocked, nullptr, static_cast<void*>(&s_one)); one->delayFollowing = delay; ScheduleEventPtr two = Schedule_Event(4 + delay, f_twoThree, nullptr, nullptr, static_cast<void*>(&s_two)); two->delayFollowing = delay; ScheduleEventPtr three = Schedule_Event(5 + delay, f_twoThree, nullptr, nullptr, static_cast<void*>(&s_three)); three->delayFollowing = delay; ScheduleEventPtr four = Schedule_Event(5, f_oneFour, delayCheckBlocked, nullptr, static_cast<void*>(&s_four)); four->delayFollowing = delay; ScheduleEventPtr e = Dequeue_Event(1); CU_ASSERT_FALSE(e); e = Dequeue_Event(2); CU_ASSERT_FALSE(e); e = Dequeue_Event(3); CU_ASSERT_FALSE(e); e = Dequeue_Event(5); CU_ASSERT_FALSE(e); delayCheckBlockedVal = true; e = Dequeue_Event(5); CU_ASSERT_FALSE(e); e = Dequeue_Event(5 + delay); CU_ASSERT_EQUAL_FATAL(e, one); e = Dequeue_Event(4 + delay); CU_ASSERT_EQUAL_FATAL(e, two); e = Dequeue_Event(4 + delay); CU_ASSERT_FALSE(e); e = Dequeue_Event(5 + delay); CU_ASSERT_EQUAL_FATAL(e, three); e = Dequeue_Event(5 + delay); CU_ASSERT_EQUAL_FATAL(e, four); }
static void testScheduler (void) { scheduleEvent_t *one, *two, *three, *four, *five, *e; three = Schedule_Event(4, NULL, NULL, NULL, "three"); CU_ASSERT_EQUAL_FATAL(three->next, NULL); four = Schedule_Event(4, NULL, NULL, NULL, "four"); CU_ASSERT_EQUAL_FATAL(three->next, four); CU_ASSERT_EQUAL_FATAL(four->next, NULL); five = Schedule_Event(4, NULL, NULL, NULL, "five"); CU_ASSERT_EQUAL_FATAL(three->next, four); CU_ASSERT_EQUAL_FATAL(four->next, five); CU_ASSERT_EQUAL_FATAL(five->next, NULL); one = Schedule_Event(3, NULL, delayCheck, NULL, "one"); CU_ASSERT_EQUAL_FATAL(one->next, three); CU_ASSERT_EQUAL_FATAL(three->next, four); CU_ASSERT_EQUAL_FATAL(four->next, five); CU_ASSERT_EQUAL_FATAL(five->next, NULL); two = Schedule_Event(3, NULL, NULL, NULL, "two"); CU_ASSERT_EQUAL_FATAL(one->next, two); CU_ASSERT_EQUAL_FATAL(two->next, three); CU_ASSERT_EQUAL_FATAL(three->next, four); CU_ASSERT_EQUAL_FATAL(four->next, five); CU_ASSERT_EQUAL_FATAL(five->next, NULL); e = Dequeue_Event(1); CU_ASSERT_EQUAL(e, NULL); e = Dequeue_Event(2); CU_ASSERT_EQUAL(e, NULL); /* one is delayed via check function - so we get the 2nd event at the first dequeue here */ e = Dequeue_Event(3); CU_ASSERT_EQUAL_FATAL(e, two); /* now we are ready for the 1st event */ e = Dequeue_Event(5); CU_ASSERT_EQUAL_FATAL(e, one); /* the remaining events are in order */ e = Dequeue_Event(5); CU_ASSERT_EQUAL_FATAL(e, three); e = Dequeue_Event(5); CU_ASSERT_EQUAL_FATAL(e, four); e = Dequeue_Event(5); CU_ASSERT_EQUAL_FATAL(e, five); }
/** * @brief This is the function that is called directly from main() * @sa main * @sa Qcommon_Init * @sa Qcommon_Shutdown * @sa SV_Frame * @sa CL_Frame */ void Qcommon_Frame (void) { try { /* If the next event is due... */ ScheduleEventPtr event = Dequeue_Event(Sys_Milliseconds()); if (event) { /* Dispatch the event */ event->func(event->when, event->data); } } catch (comRestart_t const& restart) { SV_Shutdown("Restart.", false); CL_Shutdown(); Qcommon_Shutdown(); CL_FilterEventQueue(&Event_FilterAll); if (restart.gamedir != nullptr) { const char* restartArgv[] = {"", "+set", "fs_gamedir", restart.gamedir}; Qcommon_Init(4, const_cast<char** >(restartArgv)); } else { Qcommon_Init(0, nullptr); } } catch (comDrop_t const&) { return; } /* Now we spend time_to_next milliseconds working on whatever * IO is ready (but always try at least once, to make sure IO * doesn't stall) */ int time_to_next; do { time_to_next = !eventQueue.empty() ? (eventQueue.begin()->get()->when - Sys_Milliseconds()) : 1000; if (time_to_next < 0) time_to_next = 0; NET_Wait(time_to_next); } while (time_to_next > 0); }
static void testScheduler (void) { std::string s_one("one"); std::string s_two("two"); std::string s_three("three"); std::string s_four("four"); std::string s_five("five"); ScheduleEventPtr one = Schedule_Event(3, nullptr, nullptr, nullptr, static_cast<void*>(&s_one)); ScheduleEventPtr two = Schedule_Event(3, nullptr, nullptr, nullptr, static_cast<void*>(&s_two)); ScheduleEventPtr three = Schedule_Event(4, nullptr, nullptr, nullptr, static_cast<void*>(&s_three)); ScheduleEventPtr four = Schedule_Event(4, nullptr, nullptr, nullptr, static_cast<void*>(&s_four)); ScheduleEventPtr five = Schedule_Event(5, nullptr, nullptr, nullptr, static_cast<void*>(&s_five)); CU_ASSERT_EQUAL(Dequeue_Event(1000), one); CU_ASSERT_EQUAL(Dequeue_Event(1000), two); CU_ASSERT_EQUAL(Dequeue_Event(1000), three); CU_ASSERT_EQUAL(Dequeue_Event(1000), four); CU_ASSERT_EQUAL(Dequeue_Event(1000), five); CU_ASSERT_FALSE(Dequeue_Event(1000)); }
static void testSchedulerCheck (void) { std::string s_one("one"); std::string s_two("two"); std::string s_three("three"); std::string s_four("four"); std::string s_five("five"); ScheduleEventPtr three = Schedule_Event(4, nullptr, nullptr, nullptr, static_cast<void*>(&s_three)); ScheduleEventPtr four = Schedule_Event(4, nullptr, nullptr, nullptr, static_cast<void*>(&s_four)); ScheduleEventPtr five = Schedule_Event(4, nullptr, nullptr, nullptr, static_cast<void*>(&s_five)); ScheduleEventPtr one = Schedule_Event(3, nullptr, delayCheck, nullptr, static_cast<void*>(&s_one)); ScheduleEventPtr two = Schedule_Event(3, nullptr, nullptr, nullptr, static_cast<void*>(&s_two)); ScheduleEventPtr e = Dequeue_Event(1); CU_ASSERT_FALSE(e); e = Dequeue_Event(2); CU_ASSERT_FALSE(e); /* one is delayed via check function - so we get the 2nd event at the first dequeue here */ e = Dequeue_Event(3); CU_ASSERT_EQUAL_FATAL(e, two); /* now we are ready for the 1st event */ e = Dequeue_Event(5); CU_ASSERT_EQUAL_FATAL(e, one); /* the remaining events are in order */ e = Dequeue_Event(5); CU_ASSERT_EQUAL_FATAL(e, three); e = Dequeue_Event(5); CU_ASSERT_EQUAL_FATAL(e, four); e = Dequeue_Event(5); CU_ASSERT_EQUAL_FATAL(e, five); }