sync.h uses lock_guard for mutex

master
Xavier Arteaga 5 years ago committed by Xavier Arteaga
parent 81de38e43c
commit c7be984819

@ -212,20 +212,19 @@ private:
* and returns the current state * and returns the current state
*/ */
state_t run_state() { state_t run_state() {
std::unique_lock<std::mutex> ul(inside); std::lock_guard<std::mutex> lg(inside);
cur_state = next_state; cur_state = next_state;
if (state_setting) { if (state_setting) {
state_setting = false; state_setting = false;
state_running = true; state_running = true;
} }
cvar.notify_all(); cvar.notify_all();
inside.unlock();
return cur_state; return cur_state;
} }
// Called by the main thread at the end of each state to indicate it has finished. // Called by the main thread at the end of each state to indicate it has finished.
void state_exit(bool exit_ok = true) { void state_exit(bool exit_ok = true) {
std::unique_lock<std::mutex> ul(inside); std::lock_guard<std::mutex> lg(inside);
if (cur_state == SFN_SYNC && exit_ok == true) { if (cur_state == SFN_SYNC && exit_ok == true) {
next_state = CAMPING; next_state = CAMPING;
} else { } else {
@ -235,7 +234,7 @@ private:
cvar.notify_all(); cvar.notify_all();
} }
void force_sfn_sync() { void force_sfn_sync() {
std::unique_lock<std::mutex> ul(inside); std::lock_guard<std::mutex> lg(inside);
next_state = SFN_SYNC; next_state = SFN_SYNC;
} }
@ -245,23 +244,20 @@ private:
* These functions are mutexed and only 1 can be called at a time * These functions are mutexed and only 1 can be called at a time
*/ */
void go_idle() { void go_idle() {
outside.lock(); std::lock_guard<std::mutex> lg(outside);
go_state(IDLE); go_state(IDLE);
outside.unlock();
} }
void run_cell_search() { void run_cell_search() {
outside.lock(); std::lock_guard<std::mutex> lg(outside);
go_state(CELL_SEARCH); go_state(CELL_SEARCH);
wait_state_run(); wait_state_run();
wait_state_next(); wait_state_next();
outside.unlock();
} }
void run_sfn_sync() { void run_sfn_sync() {
outside.lock(); std::lock_guard<std::mutex> lg(outside);
go_state(SFN_SYNC); go_state(SFN_SYNC);
wait_state_run(); wait_state_run();
wait_state_next(); wait_state_next();
outside.unlock();
} }

Loading…
Cancel
Save