mirror of
https://github.com/openssl/openssl.git
synced 2024-11-27 05:21:51 +08:00
4574a7fd8d
Some primitives are designed to be used in a multi-threaded environment, if supported, e.g., Argon2. This patch adds support for preemptive threading and basic synchronization primitives for platforms compliant with POSIX threads or Windows CRT. Native functions are wrapped to provide a common (internal) API. Threading support can be disabled at compile time. If enabled, threading is disabled by default and needs to be explicitly enabled by the user. Thread enablement requires an explicit limit on the number of threads that OpenSSL may spawn (non-negative integer/infinity). The limit may be changed. Signed-off-by: Čestmír Kalina <ckalina@redhat.com> Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/12255)
40 lines
1.3 KiB
C
40 lines
1.3 KiB
C
/*
|
|
* Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
|
|
*
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
* in the file LICENSE in the source distribution or at
|
|
* https://www.openssl.org/source/license.html
|
|
*/
|
|
|
|
#ifndef OPENSSL_INTERNAL_THREAD_H
|
|
# define OPENSSL_INTERNAL_THREAD_H
|
|
# include <openssl/configuration.h>
|
|
# include <internal/thread_arch.h>
|
|
# include <openssl/e_os2.h>
|
|
# include <openssl/types.h>
|
|
# include <internal/cryptlib.h>
|
|
# include "crypto/context.h"
|
|
|
|
void *ossl_crypto_thread_start(OSSL_LIB_CTX *ctx, CRYPTO_THREAD_ROUTINE start,
|
|
void *data);
|
|
int ossl_crypto_thread_join(void *task, CRYPTO_THREAD_RETVAL *retval);
|
|
int ossl_crypto_thread_clean(void *vhandle);
|
|
uint64_t ossl_get_avail_threads(OSSL_LIB_CTX *ctx);
|
|
|
|
# if defined(OPENSSL_THREADS)
|
|
|
|
# define OSSL_LIB_CTX_GET_THREADS(CTX) \
|
|
ossl_lib_ctx_get_data(CTX, OSSL_LIB_CTX_THREAD_INDEX);
|
|
|
|
typedef struct openssl_threads_st {
|
|
uint64_t max_threads;
|
|
uint64_t active_threads;
|
|
CRYPTO_MUTEX *lock;
|
|
CRYPTO_CONDVAR *cond_finished;
|
|
} OSSL_LIB_CTX_THREADS;
|
|
|
|
# endif /* defined(OPENSSL_THREADS) */
|
|
|
|
#endif /* OPENSSL_INTERNAL_THREAD_H */
|