QUIC Thread Assisted Mode: Refactor locking to be infallible
authorHugo Landau <hlandau@openssl.org>
Thu, 23 Feb 2023 05:06:59 +0000 (05:06 +0000)
committerHugo Landau <hlandau@openssl.org>
Thu, 30 Mar 2023 10:14:16 +0000 (11:14 +0100)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20348)

crypto/thread/arch/thread_win.c
ssl/quic/quic_impl.c
ssl/quic/quic_reactor.c

index cfda50f0beda4058990ead5c06a9c197f05b4679..f647c68c0a29c120c807c1943c3b219b2366c8bb 100644 (file)
@@ -197,15 +197,12 @@ void ossl_crypto_condvar_wait_timeout(CRYPTO_CONDVAR *cv, CRYPTO_MUTEX *mutex,
 {
     DWORD timeout;
 
-    fprintf(stderr, "# wt\n"); fflush(stderr);
     if (!determine_timeout(deadline, &timeout))
         timeout = 1;
 
     ossl_crypto_mutex_unlock(mutex);
     WaitForSingleObject((HANDLE)cv, timeout);
-    fprintf(stderr, "# wtd\n"); fflush(stderr);
     ossl_crypto_mutex_lock(mutex);
-    fprintf(stderr, "# wtd2\n"); fflush(stderr);
 }
 
 void ossl_crypto_condvar_broadcast(CRYPTO_CONDVAR *cv)
index 2c7c247260cf4e89672b5ab7bad8fec83a6e3aed..b293bf7bd93d629e4dfba8d4d4ad4c2e35e11953 100644 (file)
@@ -110,10 +110,9 @@ static ossl_inline int expect_quic_conn(const QUIC_CONNECTION *qc)
  *
  * Precondition: Channel mutex is not held (unchecked)
  */
-static int quic_lock(QUIC_CONNECTION *qc)
+static void quic_lock(QUIC_CONNECTION *qc)
 {
     ossl_crypto_mutex_lock(qc->mutex);
-    return 1;
 }
 
 /* Precondition: Channel mutex is held (unchecked) */
@@ -188,7 +187,7 @@ void ossl_quic_free(SSL *s)
     if (!expect_quic_conn(qc))
         return;
 
-    quic_lock(qc); /* best effort */
+    quic_lock(qc);
 
     if (qc->is_thread_assisted && qc->started) {
         ossl_quic_thread_assist_wait_stopped(&qc->thread_assist);
@@ -463,8 +462,7 @@ static int blocking_mode(const QUIC_CONNECTION *qc)
 QUIC_TAKES_LOCK
 int ossl_quic_tick(QUIC_CONNECTION *qc)
 {
-    if (!quic_lock(qc))
-        return 0;
+    quic_lock(qc);
 
     if (qc->ch == NULL) {
         quic_unlock(qc);
@@ -487,8 +485,7 @@ int ossl_quic_get_tick_timeout(QUIC_CONNECTION *qc, struct timeval *tv)
 {
     OSSL_TIME deadline = ossl_time_infinite();
 
-    if (!quic_lock(qc))
-        return 0;
+    quic_lock(qc);
 
     if (qc->ch != NULL)
         deadline
@@ -530,8 +527,7 @@ int ossl_quic_get_net_read_desired(QUIC_CONNECTION *qc)
 {
     int ret;
 
-    if (!quic_lock(qc))
-        return 0;
+    quic_lock(qc);
 
     if (qc->ch == NULL)
         return 0;
@@ -547,8 +543,7 @@ int ossl_quic_get_net_write_desired(QUIC_CONNECTION *qc)
 {
     int ret;
 
-    if (!quic_lock(qc))
-        return 0;
+    quic_lock(qc);
 
     if (qc->ch == NULL)
         return 0;
@@ -587,8 +582,7 @@ int ossl_quic_conn_shutdown(QUIC_CONNECTION *qc, uint64_t flags,
 {
     int ret;
 
-    if (!quic_lock(qc))
-        return -1;
+    quic_lock(qc);
 
     if (!ensure_channel(qc)) {
         quic_unlock(qc);
@@ -826,8 +820,7 @@ int ossl_quic_do_handshake(QUIC_CONNECTION *qc)
 {
     int ret;
 
-    if (!quic_lock(qc))
-        return -1;
+    quic_lock(qc);
 
     ret = quic_do_handshake(qc);
     quic_unlock(qc);
@@ -1142,8 +1135,7 @@ int ossl_quic_write(SSL *s, const void *buf, size_t len, size_t *written)
     if (!expect_quic_conn(qc))
         return 0;
 
-    if (!quic_lock(qc))
-        return 0;
+    quic_lock(qc);
 
     if (qc->ch != NULL && ossl_quic_channel_is_term_any(qc->ch)) {
         ret = QUIC_RAISE_NON_NORMAL_ERROR(qc, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL);
@@ -1279,8 +1271,7 @@ static int quic_read(SSL *s, void *buf, size_t len, size_t *bytes_read, int peek
     if (!expect_quic_conn(qc))
         return 0;
 
-    if (!quic_lock(qc))
-        return 0;
+    quic_lock(qc);
 
     if (qc->ch != NULL && ossl_quic_channel_is_term_any(qc->ch)) {
         ret = QUIC_RAISE_NON_NORMAL_ERROR(qc, SSL_R_PROTOCOL_IS_SHUTDOWN, NULL);
@@ -1366,8 +1357,7 @@ static size_t ossl_quic_pending_int(const QUIC_CONNECTION *qc)
     if (!expect_quic_conn(qc))
         return 0;
 
-    if (!quic_lock((QUIC_CONNECTION *)qc))
-        return 0;
+    quic_lock((QUIC_CONNECTION *)qc);
 
     if (qc->stream0 == NULL || qc->stream0->rstream == NULL)
         /* Cannot raise errors here because we are const, just fail. */
@@ -1402,8 +1392,7 @@ int ossl_quic_conn_stream_conclude(QUIC_CONNECTION *qc)
 {
     QUIC_STREAM *qs = qc->stream0;
 
-    if (!quic_lock(qc))
-        return 0;
+    quic_lock(qc);
 
     if (qs == NULL || qs->sstream == NULL) {
         quic_unlock(qc);
index d9826e7e940cb190375516bb7103fa9b02f66619..b6490f2459b7a66c82dc561a5accb07452e551d6 100644 (file)
@@ -8,6 +8,7 @@
  */
 #include "internal/quic_reactor.h"
 #include "internal/common.h"
+#include "internal/thread_arch.h"
 
 /*
  * Core I/O Reactor Framework