summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2014-05-20 12:05:50 +0400
committerDmitry Kozlov <xeb@mail.ru>2014-07-11 14:58:42 +0400
commit111e1beef442d0fa8ee9ff45db53999684a7f31a (patch)
treefe9276c162caeb99ee253499a07ad5672f3ade99
parentf7b2b5c9c05831e6f5ba4af1d03524980aee1f52 (diff)
downloadaccel-ppp-111e1beef442d0fa8ee9ff45db53999684a7f31a.tar.gz
accel-ppp-111e1beef442d0fa8ee9ff45db53999684a7f31a.zip
triton: fix possible race
-rw-r--r--accel-pppd/triton/triton.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c
index 667bb06a..dcd91c1e 100644
--- a/accel-pppd/triton/triton.c
+++ b/accel-pppd/triton/triton.c
@@ -148,24 +148,23 @@ static void* triton_thread(struct _triton_thread_t *thread)
spin_unlock(&threads_lock);
}
-cont:
log_debug2("thread %p: ctx=%p %p\n", thread, thread->ctx, thread->ctx ? thread->ctx->thread : NULL);
this_ctx = thread->ctx->ud;
if (thread->ctx->ud->before_switch)
thread->ctx->ud->before_switch(thread->ctx->ud, thread->ctx->bf_arg);
+cont:
log_debug2("thread %p: switch to %p\n", thread, thread->ctx);
ctx_thread(thread->ctx);
log_debug2("thread %p: switch from %p %p\n", thread, thread->ctx, thread->ctx->thread);
- spin_lock(&thread->ctx->lock);
+ spin_lock(&threads_lock);
if (thread->ctx->pending) {
- spin_unlock(&thread->ctx->lock);
+ spin_unlock(&threads_lock);
goto cont;
}
thread->ctx->thread = NULL;
-
- spin_unlock(&thread->ctx->lock);
+ spin_unlock(&threads_lock);
if (thread->ctx->need_free) {
log_debug2("- context %p removed\n", thread->ctx);
@@ -269,11 +268,13 @@ struct _triton_thread_t *create_thread()
int triton_queue_ctx(struct _triton_context_t *ctx)
{
+ spin_lock(&threads_lock);
ctx->pending = 1;
- if (ctx->thread || ctx->queued || ctx->init)
+ if (ctx->thread || ctx->queued || ctx->init) {
+ spin_unlock(&threads_lock);
return 0;
+ }
- spin_lock(&threads_lock);
if (list_empty(&sleep_threads) || need_config_reload || triton_stat.thread_active > thread_count ||
(ctx->priority == 0 && triton_stat.thread_count > thread_count_max)) {
if (ctx->priority)