Prevent input_server from hogging the CPU when input devices fail.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14476 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen
2005-10-23 00:28:14 +00:00
parent a21a8b1324
commit 106d748c45
5 changed files with 22 additions and 17 deletions
@@ -618,10 +618,15 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
memset(states, 0, sizeof(states)); memset(states, 0, sizeof(states));
while (dev->active) {
LOG("%s\n", __PRETTY_FUNCTION__); LOG("%s\n", __PRETTY_FUNCTION__);
if (ioctl(dev->fd, kGetNextKey, &buffer) == B_OK) { while (dev->active) {
if (ioctl(dev->fd, kGetNextKey, &buffer) != B_OK) {
snooze(10000); // this is a realtime thread, and something is wrong...
continue;
}
uint32 keycode = 0; uint32 keycode = 0;
bool is_keydown = false; bool is_keydown = false;
bigtime_t timestamp = 0; bigtime_t timestamp = 0;
@@ -769,10 +774,6 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
activeDeadKey = newDeadKey; activeDeadKey = newDeadKey;
} }
lastKeyCode = keycode; lastKeyCode = keycode;
} else {
LOG("kGetNextKey error 2\n");
snooze(100000);
}
} }
return 0; return 0;
@@ -339,8 +339,10 @@ MouseInputDevice::DeviceWatcher(void *arg)
BMessage *message = NULL; BMessage *message = NULL;
while (dev->active) { while (dev->active) {
memset(&movements, 0, sizeof(movements)); memset(&movements, 0, sizeof(movements));
if (ioctl(dev->fd, MS_READ, &movements) < B_OK) if (ioctl(dev->fd, MS_READ, &movements) != B_OK) {
snooze(10000); // this is a realtime thread, and something is wrong...
continue; continue;
}
uint32 buttons = buttons_state ^ movements.buttons; uint32 buttons = buttons_state ^ movements.buttons;
@@ -251,9 +251,10 @@ MouseInputDevice::DeviceWatcher(void* arg)
while (dev->active) while (dev->active)
{ {
memset(&movements, 0, sizeof(movements)); memset(&movements, 0, sizeof(movements));
if (dev->sm->GetMouseEvent(&movements) != B_OK) {
if (dev->sm->GetMouseEvent(&movements) < B_OK) snooze(10000); // this is a realtime thread, and something is wrong...
continue; continue;
}
/* /*
LOG("%s: buttons: 0x%lx, x: %ld, y: %ld, clicks:%ld, wheel_x:%ld, \ LOG("%s: buttons: 0x%lx, x: %ld, y: %ld, clicks:%ld, wheel_x:%ld, \
wheel_y:%ld\n", dev->device_ref.name, movements.buttons, wheel_y:%ld\n", dev->device_ref.name, movements.buttons,
@@ -306,11 +306,8 @@ SerialMouse::GetMouseEvent(mouse_movement* mm)
if (GetPacket(data) != B_OK) if (GetPacket(data) != B_OK)
return B_ERROR; // not enough, or out-of-sync, data. return B_ERROR; // not enough, or out-of-sync, data.
if (PacketToMM(data, mm) != B_OK) { if (PacketToMM(data, mm) != B_OK)
// Something went wrong, clean up. return B_ERROR; // something went wrong
memset(mm, 0, sizeof(mouse_movement));
return B_ERROR;
}
#ifdef DEBUG_SERIAL_MOUSE #ifdef DEBUG_SERIAL_MOUSE
DumpData(mm); DumpData(mm);
@@ -344,8 +341,10 @@ SerialMouse::GetPacket(char data[])
// TODO: Shall we block here instead of leaving after a timeout? // TODO: Shall we block here instead of leaving after a timeout?
// Yes, if we get called it's because there IS a mouse out there. // Yes, if we get called it's because there IS a mouse out there.
if (fSerialPort->Read(&c, 1) != 1) if (fSerialPort->Read(&c, 1) != 1) {
snooze(5000); // this is a realtime thread, and something is wrong...
break; break;
}
if (bytes_read == 0) { if (bytes_read == 0) {
if ((c & mp[fMouseID].sync[0]) != mp[fMouseID].sync[1]) { if ((c & mp[fMouseID].sync[0]) != mp[fMouseID].sync[1]) {
@@ -322,8 +322,10 @@ TabletInputDevice::DeviceWatcher(void *arg)
BMessage *message; BMessage *message;
while (dev->active) { while (dev->active) {
memset(&movements, 0, sizeof(movements)); memset(&movements, 0, sizeof(movements));
if (ioctl(dev->fd, MS_READ, &movements) < B_OK) if (ioctl(dev->fd, MS_READ, &movements) != B_OK) {
snooze(10000); // this is a realtime thread, and something is wrong...
continue; continue;
}
uint32 buttons = buttons_state ^ movements.buttons; uint32 buttons = buttons_state ^ movements.buttons;