From ee9a8fa514a3d5baaf08ce50a778a31b8ca685e7 Mon Sep 17 00:00:00 2001 From: simon987 Date: Wed, 29 Dec 2021 19:18:10 -0500 Subject: [PATCH] Add thread lock for incremental_mark_file_for_copy() --- src/ctx.h | 1 + src/main.c | 1 + src/parsing/parse.c | 2 ++ src/util.h | 3 +++ 4 files changed, 7 insertions(+) diff --git a/src/ctx.h b/src/ctx.h index a1788e1..1e47b08 100644 --- a/src/ctx.h +++ b/src/ctx.h @@ -41,6 +41,7 @@ typedef struct { GHashTable *original_table; GHashTable *copy_table; + pthread_mutex_t copy_table_mu; pcre *exclude; pcre_extra *exclude_extra; diff --git a/src/main.c b/src/main.c index f7535ca..021cb38 100644 --- a/src/main.c +++ b/src/main.c @@ -170,6 +170,7 @@ void initialize_scan_context(scan_args_t *args) { ScanCtx.dbg_current_files = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, NULL); pthread_mutex_init(&ScanCtx.dbg_current_files_mu, NULL); pthread_mutex_init(&ScanCtx.dbg_file_counts_mu, NULL); + pthread_mutex_init(&ScanCtx.copy_table_mu, NULL); ScanCtx.calculate_checksums = args->calculate_checksums; diff --git a/src/parsing/parse.c b/src/parsing/parse.c index f266f00..bec4b21 100644 --- a/src/parsing/parse.c +++ b/src/parsing/parse.c @@ -79,7 +79,9 @@ void parse(void *arg) { int inc_ts = incremental_get(ScanCtx.original_table, doc->path_md5); if (inc_ts != 0 && inc_ts == job->vfile.info.st_mtim.tv_sec) { + pthread_mutex_lock(&ScanCtx.copy_table_mu); incremental_mark_file_for_copy(ScanCtx.copy_table, doc->path_md5); + pthread_mutex_unlock(&ScanCtx.copy_table_mu); pthread_mutex_lock(&ScanCtx.dbg_file_counts_mu); ScanCtx.dbg_skipped_files_count += 1; diff --git a/src/util.h b/src/util.h index 3ff3abf..d3d71d0 100644 --- a/src/util.h +++ b/src/util.h @@ -133,6 +133,9 @@ static int incremental_get_str(GHashTable *table, const char *path_md5) { } } +/** + * Not thread safe! + */ __always_inline static int incremental_mark_file_for_copy(GHashTable *table, const unsigned char path_md5[MD5_DIGEST_LENGTH]) { char *ptr = malloc(MD5_STR_LENGTH);