@@ -159,7 +159,7 @@ BOOL WINAPI SigintWatchdogHelper::WinCtrlCHandlerRoutine(DWORD dwCtrlType) {
159159
160160
161161bool SigintWatchdogHelper::InformWatchdogsAboutSignal () {
162- uv_mutex_lock (& instance.list_mutex_ );
162+ Mutex::ScopedLock scoped_lock ( instance.list_mutex_ );
163163
164164 bool is_stopping = false ;
165165#ifdef __POSIX__
@@ -175,14 +175,13 @@ bool SigintWatchdogHelper::InformWatchdogsAboutSignal() {
175175 for (auto it : instance.watchdogs_ )
176176 it->HandleSigint ();
177177
178- uv_mutex_unlock (&instance.list_mutex_ );
179178 return is_stopping;
180179}
181180
182181
183182int SigintWatchdogHelper::Start () {
184183 int ret = 0 ;
185- uv_mutex_lock (& mutex_);
184+ Mutex::ScopedLock scoped_lock ( mutex_);
186185
187186 if (start_stop_count_++ > 0 ) {
188187 goto dont_start;
@@ -209,29 +208,30 @@ int SigintWatchdogHelper::Start() {
209208#endif
210209
211210 dont_start:
212- uv_mutex_unlock (&mutex_);
213211 return ret;
214212}
215213
216214
217215bool SigintWatchdogHelper::Stop () {
218- uv_mutex_lock (&mutex_);
219- uv_mutex_lock (&list_mutex_);
216+ Mutex::ScopedLock scoped_lock (mutex_);
220217
221- bool had_pending_signal = has_pending_signal_;
218+ bool had_pending_signal;
219+ {
220+ Mutex::ScopedLock scoped_lock_watchdoglist (list_mutex_);
222221
223- if (--start_stop_count_ > 0 ) {
224- uv_mutex_unlock (&list_mutex_);
225- goto dont_stop;
226- }
222+ had_pending_signal = has_pending_signal_;
223+
224+ if (--start_stop_count_ > 0 ) {
225+ goto dont_stop;
226+ }
227227
228228#ifdef __POSIX__
229- // Set stopping now because it's only protected by list_mutex_.
230- stopping_ = true ;
229+ // Set stopping now because it's only protected by list_mutex_.
230+ stopping_ = true ;
231231#endif
232232
233- watchdogs_.clear ();
234- uv_mutex_unlock (&list_mutex_);
233+ watchdogs_.clear ();
234+ }
235235
236236#ifdef __POSIX__
237237 if (!has_running_thread_) {
@@ -252,31 +252,26 @@ bool SigintWatchdogHelper::Stop() {
252252
253253 had_pending_signal = has_pending_signal_;
254254 dont_stop:
255- uv_mutex_unlock (&mutex_);
256255
257256 has_pending_signal_ = false ;
258257 return had_pending_signal;
259258}
260259
261260
262261void SigintWatchdogHelper::Register (SigintWatchdog* wd) {
263- uv_mutex_lock (& list_mutex_);
262+ Mutex::ScopedLock scoped_lock ( list_mutex_);
264263
265264 watchdogs_.push_back (wd);
266-
267- uv_mutex_unlock (&list_mutex_);
268265}
269266
270267
271268void SigintWatchdogHelper::Unregister (SigintWatchdog* wd) {
272- uv_mutex_lock (& list_mutex_);
269+ Mutex::ScopedLock scoped_lock ( list_mutex_);
273270
274271 auto it = std::find (watchdogs_.begin (), watchdogs_.end (), wd);
275272
276273 CHECK_NE (it, watchdogs_.end ());
277274 watchdogs_.erase (it);
278-
279- uv_mutex_unlock (&list_mutex_);
280275}
281276
282277
@@ -288,9 +283,6 @@ SigintWatchdogHelper::SigintWatchdogHelper()
288283 stopping_ = false ;
289284 CHECK_EQ (0 , uv_sem_init (&sem_, 0 ));
290285#endif
291-
292- CHECK_EQ (0 , uv_mutex_init (&mutex_));
293- CHECK_EQ (0 , uv_mutex_init (&list_mutex_));
294286};
295287
296288
@@ -302,9 +294,6 @@ SigintWatchdogHelper::~SigintWatchdogHelper() {
302294 CHECK_EQ (has_running_thread_, false );
303295 uv_sem_destroy (&sem_);
304296#endif
305-
306- uv_mutex_destroy (&mutex_);
307- uv_mutex_destroy (&list_mutex_);
308297}
309298
310299SigintWatchdogHelper SigintWatchdogHelper::instance;
0 commit comments