summaryrefslogtreecommitdiff
path: root/ssl/quic
diff options
context:
space:
mode:
authorHugo Landau <hlandau@openssl.org>2023-02-21 10:18:59 +0000
committerHugo Landau <hlandau@openssl.org>2023-03-30 11:14:08 +0100
commitffce2946c7f59ad14ffeeef16a82bf7f04e8cd9c (patch)
tree051a4ffc534aea4f40035722d5cea256e7b01cd6 /ssl/quic
parentccd31037713ad1cdfd88c85a169bd18b08579813 (diff)
downloadopenssl-new-ffce2946c7f59ad14ffeeef16a82bf7f04e8cd9c.tar.gz
Switch to using ossl_crypto_mutex from CRYPTO_RWLOCK
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20348)
Diffstat (limited to 'ssl/quic')
-rw-r--r--ssl/quic/quic_impl.c34
-rw-r--r--ssl/quic/quic_thread_assist.c17
2 files changed, 25 insertions, 26 deletions
diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c
index 4286c526b7..b478e7c4f2 100644
--- a/ssl/quic/quic_impl.c
+++ b/ssl/quic/quic_impl.c
@@ -112,14 +112,15 @@ static ossl_inline int expect_quic_conn(const QUIC_CONNECTION *qc)
*/
static int quic_lock(QUIC_CONNECTION *qc)
{
- return CRYPTO_THREAD_write_lock(qc->mutex);
+ ossl_crypto_mutex_lock(qc->mutex);
+ return 1;
}
/* Precondition: Channel mutex is held (unchecked) */
QUIC_NEEDS_LOCK
static void quic_unlock(QUIC_CONNECTION *qc)
{
- CRYPTO_THREAD_unlock(qc->mutex);
+ ossl_crypto_mutex_unlock(qc->mutex);
}
@@ -158,7 +159,7 @@ SSL *ossl_quic_new(SSL_CTX *ctx)
if (qc->tls == NULL || (sc = SSL_CONNECTION_FROM_SSL(qc->tls)) == NULL)
goto err;
- if ((qc->mutex = CRYPTO_THREAD_lock_new()) == NULL)
+ if ((qc->mutex = ossl_crypto_mutex_new()) == NULL)
goto err;
qc->is_thread_assisted
@@ -200,7 +201,7 @@ void ossl_quic_free(SSL *s)
/* Note: SSL_free calls OPENSSL_free(qc) for us */
SSL_free(qc->tls);
- CRYPTO_THREAD_lock_free(qc->mutex);
+ ossl_crypto_mutex_free(&qc->mutex);
}
/* SSL method init */
@@ -681,6 +682,7 @@ static int ensure_channel(QUIC_CONNECTION *qc)
args.propq = qc->ssl.ctx->propq;
args.is_server = 0;
args.tls = qc->tls;
+ args.mutex = qc->mutex;
qc->ch = ossl_quic_channel_new(&args);
if (qc->ch == NULL)
@@ -697,21 +699,23 @@ static int ensure_channel(QUIC_CONNECTION *qc)
QUIC_NEEDS_LOCK
static int ensure_channel_and_start(QUIC_CONNECTION *qc)
{
- if (!ensure_channel(qc))
- return 0;
-
- if (!configure_channel(qc)
- || !ossl_quic_channel_start(qc->ch))
- goto err;
+ if (!qc->started) {
+ if (!ensure_channel(qc))
+ return 0;
- qc->stream0 = ossl_quic_channel_get_stream_by_id(qc->ch, 0);
- if (qc->stream0 == NULL)
- goto err;
+ if (!configure_channel(qc)
+ || !ossl_quic_channel_start(qc->ch))
+ goto err;
- if (qc->is_thread_assisted)
- if (!ossl_quic_thread_assist_init_start(&qc->thread_assist, qc->ch))
+ qc->stream0 = ossl_quic_channel_get_stream_by_id(qc->ch, 0);
+ if (qc->stream0 == NULL)
goto err;
+ if (qc->is_thread_assisted)
+ if (!ossl_quic_thread_assist_init_start(&qc->thread_assist, qc->ch))
+ goto err;
+ }
+
qc->started = 1;
return 1;
diff --git a/ssl/quic/quic_thread_assist.c b/ssl/quic/quic_thread_assist.c
index 4f760ea99c..9d6c4ecda5 100644
--- a/ssl/quic/quic_thread_assist.c
+++ b/ssl/quic/quic_thread_assist.c
@@ -23,8 +23,7 @@ static unsigned int assist_thread_main(void *arg)
CRYPTO_MUTEX *m = ossl_quic_channel_get_mutex(qta->ch);
QUIC_REACTOR *rtor;
- if (!CRYPTO_THREAD_write_lock(m))
- return 0;
+ ossl_crypto_mutex_lock(m);
rtor = ossl_quic_channel_get_reactor(qta->ch);
@@ -52,7 +51,7 @@ static unsigned int assist_thread_main(void *arg)
ossl_quic_reactor_tick(rtor, QUIC_REACTOR_TICK_FLAG_CHANNEL_ONLY);
}
- CRYPTO_THREAD_unlock(m);
+ ossl_crypto_mutex_unlock(m);
return 1;
}
@@ -92,12 +91,10 @@ int ossl_quic_thread_assist_stop_async(QUIC_THREAD_ASSIST *qta)
return 1;
}
-static void ignore_res(int x) {}
-
int ossl_quic_thread_assist_wait_stopped(QUIC_THREAD_ASSIST *qta)
{
CRYPTO_THREAD_RETVAL rv;
- CRYPTO_RWLOCK *m = ossl_quic_channel_get_mutex(qta->ch);
+ CRYPTO_MUTEX *m = ossl_quic_channel_get_mutex(qta->ch);
if (qta->joined)
return 1;
@@ -105,18 +102,16 @@ int ossl_quic_thread_assist_wait_stopped(QUIC_THREAD_ASSIST *qta)
if (!ossl_quic_thread_assist_stop_async(qta))
return 0;
- CRYPTO_THREAD_unlock(m);
+ ossl_crypto_mutex_unlock(m);
if (!ossl_crypto_thread_native_join(qta->t, &rv)) {
- ignore_res(CRYPTO_THREAD_write_lock(m)); /* best effort */
+ ossl_crypto_mutex_lock(m);
return 0;
}
qta->joined = 1;
- if (!CRYPTO_THREAD_write_lock(m))
- return 0;
-
+ ossl_crypto_mutex_lock(m);
return 1;
}