Skip to content

Commit 34b5bbf

Browse files
authored
fix resume_threads() (#1040)
1 parent d39f52b commit 34b5bbf

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

thread/test/test.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
493518
TEST(Thread, function)
494519
{
495520
photon::join_handle* th1 = photon::thread_enable_join(photon::thread_create(&asdf, (void*)0));

thread/thread.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)