dirmonitor: fix high cpu usage, fixes #1237 (#1271)

This commit is contained in:
Jefferson González 2022-12-27 19:23:39 -04:00 committed by GitHub
parent c29b1c2cb9
commit 5fa7dabd34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -108,6 +108,9 @@ int get_changes_dirmonitor(
results = monitor->count;
SDL_UnlockMutex(monitor->lock);
if (monitor->count <= 0)
SDL_Delay(100);
return results;
}

View File

@ -24,7 +24,7 @@ void deinit_dirmonitor(struct dirmonitor_internal* monitor) {
int get_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, int buffer_size) {
struct timespec ts = { 0, 10 * 1000000 }; // 10 ms
struct timespec ts = { 0, 100 * 1000000 }; // 100 ms
int nev = kevent(monitor->fd, NULL, 0, (struct kevent*)buffer, buffer_size / sizeof(kevent), &ts);
if (nev == -1)
@ -45,7 +45,7 @@ int translate_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buff
int add_dirmonitor(struct dirmonitor_internal* monitor, const char* path) {
int fd = open(path, O_RDONLY);
struct kevent change;
// a timeout of zero should make kevent return immediately
struct timespec ts = { 0, 0 }; // 0 s