diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c index 667bb06a145df896ba61499e0cd66570fbfec1d4..dcd91c1e1d0722c764a25ebc88ff781d3df5db01 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)