diff --git a/src/apps/powerstatus/DriverInterface.cpp b/src/apps/powerstatus/DriverInterface.cpp index c8b2b46451..3d070c0140 100644 --- a/src/apps/powerstatus/DriverInterface.cpp +++ b/src/apps/powerstatus/DriverInterface.cpp @@ -21,6 +21,7 @@ Monitor::~Monitor() status_t Monitor::StartWatching(BHandler* target) { + BAutolock autolock(fListLocker); if (fWatcherList.HasItem(target)) return B_ERROR; @@ -32,6 +33,7 @@ Monitor::StartWatching(BHandler* target) status_t Monitor::StopWatching(BHandler* target) { + BAutolock autolock(fListLocker); return fWatcherList.RemoveItem(target); } @@ -64,8 +66,6 @@ PowerStatusDriverInterface::~PowerStatusDriverInterface() status_t PowerStatusDriverInterface::StartWatching(BHandler* target) { - BAutolock autolock(fListLocker); - status_t status = Monitor::StartWatching(target); if (status != B_OK) @@ -95,8 +95,6 @@ PowerStatusDriverInterface::StartWatching(BHandler* target) status_t PowerStatusDriverInterface::StopWatching(BHandler* target) { - BAutolock autolock(fListLocker); - if (fThreadId < 0) return B_BAD_VALUE; diff --git a/src/apps/powerstatus/DriverInterface.h b/src/apps/powerstatus/DriverInterface.h index 5d271b9731..da6e55785c 100644 --- a/src/apps/powerstatus/DriverInterface.h +++ b/src/apps/powerstatus/DriverInterface.h @@ -42,6 +42,7 @@ public: virtual void Broadcast(uint32 message); protected: + BLocker fListLocker; WatcherList fWatcherList; }; @@ -72,8 +73,6 @@ private: static int32 _ThreadWatchPowerFunction(void* data); thread_id fThreadId; - - BLocker fListLocker; }; diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index 56dad98ebb..57bc3a9764 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -400,7 +400,7 @@ PowerStatusReplicant::PowerStatusReplicant(BMessage* archive) PowerStatusReplicant::~PowerStatusReplicant() { - if (fExtWindowMessenger) + if (fMessengerExist) delete fExtWindowMessenger; fDriverInterface->StopWatching(this); @@ -536,6 +536,7 @@ PowerStatusReplicant::_Init() } fExtendedWindow = NULL; + fMessengerExist = false; fExtWindowMessenger = NULL; fDriverInterface->StartWatching(this); @@ -566,7 +567,10 @@ PowerStatusReplicant::_OpenExtendedWindow() msg.AddSpecifier("Hidden", int32(0)); if (fExtWindowMessenger->SendMessage(&msg) == B_BAD_PORT_ID) { fExtendedWindow = new ExtendedInfoWindow(fDriverInterface); + if (fMessengerExist) + delete fExtWindowMessenger; fExtWindowMessenger = new BMessenger(NULL, fExtendedWindow); + fMessengerExist = true; fExtendedWindow->Show(); } else diff --git a/src/apps/powerstatus/PowerStatusView.h b/src/apps/powerstatus/PowerStatusView.h index e4ebc7a85f..f3d7042898 100644 --- a/src/apps/powerstatus/PowerStatusView.h +++ b/src/apps/powerstatus/PowerStatusView.h @@ -86,6 +86,7 @@ class PowerStatusReplicant : public PowerStatusView void _OpenExtendedWindow(); BWindow* fExtendedWindow; + bool fMessengerExist; BMessenger* fExtWindowMessenger; };