Potential tpool_wait fix for #416, #397, #399

This commit is contained in:
simon987 2023-09-26 17:58:07 -04:00
parent 33ae585879
commit 660fbf75d8

View File

@ -77,14 +77,14 @@ static void worker_thread_loop(tpool_t *pool) {
job_t *job = database_get_work(ProcData.ipc_db, pool->shm->job_type); job_t *job = database_get_work(ProcData.ipc_db, pool->shm->job_type);
if (job != NULL) { if (job != NULL) {
pthread_mutex_lock(&(pool->shm->data_mutex));
pool->shm->busy_count += 1;
pthread_mutex_unlock(&(pool->shm->data_mutex));
if (pool->shm->stop) { if (pool->shm->stop) {
break; break;
} }
pthread_mutex_lock(&(pool->shm->data_mutex));
pool->shm->busy_count += 1;
pthread_mutex_unlock(&(pool->shm->data_mutex));
if (job->type == JOB_PARSE_JOB) { if (job->type == JOB_PARSE_JOB) {
parse(job->parse_job); parse(job->parse_job);
} else if (job->type == JOB_BULK_LINE) { } else if (job->type == JOB_BULK_LINE) {
@ -200,11 +200,11 @@ static void *tpool_worker(void *arg) {
pool->shm->ipc_ctx.completed_job_count += 1; pool->shm->ipc_ctx.completed_job_count += 1;
pthread_mutex_unlock(&(pool->shm->ipc_ctx.mutex)); pthread_mutex_unlock(&(pool->shm->ipc_ctx.mutex));
if (WIFSIGNALED(status)) {
pthread_mutex_lock(&(pool->shm->data_mutex)); pthread_mutex_lock(&(pool->shm->data_mutex));
pool->shm->busy_count -= 1; pool->shm->busy_count -= 1;
pthread_mutex_unlock(&(pool->shm->data_mutex)); pthread_mutex_unlock(&(pool->shm->data_mutex));
if (WIFSIGNALED(status)) {
int crashed_thread_id = -1; int crashed_thread_id = -1;
for (int i = 0; i < MAX_THREADS; i++) { for (int i = 0; i < MAX_THREADS; i++) {
if (pool->shm->thread_id_to_pid_mapping[i] == pid) { if (pool->shm->thread_id_to_pid_mapping[i] == pid) {
@ -265,7 +265,7 @@ void tpool_wait(tpool_t *pool) {
if (pool->shm->ipc_ctx.job_count > 0) { if (pool->shm->ipc_ctx.job_count > 0) {
pthread_cond_wait(&(pool->shm->done_working_cond), &pool->shm->mutex); pthread_cond_wait(&(pool->shm->done_working_cond), &pool->shm->mutex);
} else { } else {
if (pool->shm->ipc_ctx.job_count == 0 && pool->shm->busy_count == 0) { if (pool->shm->ipc_ctx.job_count == 0 && pool->shm->busy_count <= 0) {
pool->shm->stop = TRUE; pool->shm->stop = TRUE;
break; break;
} }