File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -490,6 +490,31 @@ TEST(Timer, Reapting)
490490 // timer_destroy(timer_arg.ptimer);
491491}
492492
493+ TEST (Timer, Reapting2)
494+ {
495+ timer_count = 5 ;
496+ t0 = now_time ();
497+ auto cb = [](void * arg) -> uint64_t {
498+ LOG_INFO (" timer callback" );
499+ auto t1 = now_time ();
500+ auto delta_t = t1 - t0;
501+ EXPECT_GT (delta_t , 1 * 1000 * 1000 );
502+ EXPECT_LT (delta_t , 2 * 1000 * 1000 );
503+ t0 = t1;
504+ LOG_INFO (VALUE (delta_t ));
505+ LOG_INFO (VALUE (timer_count));
506+ auto & timer_count = *(int *)arg;
507+ timer_count--;
508+ return 0 ;
509+ };
510+ Timer timer (1000 *1000 , {cb, &timer_count});
511+ while (timer_count >= 0 ) {
512+ usleep (200000 ); // 200ms. Simulate the situation of cpu usage
513+ std::cout << " ready to yield" << std::endl;
514+ photon::thread_yield ();
515+ }
516+ }
517+
493518TEST (Thread, function)
494519{
495520 photon::join_handle* th1 = photon::thread_enable_join (photon::thread_create (&asdf, (void *)0 ));
Original file line number Diff line number Diff line change @@ -1209,9 +1209,10 @@ R"(
12091209 AtomicRunQ ().insert_list_before (q);
12101210 }
12111211 }
1212- if (sleepq.empty () || ! if_update_now () ) {
1212+ if (sleepq.empty ()) {
12131213 return count;
12141214 }
1215+ if_update_now ();
12151216 do {
12161217 auto th = sleepq.front ();
12171218 if (th->ts_wakeup > now) break ;
You can’t perform that action at this time.
0 commit comments