/src/openssl/crypto/thread/api.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.  | 
3  |  |  *  | 
4  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use  | 
5  |  |  * this file except in compliance with the License.  You can obtain a copy  | 
6  |  |  * in the file LICENSE in the source distribution or at  | 
7  |  |  * https://www.openssl.org/source/license.html  | 
8  |  |  */  | 
9  |  |  | 
10  |  | #include <openssl/configuration.h>  | 
11  |  | #include <openssl/thread.h>  | 
12  |  | #include <internal/thread.h>  | 
13  |  |  | 
14  |  | uint32_t OSSL_get_thread_support_flags(void)  | 
15  | 0  | { | 
16  | 0  |     int support = 0;  | 
17  |  | 
  | 
18  | 0  | #if !defined(OPENSSL_NO_THREAD_POOL)  | 
19  | 0  |     support |= OSSL_THREAD_SUPPORT_FLAG_THREAD_POOL;  | 
20  | 0  | #endif  | 
21  | 0  | #if !defined(OPENSSL_NO_DEFAULT_THREAD_POOL)  | 
22  | 0  |     support |= OSSL_THREAD_SUPPORT_FLAG_DEFAULT_SPAWN;  | 
23  | 0  | #endif  | 
24  |  | 
  | 
25  | 0  |     return support;  | 
26  | 0  | }  | 
27  |  |  | 
28  |  | #if defined(OPENSSL_NO_THREAD_POOL) || defined(OPENSSL_NO_DEFAULT_THREAD_POOL)  | 
29  |  |  | 
30  |  | int OSSL_set_max_threads(OSSL_LIB_CTX *ctx, uint64_t max_threads)  | 
31  |  | { | 
32  |  |     return 0;  | 
33  |  | }  | 
34  |  |  | 
35  |  | uint64_t OSSL_get_max_threads(OSSL_LIB_CTX *ctx)  | 
36  |  | { | 
37  |  |     return 0;  | 
38  |  | }  | 
39  |  |  | 
40  |  | #else  | 
41  |  |  | 
42  |  | uint64_t OSSL_get_max_threads(OSSL_LIB_CTX *ctx)  | 
43  | 1  | { | 
44  | 1  |     uint64_t ret = 0;  | 
45  | 1  |     OSSL_LIB_CTX_THREADS *tdata = OSSL_LIB_CTX_GET_THREADS(ctx);  | 
46  |  |  | 
47  | 1  |     if (tdata == NULL)  | 
48  | 0  |         goto fail;  | 
49  |  |  | 
50  | 1  |     ossl_crypto_mutex_lock(tdata->lock);  | 
51  | 1  |     ret = tdata->max_threads;  | 
52  | 1  |     ossl_crypto_mutex_unlock(tdata->lock);  | 
53  |  |  | 
54  | 1  | fail:  | 
55  | 1  |     return ret;  | 
56  | 1  | }  | 
57  |  |  | 
58  |  | int OSSL_set_max_threads(OSSL_LIB_CTX *ctx, uint64_t max_threads)  | 
59  | 1  | { | 
60  | 1  |     OSSL_LIB_CTX_THREADS *tdata;  | 
61  |  |  | 
62  | 1  |     tdata = OSSL_LIB_CTX_GET_THREADS(ctx);  | 
63  | 1  |     if (tdata == NULL)  | 
64  | 0  |         return 0;  | 
65  |  |  | 
66  | 1  |     ossl_crypto_mutex_lock(tdata->lock);  | 
67  | 1  |     tdata->max_threads = max_threads;  | 
68  | 1  |     ossl_crypto_mutex_unlock(tdata->lock);  | 
69  |  |  | 
70  | 1  |     return 1;  | 
71  | 1  | }  | 
72  |  |  | 
73  |  | #endif  |