]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto: thread: remove ossl_crypto_thread_native_terminate
authorČestmír Kalina <ckalina@redhat.com>
Fri, 21 Oct 2022 17:49:21 +0000 (19:49 +0200)
committerČestmír Kalina <ckalina@redhat.com>
Fri, 21 Oct 2022 17:57:16 +0000 (19:57 +0200)
Signed-off-by: Čestmír Kalina <ckalina@redhat.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19473)

crypto/thread/arch.c
crypto/thread/arch/thread_none.c
crypto/thread/arch/thread_posix.c
crypto/thread/arch/thread_win.c
include/internal/thread_arch.h
test/threadstest.c

index 72fddf5f84d03362a00fdbf850462cbf9b15e8d3..3dddcb10a836df875826bb0cd6444d3623fbd444 100644 (file)
@@ -54,16 +54,10 @@ int ossl_crypto_thread_native_join(CRYPTO_THREAD *thread, CRYPTO_THREAD_RETVAL *
         return 0;
 
     ossl_crypto_mutex_lock(thread->statelock);
-    req_state_mask = CRYPTO_THREAD_TERMINATED | CRYPTO_THREAD_FINISHED \
-                     | CRYPTO_THREAD_JOINED;
+    req_state_mask = CRYPTO_THREAD_FINISHED | CRYPTO_THREAD_JOINED;
     while (!CRYPTO_THREAD_GET_STATE(thread, req_state_mask))
         ossl_crypto_condvar_wait(thread->condvar, thread->statelock);
 
-    if (CRYPTO_THREAD_GET_STATE(thread, CRYPTO_THREAD_TERMINATED)) {
-        ossl_crypto_mutex_unlock(thread->statelock);
-        return 0;
-    }
-
     if (CRYPTO_THREAD_GET_STATE(thread, CRYPTO_THREAD_JOINED))
         goto pass;
 
@@ -121,7 +115,6 @@ int ossl_crypto_thread_native_clean(CRYPTO_THREAD *handle)
 
     req_state_mask = 0;
     req_state_mask |= CRYPTO_THREAD_FINISHED;
-    req_state_mask |= CRYPTO_THREAD_TERMINATED;
     req_state_mask |= CRYPTO_THREAD_JOINED;
 
     ossl_crypto_mutex_lock(handle->statelock);
index 1da736a7fb679b8bbe3b0fdaf5b1dcbbaccff921..431a9b6a352a4f08d59794248fd34c90251720d0 100644 (file)
@@ -21,11 +21,6 @@ int ossl_crypto_thread_native_perform_join(CRYPTO_THREAD *thread, CRYPTO_THREAD_
     return 0;
 }
 
-int ossl_crypto_thread_native_terminate(CRYPTO_THREAD *thread)
-{
-    return 0;
-}
-
 int ossl_crypto_thread_native_exit(void)
 {
     return 0;
index 0504ac9f81ff1de5995b60e430bc4f0eb78c0051..b737a5e78866deaa8662e0bf76e11dad0801a48d 100644 (file)
@@ -85,52 +85,6 @@ int ossl_crypto_thread_native_perform_join(CRYPTO_THREAD *thread, CRYPTO_THREAD_
     return 1;
 }
 
-int ossl_crypto_thread_native_terminate(CRYPTO_THREAD *thread)
-{
-    void *res;
-    uint64_t mask;
-    pthread_t *handle;
-
-    mask = CRYPTO_THREAD_FINISHED;
-    mask |= CRYPTO_THREAD_TERMINATED;
-    mask |= CRYPTO_THREAD_JOINED;
-
-    if (thread == NULL)
-        return 0;
-
-    ossl_crypto_mutex_lock(thread->statelock);
-    if (thread->handle == NULL || CRYPTO_THREAD_GET_STATE(thread, mask))
-        goto terminated;
-    /* Do not fail when there's a join in progress. Do not block. */
-    if (CRYPTO_THREAD_GET_STATE(thread, CRYPTO_THREAD_JOIN_AWAIT))
-        goto fail;
-    ossl_crypto_mutex_unlock(thread->statelock);
-
-    handle = thread->handle;
-    if (pthread_cancel(*handle) != 0) {
-        ossl_crypto_mutex_lock(thread->statelock);
-        goto fail;
-    }
-    if (pthread_join(*handle, &res) != 0)
-        return 0;
-    if (res != PTHREAD_CANCELED)
-        return 0;
-
-    thread->handle = NULL;
-    OPENSSL_free(handle);
-
-    ossl_crypto_mutex_lock(thread->statelock);
-terminated:
-    CRYPTO_THREAD_UNSET_ERROR(thread, CRYPTO_THREAD_TERMINATED);
-    CRYPTO_THREAD_SET_STATE(thread, CRYPTO_THREAD_TERMINATED);
-    ossl_crypto_mutex_unlock(thread->statelock);
-    return 1;
-fail:
-    CRYPTO_THREAD_SET_ERROR(thread, CRYPTO_THREAD_TERMINATED);
-    ossl_crypto_mutex_unlock(thread->statelock);
-    return 0;
-}
-
 int ossl_crypto_thread_native_exit(void)
 {
     pthread_exit(NULL);
index 7b63712d5b4c45789fe26d7ca8a680c5822a80aa..b4c0500936142e5b23597faa2e2ad057a070658e 100644 (file)
@@ -83,49 +83,6 @@ int ossl_crypto_thread_native_perform_join(CRYPTO_THREAD *thread, CRYPTO_THREAD_
     return 1;
 }
 
-int ossl_crypto_thread_native_terminate(CRYPTO_THREAD *thread)
-{
-    uint64_t mask;
-    HANDLE *handle;
-
-    mask = CRYPTO_THREAD_FINISHED;
-    mask |= CRYPTO_THREAD_TERMINATED;
-    mask |= CRYPTO_THREAD_JOINED;
-
-    if (thread == NULL)
-        return 1;
-
-    ossl_crypto_mutex_lock(thread->statelock);
-    if (thread->handle == NULL || CRYPTO_THREAD_GET_STATE(thread, mask))
-        goto terminated;
-    ossl_crypto_mutex_unlock(thread->statelock);
-
-    handle = thread->handle;
-    if (WaitForSingleObject(*handle, 0) != WAIT_OBJECT_0) {
-        if (TerminateThread(*handle, STILL_ACTIVE) == 0) {
-            ossl_crypto_mutex_lock(thread->statelock);
-            CRYPTO_THREAD_SET_ERROR(thread, CRYPTO_THREAD_TERMINATED);
-            ossl_crypto_mutex_unlock(thread->statelock);
-            return 0;
-        }
-    }
-
-    if (CloseHandle(*handle) == 0) {
-        CRYPTO_THREAD_SET_ERROR(thread, CRYPTO_THREAD_TERMINATED);
-        return 0;
-    }
-
-    thread->handle = NULL;
-    OPENSSL_free(handle);
-
-    ossl_crypto_mutex_lock(thread->statelock);
-terminated:
-    CRYPTO_THREAD_UNSET_ERROR(thread, CRYPTO_THREAD_TERMINATED);
-    CRYPTO_THREAD_SET_STATE(thread, CRYPTO_THREAD_TERMINATED);
-    ossl_crypto_mutex_unlock(thread->statelock);
-    return 1;
-}
-
 int ossl_crypto_thread_native_exit(void)
 {
     _endthreadex(0);
index 142e77b76833d4c95f2779e687db0abbbe3cd647..9afdf55c767398edd3c983e329c2e632ef1ac8d7 100644 (file)
@@ -55,7 +55,6 @@ typedef CRYPTO_THREAD_RETVAL (*CRYPTO_THREAD_ROUTINE_CB)(void *,
 # define CRYPTO_THREAD_FINISHED   (1UL << 0)
 # define CRYPTO_THREAD_JOIN_AWAIT (1UL << 1)
 # define CRYPTO_THREAD_JOINED     (1UL << 2)
-# define CRYPTO_THREAD_TERMINATED (1UL << 3)
 
 # define CRYPTO_THREAD_GET_STATE(THREAD, FLAG) ((THREAD)->state & (FLAG))
 # define CRYPTO_THREAD_GET_ERROR(THREAD, FLAG) (((THREAD)->state >> 16) & (FLAG))
@@ -112,7 +111,6 @@ int ossl_crypto_thread_native_join(CRYPTO_THREAD *thread,
                               CRYPTO_THREAD_RETVAL *retval);
 int ossl_crypto_thread_native_perform_join(CRYPTO_THREAD *thread,
                                            CRYPTO_THREAD_RETVAL *retval);
-int ossl_crypto_thread_native_terminate(CRYPTO_THREAD *thread);
 int ossl_crypto_thread_native_exit(void);
 int ossl_crypto_thread_native_is_self(CRYPTO_THREAD *thread);
 int ossl_crypto_thread_native_clean(CRYPTO_THREAD *thread);
index cd1277082cc87c91f45f032d0f55fdd418e56c8f..e7b293f0a3aecfacccc331ad023422401db6f51b 100644 (file)
@@ -784,19 +784,6 @@ static uint32_t test_thread_native_fn(void *data)
     *ldata = *ldata + 1;
     return *ldata - 1;
 }
-
-static uint32_t test_thread_noreturn(void *data)
-{
-    while (1) {
-       OSSL_sleep(1000);
-    }
-
-    /* unreachable */
-    OPENSSL_die("test_thread_noreturn", __FILE__, __LINE__);
-
-    return 0;
-}
-
 /* Tests of native threads */
 
 static int test_thread_native(void)
@@ -805,7 +792,7 @@ static int test_thread_native(void)
     uint32_t local;
     CRYPTO_THREAD *t;
 
-    /* thread spawn, join and termination */
+    /* thread spawn, join */
 
     local = 1;
     t = ossl_crypto_thread_native_start(test_thread_native_fn, &local, 1);
@@ -826,14 +813,6 @@ static int test_thread_native(void)
     if (!TEST_int_eq(retval, 1) || !TEST_int_eq(local, 2))
         return 0;
 
-    if (!TEST_int_eq(ossl_crypto_thread_native_terminate(t), 1))
-        return 0;
-    if (!TEST_int_eq(ossl_crypto_thread_native_terminate(t), 1))
-        return 0;
-
-    if (!TEST_int_eq(ossl_crypto_thread_native_join(t, &retval), 0))
-        return 0;
-
     if (!TEST_int_eq(ossl_crypto_thread_native_clean(t), 1))
         return 0;
     t = NULL;
@@ -841,16 +820,6 @@ static int test_thread_native(void)
     if (!TEST_int_eq(ossl_crypto_thread_native_clean(t), 0))
         return 0;
 
-    /* termination of a long running thread */
-
-    t = ossl_crypto_thread_native_start(test_thread_noreturn, NULL, 1);
-    if (!TEST_ptr(t))
-        return 0;
-    if (!TEST_int_eq(ossl_crypto_thread_native_terminate(t), 1))
-        return 0;
-    if (!TEST_int_eq(ossl_crypto_thread_native_clean(t), 1))
-        return 0;
-
     return 1;
 }