thread safety for debug info table

This commit is contained in:
simon987 2021-06-14 15:04:08 -04:00
parent 3da2c8cae3
commit dfb8c67490
3 changed files with 5 additions and 1 deletions

View File

@ -41,6 +41,7 @@ typedef struct {
int fast; int fast;
GHashTable *dbg_current_files; GHashTable *dbg_current_files;
pthread_mutex_t dbg_current_files_mu;
scan_arc_ctx_t arc_ctx; scan_arc_ctx_t arc_ctx;
scan_comic_ctx_t comic_ctx; scan_comic_ctx_t comic_ctx;

View File

@ -168,7 +168,8 @@ void initialize_scan_context(scan_args_t *args) {
ScanCtx.arc_ctx.passphrase[0] = 0; ScanCtx.arc_ctx.passphrase[0] = 0;
} }
ScanCtx.dbg_current_files = g_hash_table_new(g_int64_hash, g_int64_equal); 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);
// Comic // Comic
ScanCtx.comic_ctx.log = _log; ScanCtx.comic_ctx.log = _log;

View File

@ -43,7 +43,9 @@ void fs_reset(struct vfile *f) {
void set_dbg_current_file(parse_job_t *job) { void set_dbg_current_file(parse_job_t *job) {
unsigned long long pid = (unsigned long long) pthread_self(); unsigned long long pid = (unsigned long long) pthread_self();
pthread_mutex_lock(&ScanCtx.dbg_current_files_mu);
g_hash_table_replace(ScanCtx.dbg_current_files, GINT_TO_POINTER(pid), job); g_hash_table_replace(ScanCtx.dbg_current_files, GINT_TO_POINTER(pid), job);
pthread_mutex_unlock(&ScanCtx.dbg_current_files_mu);
} }
void parse(void *arg) { void parse(void *arg) {