Skip to content

Commit

Permalink
Found a suspicious hang report that makes me think this mutex should …
Browse files Browse the repository at this point in the history
…be recursive.
  • Loading branch information
hrydgard committed May 18, 2017
1 parent 049d06c commit 79c0d89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions ext/native/ui/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void ScreenManager::update() {
}

void ScreenManager::switchToNext() {
std::lock_guard<std::mutex> guard(inputLock_);
std::lock_guard<std::recursive_mutex> guard(inputLock_);
if (!nextScreen_) {
ELOG("switchToNext: No nextScreen_!");
}
Expand All @@ -69,7 +69,7 @@ void ScreenManager::switchToNext() {
}

bool ScreenManager::touch(const TouchInput &touch) {
std::lock_guard<std::mutex> guard(inputLock_);
std::lock_guard<std::recursive_mutex> guard(inputLock_);
if (!stack_.empty()) {
Screen *screen = stack_.back().screen;
return screen->touch(screen->transformTouch(touch));
Expand All @@ -79,7 +79,7 @@ bool ScreenManager::touch(const TouchInput &touch) {
}

bool ScreenManager::key(const KeyInput &key) {
std::lock_guard<std::mutex> guard(inputLock_);
std::lock_guard<std::recursive_mutex> guard(inputLock_);
if (!stack_.empty()) {
return stack_.back().screen->key(key);
} else {
Expand All @@ -88,7 +88,7 @@ bool ScreenManager::key(const KeyInput &key) {
}

bool ScreenManager::axis(const AxisInput &axis) {
std::lock_guard<std::mutex> guard(inputLock_);
std::lock_guard<std::recursive_mutex> guard(inputLock_);
if (!stack_.empty()) {
return stack_.back().screen->axis(axis);
} else {
Expand All @@ -97,7 +97,7 @@ bool ScreenManager::axis(const AxisInput &axis) {
}

void ScreenManager::resized() {
std::lock_guard<std::mutex> guard(inputLock_);
std::lock_guard<std::recursive_mutex> guard(inputLock_);
// Have to notify the whole stack, otherwise there will be problems when going back
// to non-top screens.
for (auto iter = stack_.begin(); iter != stack_.end(); ++iter) {
Expand Down Expand Up @@ -171,7 +171,7 @@ Screen *ScreenManager::topScreen() const {
}

void ScreenManager::shutdown() {
std::lock_guard<std::mutex> guard(inputLock_);
std::lock_guard<std::recursive_mutex> guard(inputLock_);
for (auto x = stack_.begin(); x != stack_.end(); x++)
delete x->screen;
stack_.clear();
Expand All @@ -180,7 +180,7 @@ void ScreenManager::shutdown() {
}

void ScreenManager::push(Screen *screen, int layerFlags) {
std::lock_guard<std::mutex> guard(inputLock_);
std::lock_guard<std::recursive_mutex> guard(inputLock_);
if (nextScreen_ && stack_.empty()) {
// we're during init, this is OK
switchToNext();
Expand All @@ -195,7 +195,7 @@ void ScreenManager::push(Screen *screen, int layerFlags) {
}

void ScreenManager::pop() {
std::lock_guard<std::mutex> guard(inputLock_);
std::lock_guard<std::recursive_mutex> guard(inputLock_);
if (stack_.size()) {
delete stack_.back().screen;
stack_.pop_back();
Expand Down Expand Up @@ -226,7 +226,7 @@ void ScreenManager::finishDialog(Screen *dialog, DialogResult result) {

void ScreenManager::processFinishDialog() {
if (dialogFinished_) {
std::lock_guard<std::mutex> guard(inputLock_);
std::lock_guard<std::recursive_mutex> guard(inputLock_);
// Another dialog may have been pushed before the render, so search for it.
Screen *caller = 0;
for (size_t i = 0; i < stack_.size(); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion ext/native/ui/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ScreenManager {

Screen *topScreen() const;

std::mutex inputLock_;
std::recursive_mutex inputLock_;

private:
void pop();
Expand Down
2 changes: 1 addition & 1 deletion ext/native/ui/ui_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ UIScreen::~UIScreen() {
}

void UIScreen::DoRecreateViews() {
std::lock_guard<std::mutex> guard(screenManager()->inputLock_);
std::lock_guard<std::recursive_mutex> guard(screenManager()->inputLock_);

if (recreateViews_) {
UI::PersistMap persisted;
Expand Down

0 comments on commit 79c0d89

Please sign in to comment.