Merge "Add a new key_pressed_mutex"

This commit is contained in:
Tianjie Xu 2019-07-10 17:46:27 +00:00 committed by Gerrit Code Review
commit 33bb113af2
2 changed files with 15 additions and 12 deletions

View file

@ -236,13 +236,16 @@ class RecoveryUI {
std::condition_variable key_queue_cond;
bool key_interrupted_;
int key_queue[256], key_queue_len;
char key_pressed[KEY_MAX + 1]; // under key_queue_mutex
int key_last_down; // under key_queue_mutex
bool key_long_press; // under key_queue_mutex
int key_down_count; // under key_queue_mutex
bool enable_reboot; // under key_queue_mutex
int rel_sum;
// key press events
std::mutex key_press_mutex;
char key_pressed[KEY_MAX + 1];
int key_last_down;
bool key_long_press;
int key_down_count;
bool enable_reboot;
int rel_sum;
int consecutive_power_keys;
bool has_power_key;

View file

@ -345,7 +345,7 @@ void RecoveryUI::ProcessKey(int key_code, int updown) {
bool long_press = false;
{
std::lock_guard<std::mutex> lg(key_queue_mutex);
std::lock_guard<std::mutex> lg(key_press_mutex);
key_pressed[key_code] = updown;
if (updown) {
++key_down_count;
@ -392,7 +392,7 @@ void RecoveryUI::TimeKey(int key_code, int count) {
std::this_thread::sleep_for(750ms); // 750 ms == "long"
bool long_press = false;
{
std::lock_guard<std::mutex> lg(key_queue_mutex);
std::lock_guard<std::mutex> lg(key_press_mutex);
if (key_last_down == key_code && key_down_count == count) {
long_press = key_long_press = true;
}
@ -517,13 +517,13 @@ bool RecoveryUI::IsUsbConnected() {
}
bool RecoveryUI::IsKeyPressed(int key) {
std::lock_guard<std::mutex> lg(key_queue_mutex);
std::lock_guard<std::mutex> lg(key_press_mutex);
int pressed = key_pressed[key];
return pressed;
}
bool RecoveryUI::IsLongPress() {
std::lock_guard<std::mutex> lg(key_queue_mutex);
std::lock_guard<std::mutex> lg(key_press_mutex);
bool result = key_long_press;
return result;
}
@ -547,7 +547,7 @@ void RecoveryUI::FlushKeys() {
RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
{
std::lock_guard<std::mutex> lg(key_queue_mutex);
std::lock_guard<std::mutex> lg(key_press_mutex);
key_long_press = false;
}
@ -590,6 +590,6 @@ RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
void RecoveryUI::KeyLongPress(int) {}
void RecoveryUI::SetEnableReboot(bool enabled) {
std::lock_guard<std::mutex> lg(key_queue_mutex);
std::lock_guard<std::mutex> lg(key_press_mutex);
enable_reboot = enabled;
}