input_server: don't lock device list for mouse settings
Instead of traversing the list of input devices when we are not given a mouse name, update a list of currently running ones on device start and stop. This makes the input_server message loop independent of other threads holding the device list lock. Fixes: #19100 Change-Id: I2d0d55da04fa506bef88bf731e1a719a64958a17 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8359 Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
b14c5d98b2
commit
cbc8ea5218
@@ -788,39 +788,45 @@ InputServer::_PostMouseControlMessage(int32 code, const BString& mouseName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InputServer::_DeviceStarted(InputDeviceListItem& item)
|
||||||
|
{
|
||||||
|
if (item.Type() == B_POINTING_DEVICE && item.Running() && fRunningMouseListLocker.Lock()) {
|
||||||
|
fRunningMouseList.Add(item.Name());
|
||||||
|
fRunningMouseListLocker.Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InputServer::_DeviceStopping(InputDeviceListItem& item)
|
||||||
|
{
|
||||||
|
if (item.Type() == B_POINTING_DEVICE && fRunningMouseListLocker.Lock()) {
|
||||||
|
fRunningMouseList.Remove(item.Name());
|
||||||
|
fRunningMouseListLocker.Unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MouseSettings*
|
MouseSettings*
|
||||||
InputServer::_RunningMouseSettings()
|
InputServer::_RunningMouseSettings()
|
||||||
{
|
{
|
||||||
BAutolock lock(fInputDeviceListLocker);
|
BAutolock lock(fRunningMouseListLocker);
|
||||||
|
|
||||||
int32 count = fInputDeviceList.CountItems();
|
if (fRunningMouseList.IsEmpty())
|
||||||
for (int32 i = 0; i < count; i++) {
|
return &fDefaultMouseSettings;
|
||||||
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(i);
|
return _GetSettingsForMouse(fRunningMouseList.First());
|
||||||
if (item == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (item->Type() == B_POINTING_DEVICE && item->Running())
|
|
||||||
return _GetSettingsForMouse(item->Name());
|
|
||||||
}
|
|
||||||
|
|
||||||
return &fDefaultMouseSettings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InputServer::_RunningMiceSettings(BList& settings)
|
InputServer::_RunningMiceSettings(BList& settings)
|
||||||
{
|
{
|
||||||
BAutolock lock(fInputDeviceListLocker);
|
BAutolock lock(fRunningMouseListLocker);
|
||||||
|
|
||||||
int32 count = fInputDeviceList.CountItems();
|
int32 count = fRunningMouseList.CountStrings();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++)
|
||||||
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(i);
|
settings.AddItem(_GetSettingsForMouse(fRunningMouseList.StringAt(i)));
|
||||||
if (item == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (item->Type() == B_POINTING_DEVICE && item->Running())
|
|
||||||
settings.AddItem(_GetSettingsForMouse(item->Name()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1282,6 +1288,7 @@ InputServer::UnregisterDevices(BInputServerDevice& serverDevice,
|
|||||||
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(j);
|
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(j);
|
||||||
|
|
||||||
if (item->ServerDevice() == &serverDevice && item->HasName(device->name)) {
|
if (item->ServerDevice() == &serverDevice && item->HasName(device->name)) {
|
||||||
|
_DeviceStopping(*item);
|
||||||
item->Stop();
|
item->Stop();
|
||||||
if (fInputDeviceList.RemoveItem(j)) {
|
if (fInputDeviceList.RemoveItem(j)) {
|
||||||
BMessage message(IS_NOTIFY_DEVICE);
|
BMessage message(IS_NOTIFY_DEVICE);
|
||||||
@@ -1301,6 +1308,7 @@ InputServer::UnregisterDevices(BInputServerDevice& serverDevice,
|
|||||||
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(i);
|
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(i);
|
||||||
|
|
||||||
if (item->ServerDevice() == &serverDevice) {
|
if (item->ServerDevice() == &serverDevice) {
|
||||||
|
_DeviceStopping(*item);
|
||||||
item->Stop();
|
item->Stop();
|
||||||
if (fInputDeviceList.RemoveItem(i))
|
if (fInputDeviceList.RemoveItem(i))
|
||||||
delete item;
|
delete item;
|
||||||
@@ -1348,6 +1356,7 @@ debug_printf("InputServer::RegisterDevices() device_ref already exists: %s\n", d
|
|||||||
*device);
|
*device);
|
||||||
if (item != NULL && fInputDeviceList.AddItem(item)) {
|
if (item != NULL && fInputDeviceList.AddItem(item)) {
|
||||||
item->Start();
|
item->Start();
|
||||||
|
_DeviceStarted(*item);
|
||||||
BMessage message(IS_NOTIFY_DEVICE);
|
BMessage message(IS_NOTIFY_DEVICE);
|
||||||
message.AddBool("added", true);
|
message.AddBool("added", true);
|
||||||
message.AddString("name", item->Name());
|
message.AddString("name", item->Name());
|
||||||
@@ -1385,10 +1394,13 @@ InputServer::StartStopDevices(const char* name, input_device_type type,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doStart)
|
if (doStart) {
|
||||||
item->Start();
|
item->Start();
|
||||||
else
|
_DeviceStarted(*item);
|
||||||
|
} else {
|
||||||
|
_DeviceStopping(*item);
|
||||||
item->Stop();
|
item->Stop();
|
||||||
|
}
|
||||||
|
|
||||||
BMessage message(IS_NOTIFY_DEVICE);
|
BMessage message(IS_NOTIFY_DEVICE);
|
||||||
message.AddBool("started", doStart);
|
message.AddBool("started", doStart);
|
||||||
@@ -1426,10 +1438,13 @@ InputServer::StartStopDevices(BInputServerDevice& serverDevice, bool doStart)
|
|||||||
if (doStart == item->Running())
|
if (doStart == item->Running())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (doStart)
|
if (doStart) {
|
||||||
item->Start();
|
item->Start();
|
||||||
else
|
_DeviceStarted(*item);
|
||||||
|
} else {
|
||||||
|
_DeviceStopping(*item);
|
||||||
item->Stop();
|
item->Stop();
|
||||||
|
}
|
||||||
|
|
||||||
BMessage message(IS_NOTIFY_DEVICE);
|
BMessage message(IS_NOTIFY_DEVICE);
|
||||||
message.AddBool("started", doStart);
|
message.AddBool("started", doStart);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
|
#include <StringList.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
#include <shared_cursor_area.h>
|
#include <shared_cursor_area.h>
|
||||||
@@ -190,6 +191,8 @@ class InputServer : public BApplication {
|
|||||||
|
|
||||||
MouseSettings* _RunningMouseSettings();
|
MouseSettings* _RunningMouseSettings();
|
||||||
void _RunningMiceSettings(BList& settings);
|
void _RunningMiceSettings(BList& settings);
|
||||||
|
void _DeviceStarted(InputDeviceListItem& item);
|
||||||
|
void _DeviceStopping(InputDeviceListItem& item);
|
||||||
MouseSettings* _GetSettingsForMouse(BString mouseName);
|
MouseSettings* _GetSettingsForMouse(BString mouseName);
|
||||||
status_t _PostMouseControlMessage(int32 code, const BString& mouseName);
|
status_t _PostMouseControlMessage(int32 code, const BString& mouseName);
|
||||||
|
|
||||||
@@ -219,6 +222,8 @@ class InputServer : public BApplication {
|
|||||||
KeyboardSettings fKeyboardSettings;
|
KeyboardSettings fKeyboardSettings;
|
||||||
MultipleMouseSettings fMouseSettings;
|
MultipleMouseSettings fMouseSettings;
|
||||||
MouseSettings fDefaultMouseSettings;
|
MouseSettings fDefaultMouseSettings;
|
||||||
|
BStringList fRunningMouseList;
|
||||||
|
BLocker fRunningMouseListLocker;
|
||||||
|
|
||||||
BPoint fMousePos; // current mouse position
|
BPoint fMousePos; // current mouse position
|
||||||
key_info fKeyInfo; // current key info
|
key_info fKeyInfo; // current key info
|
||||||
|
|||||||
Reference in New Issue
Block a user