Skip to content

Commit

Permalink
Add flags for finalized job threads
Browse files Browse the repository at this point in the history
Report non-finalized threads in logs
  • Loading branch information
jenshannoschwalm committed Dec 14, 2024
1 parent 3f8793b commit 0bde20e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/control/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ void dt_control_shutdown(dt_control_t *control)
dt_print(DT_DEBUG_CONTROL, "[dt_control_shutdown] gphoto thread joined");
#endif

// report not-finalized threads
if(!control->kicker_finalized)
dt_print(DT_DEBUG_CONTROL, "kicker thread not finalized");
for(int k = 0; k < control->num_threads-1; k++)
if(!control->finalized[k])
dt_print(DT_DEBUG_CONTROL, "num thread %d not finalized", k);
for(int k = 0; k < DT_CTL_WORKER_RESERVED; k++)
if(!control->finalized_res[k])
dt_print(DT_DEBUG_CONTROL, "reserved thread %d not finalized", k);

/* wait for kick_on_workers_thread */
err = pthread_join(control->kick_on_workers_thread, NULL);
dt_print(DT_DEBUG_CONTROL, "[dt_control_shutdown] joined kicker%s", err ? ", error" : "");
Expand Down
3 changes: 3 additions & 0 deletions src/control/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ typedef struct dt_control_t
pthread_cond_t cond;
int32_t num_threads;
pthread_t *thread, kick_on_workers_thread, update_gphoto_thread;
uint8_t *finalized;
uint8_t kicker_finalized;
dt_job_t **job;

GList *queues[DT_JOB_QUEUE_MAX];
Expand All @@ -202,6 +204,7 @@ typedef struct dt_control_t
dt_pthread_mutex_t res_mutex;
dt_job_t *job_res[DT_CTL_WORKER_RESERVED];
uint8_t new_res[DT_CTL_WORKER_RESERVED];
uint8_t finalized_res[DT_CTL_WORKER_RESERVED];
pthread_t thread_res[DT_CTL_WORKER_RESERVED];

struct
Expand Down
10 changes: 9 additions & 1 deletion src/control/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ static void *_control_work_res(void *ptr)
pthread_setcancelstate(old, &tmp);
}
}
control->finalized_res[threadid] = 1;
return NULL;
}

Expand All @@ -539,6 +540,7 @@ static void *_control_worker_kicker(void *ptr)
pthread_cond_broadcast(&control->cond);
dt_pthread_mutex_unlock(&control->cond_mutex);
}
control->kicker_finalized = 1;
return NULL;
}

Expand All @@ -565,6 +567,7 @@ static void *_control_work(void *ptr)
dt_pthread_mutex_unlock(&control->cond_mutex);
}
}
control->finalized[threadid] = 1;
return NULL;
}

Expand Down Expand Up @@ -604,7 +607,8 @@ void dt_control_jobs_init(dt_control_t *control)
control->num_threads = dt_worker_threads();
control->thread = (pthread_t *)calloc(control->num_threads, sizeof(pthread_t));
control->job = (dt_job_t **)calloc(control->num_threads, sizeof(dt_job_t *));

control->finalized = (uint8_t*)calloc(control->num_threads, sizeof(uint8_t));
control->kicker_finalized = 0;
g_atomic_int_set(&control->running, DT_CONTROL_STATE_RUNNING);

int err = 0; // collected errors while creating all threads
Expand All @@ -615,6 +619,7 @@ void dt_control_jobs_init(dt_control_t *control)
params->self = control;
params->threadid = k;
err |= dt_pthread_create(&control->thread[k], _control_work, params);
control->finalized[k] = 0;
}

/* create queue kicker thread */
Expand All @@ -628,6 +633,7 @@ void dt_control_jobs_init(dt_control_t *control)
params->self = control;
params->threadid = k;
err |= dt_pthread_create(&control->thread_res[k], _control_work_res, params);
control->finalized_res[k] = 0;
}
/* create thread taking care of connecting gphoto2 devices */
#ifdef HAVE_GPHOTO2
Expand All @@ -643,6 +649,8 @@ void dt_control_jobs_cleanup(dt_control_t *control)
control->job = NULL;
free(control->thread);
control->thread = NULL;
free(control->finalized);
control->finalized = NULL;
}

int dt_control_jobs_pending(dt_control_t *control)
Expand Down

0 comments on commit 0bde20e

Please sign in to comment.