mirror of
https://github.com/termux/termux-packages.git
synced 2024-11-23 14:56:16 +00:00
bf556291eb
to avoid race condition.
48 lines
1.1 KiB
Diff
48 lines
1.1 KiB
Diff
--- a/lib/fuse.c
|
|
+++ b/lib/fuse.c
|
|
@@ -38,6 +38,7 @@
|
|
#include <sys/time.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/file.h>
|
|
+#include <stdatomic.h>
|
|
|
|
#define FUSE_NODE_SLAB 1
|
|
|
|
@@ -153,6 +154,7 @@ struct fuse {
|
|
struct list_head partial_slabs;
|
|
struct list_head full_slabs;
|
|
pthread_t prune_thread;
|
|
+ atomic_flag cancel;
|
|
};
|
|
|
|
struct lock {
|
|
@@ -4640,6 +4642,7 @@ static void *fuse_prune_nodes(void *fuse
|
|
|
|
while(1) {
|
|
sleep_time = fuse_clean_cache(f);
|
|
+ if (!atomic_flag_test_and_set(&f->cancel)) pthread_exit(NULL);
|
|
sleep(sleep_time);
|
|
}
|
|
return NULL;
|
|
@@ -4647,8 +4650,10 @@ static void *fuse_prune_nodes(void *fuse
|
|
|
|
int fuse_start_cleanup_thread(struct fuse *f)
|
|
{
|
|
- if (lru_enabled(f))
|
|
+ if (lru_enabled(f)) {
|
|
+ atomic_flag_test_and_set(&f->cancel);
|
|
return fuse_start_thread(&f->prune_thread, fuse_prune_nodes, f);
|
|
+ }
|
|
|
|
return 0;
|
|
}
|
|
@@ -4657,7 +4662,7 @@ void fuse_stop_cleanup_thread(struct fus
|
|
{
|
|
if (lru_enabled(f)) {
|
|
pthread_mutex_lock(&f->lock);
|
|
- pthread_cancel(f->prune_thread);
|
|
+ atomic_flag_clear(&f->cancel);
|
|
pthread_mutex_unlock(&f->lock);
|
|
pthread_join(f->prune_thread, NULL);
|
|
}
|