mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-08 08:52:15 +02:00
Fix monitor response time (#2635)
* Sleep only when there are no upcoming events. * Add constraint to prevent starvation.
This commit is contained in:
parent
0404ee2e37
commit
333ddbefea
|
@ -488,7 +488,9 @@ final class Monitor {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
bool hasNotification = false;
|
bool hasNotification = false;
|
||||||
while (true) {
|
int sleep_counter = 0;
|
||||||
|
// Batch events up to 5 seconds
|
||||||
|
while (sleep_counter < 5) {
|
||||||
int ret = poll(&fds, 1, 0);
|
int ret = poll(&fds, 1, 0);
|
||||||
if (ret == -1) throw new MonitorException("poll failed");
|
if (ret == -1) throw new MonitorException("poll failed");
|
||||||
else if (ret == 0) break; // no events available
|
else if (ret == 0) break; // no events available
|
||||||
|
@ -621,7 +623,12 @@ final class Monitor {
|
||||||
skip:
|
skip:
|
||||||
i += inotify_event.sizeof + event.len;
|
i += inotify_event.sizeof + event.len;
|
||||||
}
|
}
|
||||||
Thread.sleep(dur!"seconds"(1));
|
|
||||||
|
// Sleep for one second to prevent missing fast-changing events.
|
||||||
|
if (poll(&fds, 1, 0) == 0) {
|
||||||
|
sleep_counter += 1;
|
||||||
|
Thread.sleep(dur!"seconds"(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!hasNotification) break;
|
if (!hasNotification) break;
|
||||||
processChanges();
|
processChanges();
|
||||||
|
|
Loading…
Reference in a new issue