|
|
@ -309,6 +309,10 @@ private:
|
|
|
|
state_t run_state() {
|
|
|
|
state_t run_state() {
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
cur_state = next_state;
|
|
|
|
cur_state = next_state;
|
|
|
|
|
|
|
|
if (state_setting) {
|
|
|
|
|
|
|
|
state_setting = false;
|
|
|
|
|
|
|
|
state_changing = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
pthread_cond_broadcast(&cvar);
|
|
|
|
pthread_cond_broadcast(&cvar);
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
return cur_state;
|
|
|
|
return cur_state;
|
|
|
@ -322,6 +326,8 @@ private:
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
next_state = IDLE;
|
|
|
|
next_state = IDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
state_changing = false;
|
|
|
|
|
|
|
|
pthread_cond_broadcast(&cvar);
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void force_sfn_sync() {
|
|
|
|
void force_sfn_sync() {
|
|
|
@ -383,13 +389,16 @@ private:
|
|
|
|
pthread_cond_init(&cvar, NULL);
|
|
|
|
pthread_cond_init(&cvar, NULL);
|
|
|
|
cur_state = IDLE;
|
|
|
|
cur_state = IDLE;
|
|
|
|
next_state = IDLE;
|
|
|
|
next_state = IDLE;
|
|
|
|
|
|
|
|
state_setting = false;
|
|
|
|
|
|
|
|
state_changing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
void go_state(state_t s) {
|
|
|
|
void go_state(state_t s) {
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
next_state = s;
|
|
|
|
next_state = s;
|
|
|
|
while(cur_state != s) {
|
|
|
|
state_setting = true;
|
|
|
|
|
|
|
|
while(state_setting) {
|
|
|
|
pthread_cond_wait(&cvar, &inside);
|
|
|
|
pthread_cond_wait(&cvar, &inside);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
@ -398,12 +407,13 @@ private:
|
|
|
|
/* Waits until there is a call to set_state() and then run_state(). Returns when run_state() returns */
|
|
|
|
/* Waits until there is a call to set_state() and then run_state(). Returns when run_state() returns */
|
|
|
|
void wait_state_change(state_t prev_state) {
|
|
|
|
void wait_state_change(state_t prev_state) {
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
while(cur_state == prev_state) {
|
|
|
|
while(state_changing) {
|
|
|
|
pthread_cond_wait(&cvar, &inside);
|
|
|
|
pthread_cond_wait(&cvar, &inside);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool state_changing, state_setting;
|
|
|
|
state_t cur_state, next_state;
|
|
|
|
state_t cur_state, next_state;
|
|
|
|
pthread_mutex_t inside, outside;
|
|
|
|
pthread_mutex_t inside, outside;
|
|
|
|
pthread_cond_t cvar;
|
|
|
|
pthread_cond_t cvar;
|
|
|
|