Ticket #9481: 0001-Use-LockLooper-in-BMenuBar-_Track-which-is-atomic.patch

File 0001-Use-LockLooper-in-BMenuBar-_Track-which-is-atomic.patch, 2.9 KB (added by jscipione, 11 years ago)

Patch that replaces window->(Un)Lock() with (Un)LockLooper()

  • src/kits/interface/MenuBar.cpp

    From c62af7064d2a59b569ad52c45fe19fbc6806a0d4 Mon Sep 17 00:00:00 2001
    From: John Scipione <jscipione@gmail.com>
    Date: Mon, 25 Feb 2013 18:15:30 -0500
    Subject: [PATCH] Use LockLooper() in BMenuBar::_Track() which is atomic.
    
    instead of Window()->Lock() which is not.
    ---
     src/kits/interface/MenuBar.cpp |   22 ++++++++++------------
     1 files changed, 10 insertions(+), 12 deletions(-)
    
    diff --git a/src/kits/interface/MenuBar.cpp b/src/kits/interface/MenuBar.cpp
    index 8c7dc13..4ae163f 100644
    a b BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu)  
    557557{
    558558    // TODO: Cleanup, merge some "if" blocks if possible
    559559    fChosenItem = NULL;
    560 
    561     BWindow* window = Window();
    562560    fState = MENU_STATE_TRACKING;
    563561
    564562    BPoint where;
    565563    uint32 buttons;
    566     if (window->Lock()) {
     564    if (LockLooper()) {
    567565        if (startIndex != -1) {
    568566            be_app->ObscureCursor();
    569567            _SelectItem(ItemAt(startIndex), true, false);
    570568        }
    571569        GetMouse(&where, &buttons);
    572         window->Unlock();
     570        UnlockLooper();
    573571    }
    574572
    575573    while (fState != MENU_STATE_CLOSED) {
    576574        bigtime_t snoozeAmount = 40000;
    577         if (Window() == NULL || !window->Lock())
     575        if (Window() == NULL || !LockLooper())
    578576            break;
    579577
    580578        BMenuItem* menuItem = NULL;
    BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu)  
    587585            // call _Track() from the selected sub-menu when the mouse cursor
    588586            // is over its window
    589587            BMenu* menu = fSelected->Submenu();
    590             window->Unlock();
     588            UnlockLooper();
    591589            snoozeAmount = 30000;
    592590            bool wasSticky = _IsStickyMode();
    593591            menu->_SetStickyMode(wasSticky);
    BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu)  
    602600            // where to store the current mouse position ?
    603601            // (Or just use the BView mouse hooks)
    604602            BPoint newWhere;
    605             if (window->Lock()) {
     603            if (LockLooper()) {
    606604                GetMouse(&newWhere, &buttons);
    607                 window->Unlock();
     605                UnlockLooper();
    608606            }
    609607
    610608            // This code is needed to make menus
    BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu)  
    619617                } else
    620618                    fState = MENU_STATE_CLOSED;
    621619            }
    622             if (!window->Lock())
     620            if (!LockLooper())
    623621                break;
    624622        } else if (menuItem != NULL) {
    625623            if (menuItem->Submenu() != NULL && menuItem != fSelected) {
    BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu)  
    642640            fState = MENU_STATE_TRACKING;
    643641        }
    644642
    645         window->Unlock();
     643        UnlockLooper();
    646644
    647645        if (fState != MENU_STATE_CLOSED) {
    648646            // If user doesn't move the mouse, loop here,
    BMenuBar::_Track(int32* action, int32 startIndex, bool showMenu)  
    680678        }
    681679    }
    682680
    683     if (window->Lock()) {
     681    if (LockLooper()) {
    684682        if (fSelected != NULL)
    685683            _SelectItem(NULL);
    686684
    687685        if (fChosenItem != NULL)
    688686            fChosenItem->Invoke();
    689687        _RestoreFocus();
    690         window->Unlock();
     688        UnlockLooper();
    691689    }
    692690
    693691    if (_IsStickyMode())