From ff9b4ff8c918d6e8934b3e0d58bc31fce99a6cf2 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Mon, 4 Mar 2013 22:22:03 -0500 Subject: [PATCH] Lock BMenuBar::_Track() atomically. Fixes #9481 --- src/kits/interface/MenuBar.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp index 8c7dc13fda..b582d87087 100644 --- a/src/kits/interface/MenuBar.cpp +++ b/src/kits/interface/MenuBar.cpp @@ -557,24 +557,22 @@ BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu) { // TODO: Cleanup, merge some "if" blocks if possible fChosenItem = NULL; - - BWindow* window = Window(); fState = MENU_STATE_TRACKING; BPoint where; uint32 buttons; - if (window->Lock()) { + if (LockLooper()) { if (startIndex != -1) { be_app->ObscureCursor(); _SelectItem(ItemAt(startIndex), true, false); } GetMouse(&where, &buttons); - window->Unlock(); + UnlockLooper(); } while (fState != MENU_STATE_CLOSED) { bigtime_t snoozeAmount = 40000; - if (Window() == NULL || !window->Lock()) + if (!LockLooper()) break; BMenuItem* menuItem = NULL; @@ -587,7 +585,7 @@ BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu) // call _Track() from the selected sub-menu when the mouse cursor // is over its window BMenu* menu = fSelected->Submenu(); - window->Unlock(); + UnlockLooper(); snoozeAmount = 30000; bool wasSticky = _IsStickyMode(); menu->_SetStickyMode(wasSticky); @@ -602,9 +600,9 @@ BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu) // where to store the current mouse position ? // (Or just use the BView mouse hooks) BPoint newWhere; - if (window->Lock()) { + if (LockLooper()) { GetMouse(&newWhere, &buttons); - window->Unlock(); + UnlockLooper(); } // This code is needed to make menus @@ -619,7 +617,7 @@ BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu) } else fState = MENU_STATE_CLOSED; } - if (!window->Lock()) + if (!LockLooper()) break; } else if (menuItem != NULL) { if (menuItem->Submenu() != NULL && menuItem != fSelected) { @@ -642,7 +640,7 @@ BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu) fState = MENU_STATE_TRACKING; } - window->Unlock(); + UnlockLooper(); if (fState != MENU_STATE_CLOSED) { // If user doesn't move the mouse, loop here, @@ -680,14 +678,14 @@ BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu) } } - if (window->Lock()) { + if (LockLooper()) { if (fSelected != NULL) _SelectItem(NULL); if (fChosenItem != NULL) fChosenItem->Invoke(); _RestoreFocus(); - window->Unlock(); + UnlockLooper(); } if (_IsStickyMode())