Skip to content

Commit

Permalink
Use a mutex to avoid reentering signal handler
Browse files Browse the repository at this point in the history
This entures we won't re-enter the signal handler from another signal
whether or not it happens in our own thread.
  • Loading branch information
jhawthorn committed Apr 28, 2021
1 parent 415ee28 commit cf67aff
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ext/stackprof/stackprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,14 @@ stackprof_job_handler(void *data)
static void
stackprof_signal_handler(int sig, siginfo_t *sinfo, void *ucontext)
{
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

_stackprof.overall_signals++;

if (!_stackprof.running) return;
if (!ruby_native_thread_p()) return;
if (pthread_mutex_trylock(&lock)) return;

if (!_stackprof.ignore_gc && rb_during_gc()) {
VALUE mode = rb_gc_latest_gc_info(sym_state);
if (mode == sym_marking) {
Expand All @@ -625,6 +632,7 @@ stackprof_signal_handler(int sig, siginfo_t *sinfo, void *ucontext)
} else {
rb_postponed_job_register_one(0, stackprof_job_handler, (void*)0);
}
pthread_mutex_unlock(&lock);
}

static void
Expand Down

0 comments on commit cf67aff

Please sign in to comment.