Use correct function to wait for condvar

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20348)
This commit is contained in:
Hugo Landau 2023-03-27 16:03:32 +01:00
parent 652fbb62a3
commit 712360631f
2 changed files with 7 additions and 8 deletions

View File

@ -78,13 +78,12 @@ pass:
CRYPTO_THREAD_SET_STATE(thread, CRYPTO_THREAD_JOINED);
/*
* Broadcast join completion. It is important to broadcast even if
* we haven't performed an actual join. Multiple threads could be
* awaiting the CRYPTO_THREAD_JOIN_AWAIT -> CRYPTO_THREAD_JOINED
* transition, but broadcast on actual join would wake only one.
* Broadcasing here will always wake one.
* Signal join completion. It is important to signal even if we haven't
* performed an actual join. Multiple threads could be awaiting the
* CRYPTO_THREAD_JOIN_AWAIT -> CRYPTO_THREAD_JOINED transition, but signal
* on actual join would wake only one. Signalling here will always wake one.
*/
ossl_crypto_condvar_broadcast(thread->condvar);
ossl_crypto_condvar_signal(thread->condvar);
ossl_crypto_mutex_unlock(thread->statelock);
if (retval != NULL)
@ -98,7 +97,7 @@ fail:
/* Have another thread that's awaiting join retry to avoid that
* thread deadlock. */
CRYPTO_THREAD_UNSET_STATE(thread, CRYPTO_THREAD_JOIN_AWAIT);
ossl_crypto_condvar_broadcast(thread->condvar);
ossl_crypto_condvar_signal(thread->condvar);
ossl_crypto_mutex_unlock(thread->statelock);
return 0;

View File

@ -87,7 +87,7 @@ int ossl_crypto_thread_join(void *vhandle, CRYPTO_THREAD_RETVAL *retval)
ossl_crypto_mutex_lock(tdata->lock);
tdata->active_threads--;
ossl_crypto_condvar_broadcast(tdata->cond_finished);
ossl_crypto_condvar_signal(tdata->cond_finished);
ossl_crypto_mutex_unlock(tdata->lock);
return 1;
}