Merge "recovery: c++ify pthread use in UI"

This commit is contained in:
Jerry Zhang
2018-05-30 00:48:30 +00:00
committed by Gerrit Code Review
5 changed files with 86 additions and 126 deletions
+44 -64
View File
@@ -19,8 +19,6 @@
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <linux/input.h>
#include <pthread.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -171,8 +169,7 @@ ScreenRecoveryUI::ScreenRecoveryUI(bool scrollable_menu)
stage(-1), stage(-1),
max_stage(-1), max_stage(-1),
locale_(""), locale_(""),
rtl_locale_(false), rtl_locale_(false) {}
updateMutex(PTHREAD_MUTEX_INITIALIZER) {}
ScreenRecoveryUI::~ScreenRecoveryUI() { ScreenRecoveryUI::~ScreenRecoveryUI() {
progress_thread_stopped_ = true; progress_thread_stopped_ = true;
@@ -368,7 +365,7 @@ void ScreenRecoveryUI::SelectAndShowBackgroundText(const std::vector<std::string
surfaces.emplace(name, std::unique_ptr<GRSurface, decltype(&free)>(text_image, &free)); surfaces.emplace(name, std::unique_ptr<GRSurface, decltype(&free)>(text_image, &free));
} }
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
gr_color(0, 0, 0, 255); gr_color(0, 0, 0, 255);
gr_clear(); gr_clear();
@@ -400,7 +397,6 @@ void ScreenRecoveryUI::SelectAndShowBackgroundText(const std::vector<std::string
} }
// Update the whole screen. // Update the whole screen.
gr_flip(); gr_flip();
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::CheckBackgroundTextImages() { void ScreenRecoveryUI::CheckBackgroundTextImages() {
@@ -624,42 +620,42 @@ void ScreenRecoveryUI::ProgressThreadLoop() {
double interval = 1.0 / kAnimationFps; double interval = 1.0 / kAnimationFps;
while (!progress_thread_stopped_) { while (!progress_thread_stopped_) {
double start = now(); double start = now();
pthread_mutex_lock(&updateMutex);
bool redraw = false; bool redraw = false;
{
std::lock_guard<std::mutex> lg(updateMutex);
// update the installation animation, if active // update the installation animation, if active
// skip this if we have a text overlay (too expensive to update) // skip this if we have a text overlay (too expensive to update)
if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && !show_text) { if ((currentIcon == INSTALLING_UPDATE || currentIcon == ERASING) && !show_text) {
if (!intro_done) { if (!intro_done) {
if (current_frame == intro_frames - 1) { if (current_frame == intro_frames - 1) {
intro_done = true; intro_done = true;
current_frame = 0; current_frame = 0;
} else {
++current_frame;
}
} else { } else {
++current_frame; current_frame = (current_frame + 1) % loop_frames;
} }
} else {
current_frame = (current_frame + 1) % loop_frames;
}
redraw = true;
}
// move the progress bar forward on timed intervals, if configured
int duration = progressScopeDuration;
if (progressBarType == DETERMINATE && duration > 0) {
double elapsed = now() - progressScopeTime;
float p = 1.0 * elapsed / duration;
if (p > 1.0) p = 1.0;
if (p > progress) {
progress = p;
redraw = true; redraw = true;
} }
// move the progress bar forward on timed intervals, if configured
int duration = progressScopeDuration;
if (progressBarType == DETERMINATE && duration > 0) {
double elapsed = now() - progressScopeTime;
float p = 1.0 * elapsed / duration;
if (p > 1.0) p = 1.0;
if (p > progress) {
progress = p;
redraw = true;
}
}
if (redraw) update_progress_locked();
} }
if (redraw) update_progress_locked();
pthread_mutex_unlock(&updateMutex);
double end = now(); double end = now();
// minimum of 20ms delay between frames // minimum of 20ms delay between frames
double delay = interval - (end - start); double delay = interval - (end - start);
@@ -799,16 +795,14 @@ void ScreenRecoveryUI::LoadAnimation() {
} }
void ScreenRecoveryUI::SetBackground(Icon icon) { void ScreenRecoveryUI::SetBackground(Icon icon) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
currentIcon = icon; currentIcon = icon;
update_screen_locked(); update_screen_locked();
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::SetProgressType(ProgressType type) { void ScreenRecoveryUI::SetProgressType(ProgressType type) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
if (progressBarType != type) { if (progressBarType != type) {
progressBarType = type; progressBarType = type;
} }
@@ -816,11 +810,10 @@ void ScreenRecoveryUI::SetProgressType(ProgressType type) {
progressScopeSize = 0; progressScopeSize = 0;
progress = 0; progress = 0;
update_progress_locked(); update_progress_locked();
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::ShowProgress(float portion, float seconds) { void ScreenRecoveryUI::ShowProgress(float portion, float seconds) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
progressBarType = DETERMINATE; progressBarType = DETERMINATE;
progressScopeStart += progressScopeSize; progressScopeStart += progressScopeSize;
progressScopeSize = portion; progressScopeSize = portion;
@@ -828,11 +821,10 @@ void ScreenRecoveryUI::ShowProgress(float portion, float seconds) {
progressScopeDuration = seconds; progressScopeDuration = seconds;
progress = 0; progress = 0;
update_progress_locked(); update_progress_locked();
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::SetProgress(float fraction) { void ScreenRecoveryUI::SetProgress(float fraction) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
if (fraction < 0.0) fraction = 0.0; if (fraction < 0.0) fraction = 0.0;
if (fraction > 1.0) fraction = 1.0; if (fraction > 1.0) fraction = 1.0;
if (progressBarType == DETERMINATE && fraction > progress) { if (progressBarType == DETERMINATE && fraction > progress) {
@@ -844,14 +836,12 @@ void ScreenRecoveryUI::SetProgress(float fraction) {
update_progress_locked(); update_progress_locked();
} }
} }
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::SetStage(int current, int max) { void ScreenRecoveryUI::SetStage(int current, int max) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
stage = current; stage = current;
max_stage = max; max_stage = max;
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) { void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
@@ -862,7 +852,7 @@ void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap)
fputs(str.c_str(), stdout); fputs(str.c_str(), stdout);
} }
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
if (text_rows_ > 0 && text_cols_ > 0) { if (text_rows_ > 0 && text_cols_ > 0) {
for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) { for (const char* ptr = str.c_str(); *ptr != '\0'; ++ptr) {
if (*ptr == '\n' || text_col_ >= text_cols_) { if (*ptr == '\n' || text_col_ >= text_cols_) {
@@ -875,7 +865,6 @@ void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap)
text_[text_row_][text_col_] = '\0'; text_[text_row_][text_col_] = '\0';
update_screen_locked(); update_screen_locked();
} }
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::Print(const char* fmt, ...) { void ScreenRecoveryUI::Print(const char* fmt, ...) {
@@ -893,23 +882,21 @@ void ScreenRecoveryUI::PrintOnScreenOnly(const char *fmt, ...) {
} }
void ScreenRecoveryUI::PutChar(char ch) { void ScreenRecoveryUI::PutChar(char ch) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
if (ch != '\n') text_[text_row_][text_col_++] = ch; if (ch != '\n') text_[text_row_][text_col_++] = ch;
if (ch == '\n' || text_col_ >= text_cols_) { if (ch == '\n' || text_col_ >= text_cols_) {
text_col_ = 0; text_col_ = 0;
++text_row_; ++text_row_;
} }
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::ClearText() { void ScreenRecoveryUI::ClearText() {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
text_col_ = 0; text_col_ = 0;
text_row_ = 0; text_row_ = 0;
for (size_t i = 0; i < text_rows_; ++i) { for (size_t i = 0; i < text_rows_; ++i) {
memset(text_[i], 0, text_cols_ + 1); memset(text_[i], 0, text_cols_ + 1);
} }
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::ShowFile(FILE* fp) { void ScreenRecoveryUI::ShowFile(FILE* fp) {
@@ -986,17 +973,16 @@ void ScreenRecoveryUI::ShowFile(const std::string& filename) {
void ScreenRecoveryUI::StartMenu(const std::vector<std::string>& headers, void ScreenRecoveryUI::StartMenu(const std::vector<std::string>& headers,
const std::vector<std::string>& items, size_t initial_selection) { const std::vector<std::string>& items, size_t initial_selection) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
if (text_rows_ > 0 && text_cols_ > 1) { if (text_rows_ > 0 && text_cols_ > 1) {
menu_ = std::make_unique<Menu>(scrollable_menu_, text_rows_, text_cols_ - 1, headers, items, menu_ = std::make_unique<Menu>(scrollable_menu_, text_rows_, text_cols_ - 1, headers, items,
initial_selection); initial_selection);
update_screen_locked(); update_screen_locked();
} }
pthread_mutex_unlock(&updateMutex);
} }
int ScreenRecoveryUI::SelectMenu(int sel) { int ScreenRecoveryUI::SelectMenu(int sel) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
if (menu_) { if (menu_) {
int old_sel = menu_->selection(); int old_sel = menu_->selection();
sel = menu_->Select(sel); sel = menu_->Select(sel);
@@ -1005,17 +991,15 @@ int ScreenRecoveryUI::SelectMenu(int sel) {
update_screen_locked(); update_screen_locked();
} }
} }
pthread_mutex_unlock(&updateMutex);
return sel; return sel;
} }
void ScreenRecoveryUI::EndMenu() { void ScreenRecoveryUI::EndMenu() {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
if (menu_) { if (menu_) {
menu_.reset(); menu_.reset();
update_screen_locked(); update_screen_locked();
} }
pthread_mutex_unlock(&updateMutex);
} }
size_t ScreenRecoveryUI::ShowMenu(const std::vector<std::string>& headers, size_t ScreenRecoveryUI::ShowMenu(const std::vector<std::string>& headers,
@@ -1067,31 +1051,27 @@ size_t ScreenRecoveryUI::ShowMenu(const std::vector<std::string>& headers,
} }
bool ScreenRecoveryUI::IsTextVisible() { bool ScreenRecoveryUI::IsTextVisible() {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
int visible = show_text; int visible = show_text;
pthread_mutex_unlock(&updateMutex);
return visible; return visible;
} }
bool ScreenRecoveryUI::WasTextEverVisible() { bool ScreenRecoveryUI::WasTextEverVisible() {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
int ever_visible = show_text_ever; int ever_visible = show_text_ever;
pthread_mutex_unlock(&updateMutex);
return ever_visible; return ever_visible;
} }
void ScreenRecoveryUI::ShowText(bool visible) { void ScreenRecoveryUI::ShowText(bool visible) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
show_text = visible; show_text = visible;
if (show_text) show_text_ever = true; if (show_text) show_text_ever = true;
update_screen_locked(); update_screen_locked();
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::Redraw() { void ScreenRecoveryUI::Redraw() {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
update_screen_locked(); update_screen_locked();
pthread_mutex_unlock(&updateMutex);
} }
void ScreenRecoveryUI::KeyLongPress(int) { void ScreenRecoveryUI::KeyLongPress(int) {
+1 -3
View File
@@ -17,7 +17,6 @@
#ifndef RECOVERY_SCREEN_UI_H #ifndef RECOVERY_SCREEN_UI_H
#define RECOVERY_SCREEN_UI_H #define RECOVERY_SCREEN_UI_H
#include <pthread.h>
#include <stdio.h> #include <stdio.h>
#include <atomic> #include <atomic>
@@ -192,7 +191,6 @@ class ScreenRecoveryUI : public RecoveryUI {
GRSurface* GetCurrentFrame() const; GRSurface* GetCurrentFrame() const;
GRSurface* GetCurrentText() const; GRSurface* GetCurrentText() const;
static void* ProgressThreadStartRoutine(void* data);
void ProgressThreadLoop(); void ProgressThreadLoop();
virtual void ShowFile(FILE*); virtual void ShowFile(FILE*);
@@ -297,7 +295,7 @@ class ScreenRecoveryUI : public RecoveryUI {
std::string locale_; std::string locale_;
bool rtl_locale_; bool rtl_locale_;
pthread_mutex_t updateMutex; std::mutex updateMutex;
private: private:
void SetLocale(const std::string&); void SetLocale(const std::string&);
+36 -53
View File
@@ -18,8 +18,6 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <linux/input.h>
#include <pthread.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -74,8 +72,6 @@ RecoveryUI::RecoveryUI()
touch_slot_(0), touch_slot_(0),
is_bootreason_recovery_ui_(false), is_bootreason_recovery_ui_(false),
screensaver_state_(ScreensaverState::DISABLED) { screensaver_state_(ScreensaverState::DISABLED) {
pthread_mutex_init(&key_queue_mutex, nullptr);
pthread_cond_init(&key_queue_cond, nullptr);
memset(key_pressed, 0, sizeof(key_pressed)); memset(key_pressed, 0, sizeof(key_pressed));
} }
@@ -341,25 +337,25 @@ void RecoveryUI::ProcessKey(int key_code, int updown) {
bool register_key = false; bool register_key = false;
bool long_press = false; bool long_press = false;
pthread_mutex_lock(&key_queue_mutex); {
key_pressed[key_code] = updown; std::lock_guard<std::mutex> lg(key_queue_mutex);
if (updown) { key_pressed[key_code] = updown;
++key_down_count; if (updown) {
key_last_down = key_code; ++key_down_count;
key_long_press = false; key_last_down = key_code;
key_long_press = false;
std::thread time_key_thread(&RecoveryUI::TimeKey, this, key_code, key_down_count); std::thread time_key_thread(&RecoveryUI::TimeKey, this, key_code, key_down_count);
time_key_thread.detach(); time_key_thread.detach();
} else { } else {
if (key_last_down == key_code) { if (key_last_down == key_code) {
long_press = key_long_press; long_press = key_long_press;
register_key = true; register_key = true;
}
key_last_down = -1;
} }
key_last_down = -1;
} }
bool reboot_enabled = enable_reboot;
pthread_mutex_unlock(&key_queue_mutex);
bool reboot_enabled = enable_reboot;
if (register_key) { if (register_key) {
switch (CheckKey(key_code, long_press)) { switch (CheckKey(key_code, long_press)) {
case RecoveryUI::IGNORE: case RecoveryUI::IGNORE:
@@ -388,44 +384,37 @@ void RecoveryUI::ProcessKey(int key_code, int updown) {
void RecoveryUI::TimeKey(int key_code, int count) { void RecoveryUI::TimeKey(int key_code, int count) {
std::this_thread::sleep_for(750ms); // 750 ms == "long" std::this_thread::sleep_for(750ms); // 750 ms == "long"
bool long_press = false; bool long_press = false;
pthread_mutex_lock(&key_queue_mutex); {
if (key_last_down == key_code && key_down_count == count) { std::lock_guard<std::mutex> lg(key_queue_mutex);
long_press = key_long_press = true; if (key_last_down == key_code && key_down_count == count) {
long_press = key_long_press = true;
}
} }
pthread_mutex_unlock(&key_queue_mutex);
if (long_press) KeyLongPress(key_code); if (long_press) KeyLongPress(key_code);
} }
void RecoveryUI::EnqueueKey(int key_code) { void RecoveryUI::EnqueueKey(int key_code) {
pthread_mutex_lock(&key_queue_mutex); std::lock_guard<std::mutex> lg(key_queue_mutex);
const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]); const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
if (key_queue_len < queue_max) { if (key_queue_len < queue_max) {
key_queue[key_queue_len++] = key_code; key_queue[key_queue_len++] = key_code;
pthread_cond_signal(&key_queue_cond); key_queue_cond.notify_one();
} }
pthread_mutex_unlock(&key_queue_mutex);
} }
int RecoveryUI::WaitKey() { int RecoveryUI::WaitKey() {
pthread_mutex_lock(&key_queue_mutex); std::unique_lock<std::mutex> lk(key_queue_mutex);
// Time out after UI_WAIT_KEY_TIMEOUT_SEC, unless a USB cable is // Time out after UI_WAIT_KEY_TIMEOUT_SEC, unless a USB cable is
// plugged in. // plugged in.
do { do {
struct timeval now; std::cv_status rc = std::cv_status::no_timeout;
struct timespec timeout; while (key_queue_len == 0 && rc != std::cv_status::timeout) {
gettimeofday(&now, nullptr); rc = key_queue_cond.wait_for(lk, std::chrono::seconds(UI_WAIT_KEY_TIMEOUT_SEC));
timeout.tv_sec = now.tv_sec;
timeout.tv_nsec = now.tv_usec * 1000;
timeout.tv_sec += UI_WAIT_KEY_TIMEOUT_SEC;
int rc = 0;
while (key_queue_len == 0 && rc != ETIMEDOUT) {
rc = pthread_cond_timedwait(&key_queue_cond, &key_queue_mutex, &timeout);
} }
if (screensaver_state_ != ScreensaverState::DISABLED) { if (screensaver_state_ != ScreensaverState::DISABLED) {
if (rc == ETIMEDOUT) { if (rc == std::cv_status::timeout) {
// Lower the brightness level: NORMAL -> DIMMED; DIMMED -> OFF. // Lower the brightness level: NORMAL -> DIMMED; DIMMED -> OFF.
if (screensaver_state_ == ScreensaverState::NORMAL) { if (screensaver_state_ == ScreensaverState::NORMAL) {
if (android::base::WriteStringToFile(std::to_string(brightness_dimmed_value_), if (android::base::WriteStringToFile(std::to_string(brightness_dimmed_value_),
@@ -464,7 +453,6 @@ int RecoveryUI::WaitKey() {
key = key_queue[0]; key = key_queue[0];
memcpy(&key_queue[0], &key_queue[1], sizeof(int) * --key_queue_len); memcpy(&key_queue[0], &key_queue[1], sizeof(int) * --key_queue_len);
} }
pthread_mutex_unlock(&key_queue_mutex);
return key; return key;
} }
@@ -485,16 +473,14 @@ bool RecoveryUI::IsUsbConnected() {
} }
bool RecoveryUI::IsKeyPressed(int key) { bool RecoveryUI::IsKeyPressed(int key) {
pthread_mutex_lock(&key_queue_mutex); std::lock_guard<std::mutex> lg(key_queue_mutex);
int pressed = key_pressed[key]; int pressed = key_pressed[key];
pthread_mutex_unlock(&key_queue_mutex);
return pressed; return pressed;
} }
bool RecoveryUI::IsLongPress() { bool RecoveryUI::IsLongPress() {
pthread_mutex_lock(&key_queue_mutex); std::lock_guard<std::mutex> lg(key_queue_mutex);
bool result = key_long_press; bool result = key_long_press;
pthread_mutex_unlock(&key_queue_mutex);
return result; return result;
} }
@@ -511,15 +497,15 @@ bool RecoveryUI::HasTouchScreen() const {
} }
void RecoveryUI::FlushKeys() { void RecoveryUI::FlushKeys() {
pthread_mutex_lock(&key_queue_mutex); std::lock_guard<std::mutex> lg(key_queue_mutex);
key_queue_len = 0; key_queue_len = 0;
pthread_mutex_unlock(&key_queue_mutex);
} }
RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) { RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
pthread_mutex_lock(&key_queue_mutex); {
key_long_press = false; std::lock_guard<std::mutex> lg(key_queue_mutex);
pthread_mutex_unlock(&key_queue_mutex); key_long_press = false;
}
// If we have power and volume up keys, that chord is the signal to toggle the text display. // If we have power and volume up keys, that chord is the signal to toggle the text display.
if (HasThreeButtons() || (HasPowerKey() && HasTouchScreen() && touch_screen_allowed_)) { if (HasThreeButtons() || (HasPowerKey() && HasTouchScreen() && touch_screen_allowed_)) {
@@ -542,9 +528,7 @@ RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
// Press power seven times in a row to reboot. // Press power seven times in a row to reboot.
if (key == KEY_POWER) { if (key == KEY_POWER) {
pthread_mutex_lock(&key_queue_mutex);
bool reboot_enabled = enable_reboot; bool reboot_enabled = enable_reboot;
pthread_mutex_unlock(&key_queue_mutex);
if (reboot_enabled) { if (reboot_enabled) {
++consecutive_power_keys; ++consecutive_power_keys;
@@ -564,7 +548,6 @@ void RecoveryUI::KeyLongPress(int) {
} }
void RecoveryUI::SetEnableReboot(bool enabled) { void RecoveryUI::SetEnableReboot(bool enabled) {
pthread_mutex_lock(&key_queue_mutex); std::lock_guard<std::mutex> lg(key_queue_mutex);
enable_reboot = enabled; enable_reboot = enabled;
pthread_mutex_unlock(&key_queue_mutex);
} }
+4 -3
View File
@@ -18,10 +18,11 @@
#define RECOVERY_UI_H #define RECOVERY_UI_H
#include <linux/input.h> // KEY_MAX #include <linux/input.h> // KEY_MAX
#include <pthread.h>
#include <atomic> #include <atomic>
#include <condition_variable>
#include <functional> #include <functional>
#include <mutex>
#include <string> #include <string>
#include <thread> #include <thread>
#include <vector> #include <vector>
@@ -188,8 +189,8 @@ class RecoveryUI {
bool InitScreensaver(); bool InitScreensaver();
// Key event input queue // Key event input queue
pthread_mutex_t key_queue_mutex; std::mutex key_queue_mutex;
pthread_cond_t key_queue_cond; std::condition_variable key_queue_cond;
int key_queue[256], key_queue_len; int key_queue[256], key_queue_len;
char key_pressed[KEY_MAX + 1]; // under key_queue_mutex char key_pressed[KEY_MAX + 1]; // under key_queue_mutex
int key_last_down; // under key_queue_mutex int key_last_down; // under key_queue_mutex
+1 -3
View File
@@ -16,7 +16,6 @@
#include "wear_ui.h" #include "wear_ui.h"
#include <pthread.h>
#include <string.h> #include <string.h>
#include <string> #include <string>
@@ -86,11 +85,10 @@ void WearRecoveryUI::SetStage(int /* current */, int /* max */) {}
void WearRecoveryUI::StartMenu(const std::vector<std::string>& headers, void WearRecoveryUI::StartMenu(const std::vector<std::string>& headers,
const std::vector<std::string>& items, size_t initial_selection) { const std::vector<std::string>& items, size_t initial_selection) {
pthread_mutex_lock(&updateMutex); std::lock_guard<std::mutex> lg(updateMutex);
if (text_rows_ > 0 && text_cols_ > 0) { if (text_rows_ > 0 && text_cols_ > 0) {
menu_ = std::make_unique<Menu>(scrollable_menu_, text_rows_ - kMenuUnusableRows - 1, menu_ = std::make_unique<Menu>(scrollable_menu_, text_rows_ - kMenuUnusableRows - 1,
text_cols_ - 1, headers, items, initial_selection); text_cols_ - 1, headers, items, initial_selection);
update_screen_locked(); update_screen_locked();
} }
pthread_mutex_unlock(&updateMutex);
} }