Making the hashing buffer reusable instead of malloc every file
This commit is contained in:
47
platform.h
47
platform.h
@@ -21,29 +21,6 @@ typedef struct FileEntry {
|
||||
char owner[128]; // resolved owner name
|
||||
} FileEntry;
|
||||
|
||||
/* File path and metadata */
|
||||
static void normalize_path(char *p) {
|
||||
char *src = p;
|
||||
char *dst = p;
|
||||
int prev_slash = 0;
|
||||
|
||||
while (*src) {
|
||||
char c = *src++;
|
||||
|
||||
if (c == '\\' || c == '/') {
|
||||
if (!prev_slash) {
|
||||
*dst++ = '/';
|
||||
prev_slash = 1;
|
||||
}
|
||||
} else {
|
||||
*dst++ = c;
|
||||
prev_slash = 0;
|
||||
}
|
||||
}
|
||||
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
void platform_get_file_times(const char *path, uint64_t *out_created,
|
||||
uint64_t *out_modified);
|
||||
void platform_get_file_owner(const char *path, char *out_owner,
|
||||
@@ -68,7 +45,7 @@ static double timer_stop(HiResTimer *t) {
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Simple Mutex-Based MPMC Queue (FileEntry*)
|
||||
// Simple lock free MPMC Queue
|
||||
// ============================================================
|
||||
|
||||
typedef struct {
|
||||
@@ -127,25 +104,3 @@ typedef struct DirQueue {
|
||||
pthread_cond_t cond;
|
||||
#endif
|
||||
} DirQueue;
|
||||
|
||||
/* Hashing */
|
||||
typedef struct Job {
|
||||
FileEntry *file;
|
||||
struct Job *next;
|
||||
} Job;
|
||||
|
||||
typedef struct {
|
||||
Job *head;
|
||||
Job *tail;
|
||||
CRITICAL_SECTION cs;
|
||||
CONDITION_VARIABLE cv;
|
||||
atomic_size_t count; // queued jobs
|
||||
int stop;
|
||||
} JobQueue;
|
||||
|
||||
typedef struct {
|
||||
JobQueue *queue;
|
||||
atomic_size_t *done_counter;
|
||||
size_t total_jobs;
|
||||
atomic_int *live_workers;
|
||||
} WorkerArg;
|
||||
|
||||
Reference in New Issue
Block a user