Eliminate the second add-on monitor looper by inheriting AddOnManger

from AddOnMonitor. This solves a concurrency problem in the AddOnMonitorHandler
implementation which called into AddOnManager private methods on the wrong
looper thread without locking. Would have corrupted memory when unplugging
input devices during input_server initialization (so normally not encountered).
The code paths for adding devices were locking already, since those can be
called from other threads as well and this was anticipated.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39741 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2010-12-05 15:03:11 +00:00
parent 445751e17a
commit 509a3787b1
2 changed files with 9 additions and 24 deletions
+7 -21
View File
@@ -123,14 +123,17 @@ instantiate_add_on(image_id image, const char* path, const char* type)
AddOnManager::AddOnManager(bool safeMode) AddOnManager::AddOnManager(bool safeMode)
: :
BLooper("add-on manager"), AddOnMonitor(),
fHandler(new(std::nothrow) MonitorHandler(this)),
fSafeMode(safeMode) fSafeMode(safeMode)
{ {
SetHandler(fHandler);
} }
AddOnManager::~AddOnManager() AddOnManager::~AddOnManager()
{ {
delete fHandler;
} }
@@ -175,6 +178,7 @@ AddOnManager::MessageReceived(BMessage* message)
return; return;
default: default:
AddOnMonitor::MessageReceived(message);
return; return;
} }
@@ -255,17 +259,6 @@ AddOnManager::_RegisterAddOns()
{ {
CALLED(); CALLED();
BAutolock locker(this); BAutolock locker(this);
status_t err;
fHandler = new MonitorHandler(this);
fAddOnMonitor = new AddOnMonitor(fHandler);
err = fAddOnMonitor->InitCheck();
if (err != B_OK) {
ERROR("AddOnManager::RegisterAddOns(): fAddOnMonitor->InitCheck() "
"returned %s\n", strerror(err));
return;
}
const directory_which directories[] = { const directory_which directories[] = {
B_USER_ADDONS_DIRECTORY, B_USER_ADDONS_DIRECTORY,
@@ -302,13 +295,6 @@ AddOnManager::_UnregisterAddOns()
{ {
BAutolock locker(this); BAutolock locker(this);
BMessenger messenger(fAddOnMonitor);
messenger.SendMessage(B_QUIT_REQUESTED);
int32 exitValue;
wait_for_thread(fAddOnMonitor->Thread(), &exitValue);
delete fHandler;
fHandler = NULL;
// We have to stop manually the add-ons because the monitor doesn't // We have to stop manually the add-ons because the monitor doesn't
// disable them on exit // disable them on exit
@@ -624,9 +610,9 @@ AddOnManager::_LoadReplicant()
be_app->GetAppInfo(&info); be_app->GetAppInfo(&info);
status_t err = BDeskbar().AddItem(&info.ref); status_t err = BDeskbar().AddItem(&info.ref);
if (err != B_OK) { if (err != B_OK)
ERROR("Deskbar refuses to add method replicant: %s\n", strerror(err)); ERROR("Deskbar refuses to add method replicant: %s\n", strerror(err));
}
BMessage request(B_GET_PROPERTY); BMessage request(B_GET_PROPERTY);
BMessenger to; BMessenger to;
BMessenger status; BMessenger status;
+2 -3
View File
@@ -25,7 +25,7 @@
using namespace BPrivate; using namespace BPrivate;
class AddOnManager : public BLooper { class AddOnManager : public AddOnMonitor {
public: public:
AddOnManager(bool safeMode); AddOnManager(bool safeMode);
~AddOnManager(); ~AddOnManager();
@@ -122,9 +122,8 @@ private:
PathList fDevicePaths; PathList fDevicePaths;
MonitorHandler* fHandler; MonitorHandler* fHandler;
AddOnMonitor* fAddOnMonitor;
bool fSafeMode; bool fSafeMode;
}; };
#endif // ADD_ON_MANAGER_H #endif // ADD_ON_MANAGER_H