@@ -159,7 +159,7 @@ BOOL WINAPI SigintWatchdogHelper::WinCtrlCHandlerRoutine(DWORD dwCtrlType) {
159
159
160
160
161
161
bool SigintWatchdogHelper::InformWatchdogsAboutSignal () {
162
- uv_mutex_lock (& instance.list_mutex_ );
162
+ Mutex::ScopedLock scoped_lock ( instance.list_mutex_ );
163
163
164
164
bool is_stopping = false ;
165
165
#ifdef __POSIX__
@@ -175,14 +175,13 @@ bool SigintWatchdogHelper::InformWatchdogsAboutSignal() {
175
175
for (auto it : instance.watchdogs_ )
176
176
it->HandleSigint ();
177
177
178
- uv_mutex_unlock (&instance.list_mutex_ );
179
178
return is_stopping;
180
179
}
181
180
182
181
183
182
int SigintWatchdogHelper::Start () {
184
183
int ret = 0 ;
185
- uv_mutex_lock (& mutex_);
184
+ Mutex::ScopedLock scoped_lock ( mutex_);
186
185
187
186
if (start_stop_count_++ > 0 ) {
188
187
goto dont_start;
@@ -209,29 +208,30 @@ int SigintWatchdogHelper::Start() {
209
208
#endif
210
209
211
210
dont_start:
212
- uv_mutex_unlock (&mutex_);
213
211
return ret;
214
212
}
215
213
216
214
217
215
bool SigintWatchdogHelper::Stop () {
218
- uv_mutex_lock (&mutex_);
219
- uv_mutex_lock (&list_mutex_);
216
+ Mutex::ScopedLock scoped_lock (mutex_);
220
217
221
- bool had_pending_signal = has_pending_signal_;
218
+ bool had_pending_signal;
219
+ {
220
+ Mutex::ScopedLock scoped_lock_watchdoglist (list_mutex_);
222
221
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
+ }
227
227
228
228
#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 ;
231
231
#endif
232
232
233
- watchdogs_.clear ();
234
- uv_mutex_unlock (&list_mutex_);
233
+ watchdogs_.clear ();
234
+ }
235
235
236
236
#ifdef __POSIX__
237
237
if (!has_running_thread_) {
@@ -252,31 +252,26 @@ bool SigintWatchdogHelper::Stop() {
252
252
253
253
had_pending_signal = has_pending_signal_;
254
254
dont_stop:
255
- uv_mutex_unlock (&mutex_);
256
255
257
256
has_pending_signal_ = false ;
258
257
return had_pending_signal;
259
258
}
260
259
261
260
262
261
void SigintWatchdogHelper::Register (SigintWatchdog* wd) {
263
- uv_mutex_lock (& list_mutex_);
262
+ Mutex::ScopedLock scoped_lock ( list_mutex_);
264
263
265
264
watchdogs_.push_back (wd);
266
-
267
- uv_mutex_unlock (&list_mutex_);
268
265
}
269
266
270
267
271
268
void SigintWatchdogHelper::Unregister (SigintWatchdog* wd) {
272
- uv_mutex_lock (& list_mutex_);
269
+ Mutex::ScopedLock scoped_lock ( list_mutex_);
273
270
274
271
auto it = std::find (watchdogs_.begin (), watchdogs_.end (), wd);
275
272
276
273
CHECK_NE (it, watchdogs_.end ());
277
274
watchdogs_.erase (it);
278
-
279
- uv_mutex_unlock (&list_mutex_);
280
275
}
281
276
282
277
@@ -288,9 +283,6 @@ SigintWatchdogHelper::SigintWatchdogHelper()
288
283
stopping_ = false ;
289
284
CHECK_EQ (0 , uv_sem_init (&sem_, 0 ));
290
285
#endif
291
-
292
- CHECK_EQ (0 , uv_mutex_init (&mutex_));
293
- CHECK_EQ (0 , uv_mutex_init (&list_mutex_));
294
286
};
295
287
296
288
@@ -302,9 +294,6 @@ SigintWatchdogHelper::~SigintWatchdogHelper() {
302
294
CHECK_EQ (has_running_thread_, false );
303
295
uv_sem_destroy (&sem_);
304
296
#endif
305
-
306
- uv_mutex_destroy (&mutex_);
307
- uv_mutex_destroy (&list_mutex_);
308
297
}
309
298
310
299
SigintWatchdogHelper SigintWatchdogHelper::instance;
0 commit comments