Rewriting hash_worker() to export file_hashes.txt
This commit is contained in:
@@ -17,3 +17,5 @@ Add sleep() and SwitchToThread() to limit spinning
|
||||
v3.3: Fix bug slots used before initialization,compare and swap is protecting updating committed, but it is not protecting the memory initialization. Adding atomic_flag commit_lock to protect against that
|
||||
Fix bug multiple threads committing at the same time, fixed by using atomic_flag commit_lock and re-checking committed after acquiring the lock
|
||||
Reorder helper functions
|
||||
|
||||
v3.4: Rewriting hash_worker() to export file_hashes.txt
|
||||
|
||||
BIN
binaries/file_hasher_v3.4.exe
Normal file
BIN
binaries/file_hasher_v3.4.exe
Normal file
Binary file not shown.
@@ -411,16 +411,38 @@ static void xxh3_hash_file_stream(const char *path, char *out_hex) {
|
||||
static DWORD WINAPI hash_worker(LPVOID arg) {
|
||||
MPMCQueue *q = (MPMCQueue *)arg;
|
||||
|
||||
static CRITICAL_SECTION append_cs;
|
||||
static LONG init = 0;
|
||||
|
||||
if (InterlockedCompareExchange(&init, 1, 0) == 0) {
|
||||
InitializeCriticalSection(&append_cs);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
|
||||
FileEntry *fe = mpmc_pop(q);
|
||||
|
||||
if (!fe)
|
||||
break; // poison pill
|
||||
break;
|
||||
|
||||
char hash[HASH_STRLEN];
|
||||
xxh3_hash_file_stream(fe->path, hash);
|
||||
|
||||
char created[32], modified[32];
|
||||
format_time(fe->created_time, created, sizeof(created));
|
||||
format_time(fe->modified_time, modified, sizeof(modified));
|
||||
|
||||
double size_kib = (double)fe->size_bytes / 1024.0;
|
||||
|
||||
EnterCriticalSection(&append_cs);
|
||||
|
||||
FILE *hf = fopen(FILE_HASHES_TXT, "a");
|
||||
if (hf) {
|
||||
fprintf(hf, "%s\t%s\t%.2f\t%s\t%s\t%s\n", hash, fe->path, size_kib,
|
||||
created, modified, fe->owner);
|
||||
fclose(hf);
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&append_cs);
|
||||
|
||||
atomic_fetch_add(&g_files_hashed, 1);
|
||||
|
||||
free(fe->path);
|
||||
|
||||
Reference in New Issue
Block a user