Updating the LF MPMC queue and replacing DirQueue with it
Making the MPMC queue support when producers are consumers at the same time by adding a variable work, mpmc_push_work() that increments work and mpmc_task_done() that decrements work, and if work = 0 calls mpmc_producers_finished() that pushes poinsons to wake up sleeping threads and make them return NULL Replacing DirQueue, a queue growable with realloc with the MPMC queue
This commit is contained in:
44
platform.h
44
platform.h
@@ -6,6 +6,14 @@
|
||||
#include "lf_mpmc.h"
|
||||
|
||||
#include "arena.c"
|
||||
|
||||
#define XXH_VECTOR \
|
||||
XXH_AVX2 // not recommanded to compile with gcc see xxhash.h line 4082
|
||||
// Must compile with /arch:AVX2 in clang-cl or -mavx2 in clang/gcc
|
||||
#define XXH_INLINE_ALL
|
||||
#include "xxhash.c"
|
||||
#include "xxhash.h"
|
||||
|
||||
// ----------------------------- Config -------------------------------------
|
||||
#define FILE_HASHES_TXT "file_hashes.txt"
|
||||
#define HASH_STRLEN 33 // 128-bit hex (32 chars) + null
|
||||
@@ -45,43 +53,19 @@ static double timer_stop(HiResTimer *t) {
|
||||
(double)g_qpc_freq.QuadPart;
|
||||
}
|
||||
|
||||
/* Scan folders */
|
||||
|
||||
typedef struct DirQueue DirQueue;
|
||||
|
||||
typedef struct DirQueue {
|
||||
char **items;
|
||||
size_t count;
|
||||
size_t cap;
|
||||
size_t active;
|
||||
|
||||
int stop;
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
CRITICAL_SECTION cs;
|
||||
CONDITION_VARIABLE cv;
|
||||
#else
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
#endif
|
||||
} DirQueue;
|
||||
|
||||
// MPMC Queue
|
||||
|
||||
static MPMCQueue g_dir_queue;
|
||||
static MPMCQueue g_file_queue;
|
||||
// Workers context
|
||||
|
||||
typedef struct {
|
||||
DirQueue *dir_queue;
|
||||
u8 num_threads;
|
||||
|
||||
mem_arena *path_arena;
|
||||
mem_arena *meta_arena;
|
||||
|
||||
MPMCQueue *dir_queue;
|
||||
MPMCQueue *file_queue;
|
||||
} ScannerContext;
|
||||
|
||||
typedef struct {
|
||||
mem_arena *arena;
|
||||
MPMCQueue *file_queue;
|
||||
} WorkerContext;
|
||||
|
||||
// void scan_folder_windows_parallel(const char *base, ScannerContext *ctx);
|
||||
// void scan_folder_posix_parallel(const char *base, ScannerContext *ctx);
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user