From: Čestmír Kalina Date: Fri, 21 Oct 2022 17:49:21 +0000 (+0200) Subject: crypto: thread: remove ossl_crypto_thread_native_terminate X-Git-Tag: openssl-3.2.0-alpha1~1849 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4f32754f79d697e3af78d821296fd02fbba6e186;p=thirdparty%2Fopenssl.git crypto: thread: remove ossl_crypto_thread_native_terminate Signed-off-by: Čestmír Kalina Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/19473) --- diff --git a/crypto/thread/arch.c b/crypto/thread/arch.c index 72fddf5f84d..3dddcb10a83 100644 --- a/crypto/thread/arch.c +++ b/crypto/thread/arch.c @@ -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); diff --git a/crypto/thread/arch/thread_none.c b/crypto/thread/arch/thread_none.c index 1da736a7fb6..431a9b6a352 100644 --- a/crypto/thread/arch/thread_none.c +++ b/crypto/thread/arch/thread_none.c @@ -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; diff --git a/crypto/thread/arch/thread_posix.c b/crypto/thread/arch/thread_posix.c index 0504ac9f81f..b737a5e7886 100644 --- a/crypto/thread/arch/thread_posix.c +++ b/crypto/thread/arch/thread_posix.c @@ -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); diff --git a/crypto/thread/arch/thread_win.c b/crypto/thread/arch/thread_win.c index 7b63712d5b4..b4c05009361 100644 --- a/crypto/thread/arch/thread_win.c +++ b/crypto/thread/arch/thread_win.c @@ -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); diff --git a/include/internal/thread_arch.h b/include/internal/thread_arch.h index 142e77b7683..9afdf55c767 100644 --- a/include/internal/thread_arch.h +++ b/include/internal/thread_arch.h @@ -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); diff --git a/test/threadstest.c b/test/threadstest.c index cd1277082cc..e7b293f0a3a 100644 --- a/test/threadstest.c +++ b/test/threadstest.c @@ -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; }