Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the location of the mutex (pool->gctp_lock) so that the pool can be properly protected #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/thread_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ gc_thread_func (void *arg)

if (pool->gctp_shutdown) break;
}
gpr_mu_unlock(&pool->gctp_lock);

pool->gctp_nthreads--;

Expand All @@ -72,6 +71,7 @@ gc_thread_func (void *arg)
* Add this thread to list of dead threads so we can join them
*/
TAILQ_INSERT_TAIL(&pool->gctp_dead_threads, gcthread, gct_threads);
gpr_mu_unlock(&pool->gctp_lock);
}

/*
Expand Down Expand Up @@ -145,7 +145,6 @@ grpc_c_thread_pool_add (grpc_c_thread_pool_t *pool,
callback->gctc_arg = arg;

TAILQ_INSERT_TAIL(&pool->gctp_callbacks_head, callback, gctc_callbacks);
gpr_mu_unlock(&pool->gctp_lock);

/*
* Create a new thread if it is not already created or there are no free
Expand All @@ -155,6 +154,7 @@ grpc_c_thread_pool_add (grpc_c_thread_pool_t *pool,
struct grpc_c_thread_t *gcthread = malloc(sizeof(struct grpc_c_thread_t));
if (gcthread == NULL) {
gpr_log(GPR_ERROR, "Failed to allocate memory to create thread");
gpr_mu_unlock(&pool->gctp_lock);
return 1;
}
pool->gctp_nthreads++;
Expand All @@ -164,6 +164,7 @@ grpc_c_thread_pool_add (grpc_c_thread_pool_t *pool,
if (!gpr_thd_new(&gcthread->gct_thread, gc_thread_func,
(void *)gcthread, &toptions)) {
gpr_log(GPR_ERROR, "Failed to create thread");
gpr_mu_unlock(&pool->gctp_lock);
return 1;
}
} else {
Expand All @@ -174,6 +175,7 @@ grpc_c_thread_pool_add (grpc_c_thread_pool_t *pool,
* Join all finished threads and delete them
*/
gc_delete_threads(pool);
gpr_mu_unlock(&pool->gctp_lock);

return 0;
}
Expand Down