Skip to content

Commit a460916

Browse files
committed
New macro OQS_USE_PTHREADS conditioned on embedded
1 parent fd2231f commit a460916

File tree

8 files changed

+22
-16
lines changed

8 files changed

+22
-16
lines changed

.CMake/compiler_opts.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
106106

107107
set(THREADS_PREFER_PTHREAD_FLAG ON)
108108
find_package(Threads)
109+
if (CMAKE_USE_PTHREADS_INIT AND NOT OQS_EMBEDDED_BUILD)
110+
set(OQS_USE_PTHREADS ON)
111+
endif()
109112

110113
if(${OQS_DEBUG_BUILD})
111114
add_compile_options(-g3)
@@ -165,6 +168,9 @@ elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
165168

166169
set(THREADS_PREFER_PTHREAD_FLAG ON)
167170
find_package(Threads)
171+
if (CMAKE_USE_PTHREADS_INIT AND NOT OQS_EMBEDDED_BUILD)
172+
set(OQS_USE_PTHREADS ON)
173+
endif()
168174

169175
if(${OQS_DEBUG_BUILD})
170176
add_compile_options (-Wstrict-overflow)

src/common/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ else()
9999
target_compile_definitions(internal PRIVATE OQS_HAVE_GETENTROPY)
100100
endif()
101101
endif()
102-
if(CMAKE_USE_PTHREADS_INIT)
102+
if(OQS_USE_PTHREADS)
103103
target_link_libraries(common PRIVATE Threads::Threads)
104104
target_link_libraries(internal PRIVATE Threads::Threads)
105105
endif()

src/common/sha3/xkcp_sha3.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include <oqs/common.h>
1515

16-
#if CMAKE_USE_PTHREADS_INIT
16+
#if OQS_USE_PTHREADS
1717
#include <pthread.h>
1818
#endif
1919
#include <stddef.h>
@@ -26,7 +26,7 @@
2626
#define KECCAK_CTX_BYTES (KECCAK_CTX_ALIGNMENT * \
2727
((_KECCAK_CTX_BYTES + KECCAK_CTX_ALIGNMENT - 1)/KECCAK_CTX_ALIGNMENT))
2828

29-
#if CMAKE_USE_PTHREADS_INIT
29+
#if OQS_USE_PTHREADS
3030
static pthread_once_t dispatch_once_control = PTHREAD_ONCE_INIT;
3131
#endif
3232

