Skip to content

Commit

Permalink
dirmonitor: fix high cpu usage, fixes lite-xl#1237 (lite-xl#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgmdev authored Dec 27, 2022
1 parent c29b1c2 commit 5fa7dab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/api/dirmonitor/fsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ int get_changes_dirmonitor(
results = monitor->count;
SDL_UnlockMutex(monitor->lock);

if (monitor->count <= 0)
SDL_Delay(100);

return results;
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/dirmonitor/kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 5fa7dab

Please sign in to comment.