Made the BToolTipManager lock non-static. Create the singleton via
pthread_once(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34366 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
bc78ca9385
commit
4ac097c559
@ -26,19 +26,22 @@ public:
|
||||
void SetHideDelay(bigtime_t time);
|
||||
bigtime_t HideDelay() const;
|
||||
|
||||
static bool Lock() { return sLock.Lock(); }
|
||||
static void Unlock() { sLock.Unlock(); }
|
||||
bool Lock() { return fLock.Lock(); }
|
||||
void Unlock() { fLock.Unlock(); }
|
||||
|
||||
private:
|
||||
BToolTipManager();
|
||||
virtual ~BToolTipManager();
|
||||
|
||||
static void _InitSingleton();
|
||||
|
||||
private:
|
||||
BLocker fLock;
|
||||
BMessenger fWindow;
|
||||
|
||||
bigtime_t fShowDelay;
|
||||
bigtime_t fHideDelay;
|
||||
|
||||
static BLocker sLock;
|
||||
static BToolTipManager* sDefaultInstance;
|
||||
};
|
||||
|
||||
|
@ -110,10 +110,11 @@ BToolTip::Lock()
|
||||
while (true) {
|
||||
lockedLooper = View()->LockLooper();
|
||||
if (!lockedLooper) {
|
||||
BToolTipManager::Lock();
|
||||
BToolTipManager* manager = BToolTipManager::Manager();
|
||||
manager->Lock();
|
||||
|
||||
if (View()->Window() != NULL) {
|
||||
BToolTipManager::Unlock();
|
||||
manager->Unlock();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -131,7 +132,7 @@ BToolTip::Unlock()
|
||||
if (fLockedLooper)
|
||||
View()->UnlockLooper();
|
||||
else
|
||||
BToolTipManager::Unlock();
|
||||
BToolTipManager::Manager()->Unlock();
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <ToolTipManager.h>
|
||||
#include <ToolTipWindow.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <Autolock.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <MessageRunner.h>
|
||||
@ -17,7 +19,7 @@
|
||||
#include <ToolTip.h>
|
||||
|
||||
|
||||
BLocker BToolTipManager::sLock("tool tip manager");
|
||||
static pthread_once_t sManagerInitOnce = PTHREAD_ONCE_INIT;
|
||||
BToolTipManager* BToolTipManager::sDefaultInstance;
|
||||
|
||||
static const uint32 kMsgHideToolTip = 'hide';
|
||||
@ -59,13 +61,14 @@ public:
|
||||
|
||||
virtual void DetachedFromWindow()
|
||||
{
|
||||
BToolTipManager::Lock();
|
||||
BToolTipManager* manager = BToolTipManager::Manager();
|
||||
manager->Lock();
|
||||
|
||||
RemoveChild(fToolTip->View());
|
||||
// don't delete this one!
|
||||
fToolTip->DetachedFromWindow();
|
||||
|
||||
BToolTipManager::Unlock();
|
||||
manager->Unlock();
|
||||
}
|
||||
|
||||
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||
@ -117,9 +120,10 @@ ToolTipWindow::ToolTipWindow(BToolTip* tip, BPoint where)
|
||||
{
|
||||
SetLayout(new BGroupLayout(B_VERTICAL));
|
||||
|
||||
BToolTipManager::Lock();
|
||||
BToolTipManager* manager = BToolTipManager::Manager();
|
||||
manager->Lock();
|
||||
AddChild(new ToolTipView(tip));
|
||||
BToolTipManager::Unlock();
|
||||
manager->Unlock();
|
||||
|
||||
BSize size = ChildAt(0)->PreferredSize();
|
||||
ResizeTo(size.width, size.height);
|
||||
@ -194,15 +198,23 @@ ToolTipWindow::MessageReceived(BMessage* message)
|
||||
/*static*/ BToolTipManager*
|
||||
BToolTipManager::Manager()
|
||||
{
|
||||
BAutolock _(sLock);
|
||||
|
||||
// Note: The check is not necessary; it's just faster than always calling
|
||||
// pthread_once(). It requires reading/writing of pointers to be atomic
|
||||
// on the architecture.
|
||||
if (sDefaultInstance == NULL)
|
||||
sDefaultInstance = new BToolTipManager();
|
||||
pthread_once(&sManagerInitOnce, &_InitSingleton);
|
||||
|
||||
return sDefaultInstance;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ void
|
||||
BToolTipManager::_InitSingleton()
|
||||
{
|
||||
sDefaultInstance = new BToolTipManager();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BToolTipManager::ShowTip(BToolTip* tip, BPoint point)
|
||||
{
|
||||
@ -282,6 +294,7 @@ BToolTipManager::HideDelay() const
|
||||
|
||||
BToolTipManager::BToolTipManager()
|
||||
:
|
||||
fLock("tool tip manager"),
|
||||
fShowDelay(750000),
|
||||
fHideDelay(50000)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user