mirror of
https://github.com/termux/termux-packages.git
synced 2024-11-23 14:56:16 +00:00
bf556291eb
to avoid race condition.
47 lines
1.2 KiB
Diff
47 lines
1.2 KiB
Diff
--- a/lib/fuse_loop_mt.c
|
|
+++ b/lib/fuse_loop_mt.c
|
|
@@ -19,6 +19,7 @@
|
|
#include <semaphore.h>
|
|
#include <errno.h>
|
|
#include <sys/time.h>
|
|
+#include <stdatomic.h>
|
|
|
|
/* Environment var controlling the thread stack size */
|
|
#define ENVNAME_THREAD_STACK "FUSE_THREAD_STACK"
|
|
@@ -30,6 +31,7 @@ struct fuse_worker {
|
|
size_t bufsize;
|
|
char *buf;
|
|
struct fuse_mt *mt;
|
|
+ atomic_flag cancel;
|
|
};
|
|
|
|
struct fuse_mt {
|
|
@@ -77,9 +79,8 @@ static void *fuse_do_work(void *data)
|
|
};
|
|
int res;
|
|
|
|
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
|
+ if (!atomic_flag_test_and_set(&w->cancel)) pthread_exit(NULL);
|
|
res = fuse_session_receive_buf(mt->se, &fbuf, &ch);
|
|
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
|
if (res == -EINTR)
|
|
continue;
|
|
if (res <= 0) {
|
|
@@ -193,6 +194,7 @@ static int fuse_loop_start_thread(struct
|
|
return -1;
|
|
}
|
|
|
|
+ atomic_flag_test_and_set(&w->cancel);
|
|
res = fuse_start_thread(&w->thread_id, fuse_do_work, w);
|
|
if (res == -1) {
|
|
free(w->buf);
|
|
@@ -243,7 +245,7 @@ int fuse_session_loop_mt(struct fuse_ses
|
|
|
|
pthread_mutex_lock(&mt.lock);
|
|
for (w = mt.main.next; w != &mt.main; w = w->next)
|
|
- pthread_cancel(w->thread_id);
|
|
+ atomic_flag_clear(&w->cancel);
|
|
mt.exit = 1;
|
|
pthread_mutex_unlock(&mt.lock);
|
|
|