Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement POSIX polling dirmonitor #1926

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jan200101
Copy link
Contributor

Does what it says on the tin
generic fallback for any POSIX.1-2008 compatible system (though by checking preprocessors it can be lowered down by about a decade)

How it works:

  • it keeps a list of file descriptors
    • new file descriptors are either added into empty slots or the list is made bigger
    • removed file descriptors are set to a negative number to makew space
  • if the descriptors modification time has changed the fd is marked as modified
  • if nothing has been modified delay by 100ms to reduce CPU usage

From some minimal testing this seems to work pretty well

src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
@Jan200101 Jan200101 force-pushed the PR/polling-dirmonitor branch from 125fcdc to 319e9d7 Compare November 3, 2024 09:07
}

int translate_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, int count, int (*change_callback)(int, const char*, void*), void* data) {
printf("TRANSLATE %i\n", count);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO remove

@Jan200101
Copy link
Contributor Author

Done some digging around and apparently fstat is bugged on Darwin, would need someone to verify this so the backend will never be selected on MacOS

Copy link
Member

@takase1121 takase1121 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just some minor inconsistencies and the darwin fstat thing. I will try to test, but do you have anything specific that I should look for?

meson_options.txt Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
src/api/dirmonitor/polling.c Outdated Show resolved Hide resolved
Comment on lines +48 to +50
for (size_t i = 0; i < monitor->fd_count; ++i) {
if (monitor->fds[i].fd < 0)
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could fd_count be raced over?
Same with the fds structs.

For example:

  1. We enter get_changes_dirmonitor
  2. Main thread enters add_dirmonitor
  3. add_dirmonitor needs to allocate new space, so it does, but still doesn't switch it out
  4. get_changes_dirmonitor saves fds in a register
  5. add_dirmonitor switches out the spaces, frees the old fds
  6. get_changes_dirmonitor uses the fds from the register, SIGSEGVs.

// Prepare a new list before switching it to prevent race conditions
struct file_info* old_fds = monitor->fds;
struct file_info* new_fds;
new_fds = malloc(sizeof(*new_fds) * (monitor->fd_count + 1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not too sure about just allocating one more space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants