@@ -102,6 +102,7 @@ void Watchdog::Timer(uv_timer_t* timer) {
102102SigintWatchdog::SigintWatchdog (
103103 v8::Isolate* isolate, bool * received_signal)
104104 : isolate_(isolate), received_signal_(received_signal) {
105+ Mutex::ScopedLock lock (SigintWatchdogHelper::GetInstanceActionMutex ());
105106 // Register this watchdog with the global SIGINT/Ctrl+C listener.
106107 SigintWatchdogHelper::GetInstance ()->Register (this );
107108 // Start the helper thread, if that has not already happened.
@@ -110,6 +111,7 @@ SigintWatchdog::SigintWatchdog(
110111
111112
112113SigintWatchdog::~SigintWatchdog () {
114+ Mutex::ScopedLock lock (SigintWatchdogHelper::GetInstanceActionMutex ());
113115 SigintWatchdogHelper::GetInstance ()->Unregister (this );
114116 SigintWatchdogHelper::GetInstance ()->Stop ();
115117}
@@ -144,6 +146,7 @@ void TraceSigintWatchdog::New(const FunctionCallbackInfo<Value>& args) {
144146void TraceSigintWatchdog::Start (const FunctionCallbackInfo<Value>& args) {
145147 TraceSigintWatchdog* watchdog;
146148 ASSIGN_OR_RETURN_UNWRAP (&watchdog, args.Holder ());
149+ Mutex::ScopedLock lock (SigintWatchdogHelper::GetInstanceActionMutex ());
147150 // Register this watchdog with the global SIGINT/Ctrl+C listener.
148151 SigintWatchdogHelper::GetInstance ()->Register (watchdog);
149152 // Start the helper thread, if that has not already happened.
@@ -154,6 +157,7 @@ void TraceSigintWatchdog::Start(const FunctionCallbackInfo<Value>& args) {
154157void TraceSigintWatchdog::Stop (const FunctionCallbackInfo<Value>& args) {
155158 TraceSigintWatchdog* watchdog;
156159 ASSIGN_OR_RETURN_UNWRAP (&watchdog, args.Holder ());
160+ Mutex::ScopedLock lock (SigintWatchdogHelper::GetInstanceActionMutex ());
157161 SigintWatchdogHelper::GetInstance ()->Unregister (watchdog);
158162 SigintWatchdogHelper::GetInstance ()->Stop ();
159163}
@@ -215,6 +219,7 @@ void TraceSigintWatchdog::HandleInterrupt() {
215219 signal_flag_ = SignalFlags::None;
216220 interrupting = false ;
217221
222+ Mutex::ScopedLock lock (SigintWatchdogHelper::GetInstanceActionMutex ());
218223 SigintWatchdogHelper::GetInstance ()->Unregister (this );
219224 SigintWatchdogHelper::GetInstance ()->Stop ();
220225 raise (SIGINT);
@@ -413,6 +418,7 @@ SigintWatchdogHelper::~SigintWatchdogHelper() {
413418}
414419
415420SigintWatchdogHelper SigintWatchdogHelper::instance;
421+ Mutex SigintWatchdogHelper::instance_action_mutex_;
416422
417423namespace watchdog {
418424static void Initialize (Local<Object> target,
0 commit comments