Skip to content

Commit 9c7bded

Browse files
authored
more: print more context if we preempt in atomic section (#389)
Signed-off-by: Roman Gershman <romange@gmail.com>
1 parent 802f520 commit 9c7bded

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

util/fibers/detail/scheduler.cc

+11-3
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,17 @@ ctx::fiber_context Scheduler::Preempt() {
203203
if (FiberActive() == dispatch_cntx_.get()) {
204204
LOG(DFATAL) << "Should not preempt dispatcher: " << GetStacktrace();
205205
}
206-
if (IsFiberAtomicSection())
207-
LOG(DFATAL) << "Preempting inside of atomic section";
206+
207+
if (IsFiberAtomicSection()) {
208+
static int64_t last_ts = 0;
209+
int64_t now = time(nullptr);
210+
if (now != last_ts) { // once a second at most.
211+
last_ts = now;
212+
LOG(DFATAL) << "Preempting inside of atomic section, fiber: " << FiberActive()->name()
213+
<< ", stacktrace:\n" << GetStacktrace();
214+
}
215+
}
216+
208217
DCHECK(!ready_queue_.empty()); // dispatcher fiber is always in the ready queue.
209218

210219
FiberInterface* fi = &ready_queue_.front();
@@ -457,7 +466,6 @@ void Scheduler::PrintAllFiberStackTraces() {
457466
add_time = false;
458467
}
459468

460-
461469
string print_cb_str;
462470
#ifndef NDEBUG
463471
print_cb_str = fb->stacktrace_print_cb_ ? fb->stacktrace_print_cb_() : string{};

0 commit comments

Comments
 (0)