* Keep an open count in the JoystickProtocolHandler.
* Only cancel the update thread if the last open instance is closed. This fixes that other applications using the same joystick would stop getting updated values as soon as one application was closed. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41905 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -31,6 +31,7 @@ JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report)
|
|||||||
fButtonCount(0),
|
fButtonCount(0),
|
||||||
fMaxButton(0),
|
fMaxButton(0),
|
||||||
fButtons(NULL),
|
fButtons(NULL),
|
||||||
|
fOpenCount(0),
|
||||||
fUpdateThread(-1)
|
fUpdateThread(-1)
|
||||||
{
|
{
|
||||||
mutex_init(&fUpdateLock, "joystick update lock");
|
mutex_init(&fUpdateLock, "joystick update lock");
|
||||||
@@ -101,7 +102,7 @@ JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report)
|
|||||||
|
|
||||||
fCurrentValues.initialize(fAxisCount, 0, fMaxButton);
|
fCurrentValues.initialize(fAxisCount, 0, fMaxButton);
|
||||||
|
|
||||||
TRACE("joystick device with %lu buttons\n", buttonCount);
|
TRACE("joystick device with %lu buttons\n", fButtonCount);
|
||||||
TRACE("report id: %u\n", report.ID());
|
TRACE("report id: %u\n", report.ID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,6 +191,9 @@ JoystickProtocolHandler::Open(uint32 flags, uint32 *cookie)
|
|||||||
resume_thread(fUpdateThread);
|
resume_thread(fUpdateThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result == B_OK)
|
||||||
|
fOpenCount++;
|
||||||
|
|
||||||
mutex_unlock(&fUpdateLock);
|
mutex_unlock(&fUpdateLock);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
@@ -203,7 +207,8 @@ JoystickProtocolHandler::Close(uint32 *cookie)
|
|||||||
{
|
{
|
||||||
status_t result = mutex_lock(&fUpdateLock);
|
status_t result = mutex_lock(&fUpdateLock);
|
||||||
if (result == B_OK) {
|
if (result == B_OK) {
|
||||||
fUpdateThread = -1;
|
if (--fOpenCount == 0)
|
||||||
|
fUpdateThread = -1;
|
||||||
mutex_unlock(&fUpdateLock);
|
mutex_unlock(&fUpdateLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ private:
|
|||||||
joystick_module_info fJoystickModuleInfo;
|
joystick_module_info fJoystickModuleInfo;
|
||||||
variable_joystick fCurrentValues;
|
variable_joystick fCurrentValues;
|
||||||
|
|
||||||
|
uint32 fOpenCount;
|
||||||
mutex fUpdateLock;
|
mutex fUpdateLock;
|
||||||
thread_id fUpdateThread;
|
thread_id fUpdateThread;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user