@@ -85,7 +85,7 @@ static void Keccak_Dispatch(void) {
8585
* that have not been permuted, or not-yet-squeezed bytes.
8686
**************************************************/
8787
static void keccak_inc_reset(uint64_t *s) {
88-
#if CMAKE_USE_PTHREADS_INIT
88+
#if OQS_USE_PTHREADS
8989
pthread_once(&dispatch_once_control, Keccak_Dispatch);
9090
#else
9191
if (Keccak_Initialize_ptr == NULL) {

src/common/sha3/xkcp_sha3x4.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <oqs/common.h>
99
#include <oqs/oqsconfig.h>
1010

11-
#if CMAKE_USE_PTHREADS_INIT
11+
#if OQS_USE_PTHREADS
1212
#include <pthread.h>
1313
#endif
1414
#include <stddef.h>
@@ -21,7 +21,7 @@
2121
#define KECCAK_X4_CTX_BYTES (KECCAK_X4_CTX_ALIGNMENT * \
2222
((_KECCAK_X4_CTX_BYTES + KECCAK_X4_CTX_ALIGNMENT - 1)/KECCAK_X4_CTX_ALIGNMENT))
2323

24-
#if CMAKE_USE_PTHREADS_INIT
24+
#if OQS_USE_PTHREADS
2525
static pthread_once_t dispatch_once_control = PTHREAD_ONCE_INIT;
2626
#endif
2727

@@ -65,7 +65,7 @@ static void Keccak_X4_Dispatch(void) {
6565
}
6666

6767
static void keccak_x4_inc_reset(uint64_t *s) {
68-
#if CMAKE_USE_PTHREADS_INIT
68+
#if OQS_USE_PTHREADS
6969
pthread_once(&dispatch_once_control, Keccak_X4_Dispatch);
7070
#else
7171
if (Keccak_X4_Initialize_ptr == NULL) {

src/oqsconfig.h.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
#cmakedefine USE_SANITIZER "@USE_SANITIZER@"
1919
#cmakedefine CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@"
2020

21-
#cmakedefine CMAKE_USE_PTHREADS_INIT 1
22-
2321
#cmakedefine OQS_USE_OPENSSL 1
2422
#cmakedefine OQS_USE_AES_OPENSSL 1
2523
#cmakedefine OQS_USE_SHA2_OPENSSL 1
2624
#cmakedefine OQS_USE_SHA3_OPENSSL 1
2725

2826
#cmakedefine OQS_EMBEDDED_BUILD 1
2927

28+
#cmakedefine OQS_USE_PTHREADS 1
29+
3030
#cmakedefine OQS_USE_ADX_INSTRUCTIONS 1
3131
#cmakedefine OQS_USE_AES_INSTRUCTIONS 1
3232
#cmakedefine OQS_USE_AVX_INSTRUCTIONS 1

tests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ endif()
3131

3232
# List oqs-internal after oqs so that oqs has linking precedence.
3333
set(TEST_DEPS oqs oqs-internal ${LIBM})
34-
if(CMAKE_USE_PTHREADS_INIT)
34+
if(OQS_USE_PTHREADS)
3535
set(TEST_DEPS ${TEST_DEPS} Threads::Threads)
3636
endif()
3737

tests/test_kem.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <oqs/oqs.h>
99

10-
#if CMAKE_USE_PTHREADS_INIT
10+
#if OQS_USE_PTHREADS
1111
#include <pthread.h>
1212
#endif
1313

@@ -197,7 +197,7 @@ static void TEST_KEM_randombytes(uint8_t *random_array, size_t bytes_to_read) {
197197
}
198198
#endif
199199

200-
#if CMAKE_USE_PTHREADS_INIT
200+
#if OQS_USE_PTHREADS
201201
struct thread_data {
202202
char *alg_name;
203203
OQS_STATUS rc;
@@ -245,7 +245,7 @@ int main(int argc, char **argv) {
245245
#endif
246246

247247
OQS_STATUS rc;
248-
#if CMAKE_USE_PTHREADS_INIT
248+
#if OQS_USE_PTHREADS
249249
#define MAX_LEN_KEM_NAME_ 64
250250
// don't run Classic McEliece in threads because of large stack usage
251251
char no_thread_kem_patterns[][MAX_LEN_KEM_NAME_] = {"Classic-McEliece", "HQC-256-"};

tests/test_sig.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <oqs/oqs.h>
1212

13-
#if CMAKE_USE_PTHREADS_INIT
13+
#if OQS_USE_PTHREADS
1414
#include <pthread.h>
1515
#endif
1616

@@ -174,7 +174,7 @@ static void TEST_SIG_randombytes(uint8_t *random_array, size_t bytes_to_read) {
174174
}
175175
#endif
176176

177-
#if CMAKE_USE_PTHREADS_INIT
177+
#if OQS_USE_PTHREADS
178178
struct thread_data {
179179
char *alg_name;
180180
OQS_STATUS rc;
@@ -222,7 +222,7 @@ int main(int argc, char **argv) {
222222
#endif
223223

224224
OQS_STATUS rc;
225-
#if CMAKE_USE_PTHREADS_INIT
225+
#if OQS_USE_PTHREADS
226226
#define MAX_LEN_SIG_NAME_ 64
227227
pthread_t thread;
228228
struct thread_data td;

0 commit comments

Comments
 (0)