termux-packages/root-packages/libfuse3/poll.c.patch

56 lines
1.4 KiB
Diff

--- a/example/poll.c
+++ b/example/poll.c
@@ -35,6 +35,7 @@
#include <time.h>
#include <pthread.h>
#include <poll.h>
+#include <stdatomic.h>
/*
* fsel_open_mask is used to limit the number of opens to 1 per file.
@@ -220,7 +221,8 @@ static void *fsel_producer(void *data)
const struct timespec interval = { 0, 250000000 };
unsigned idx = 0, nr = 1;
- (void) data;
+ atomic_flag *cancel = (atomic_flag *) data;
+ atomic_flag_clear(cancel);
while (1) {
int i, t;
@@ -257,6 +259,8 @@ static void *fsel_producer(void *data)
pthread_mutex_unlock(&fsel_mutex);
+ if (atomic_flag_test_and_set(cancel)) pthread_exit(NULL);
+ atomic_flag_clear(cancel);
nanosleep(&interval, NULL);
}
@@ -268,6 +272,7 @@ int main(int argc, char *argv[])
pthread_t producer;
pthread_attr_t attr;
int ret;
+ atomic_flag cancel;
errno = pthread_mutex_init(&fsel_mutex, NULL);
if (errno) {
@@ -281,7 +286,7 @@ int main(int argc, char *argv[])
return 1;
}
- errno = pthread_create(&producer, &attr, fsel_producer, NULL);
+ errno = pthread_create(&producer, &attr, fsel_producer, (void *)&cancel);
if (errno) {
perror("pthread_create");
return 1;
@@ -289,7 +294,7 @@ int main(int argc, char *argv[])
ret = fuse_main(argc, argv, &fsel_oper, NULL);
- pthread_cancel(producer);
+ atomic_flag_test_and_set(&cancel);
pthread_join(producer, NULL);
return ret;