diff --git a/src/common/sha3/xkcp_dispatch.h b/src/common/sha3/xkcp_dispatch.h index 15103dbe61..73bedab69f 100644 --- a/src/common/sha3/xkcp_dispatch.h +++ b/src/common/sha3/xkcp_dispatch.h @@ -13,6 +13,12 @@ #ifndef OQS_SHA3_XKCP_DISPATCH_H #define OQS_SHA3_XKCP_DISPATCH_H +#if defined __has_include +#if __has_include () +#define OQS_SHA3_XKCP_DISPATCH_USE_PTHREAD +#endif +#endif + typedef void KeccakInitFn(void *); extern KeccakInitFn \ KeccakP1600_Initialize, \ diff --git a/src/common/sha3/xkcp_sha3.c b/src/common/sha3/xkcp_sha3.c index 16ee2ff5c0..f2daca3796 100644 --- a/src/common/sha3/xkcp_sha3.c +++ b/src/common/sha3/xkcp_sha3.c @@ -13,21 +13,21 @@ #include +#ifdef OQS_SHA3_XKCP_DISPATCH_USE_PTHREAD +#include +#endif #include #include #include #include -#ifndef __STDC_NO_THREADS__ -#include -#endif #define KECCAK_CTX_ALIGNMENT 32 #define _KECCAK_CTX_BYTES (200+sizeof(uint64_t)) #define KECCAK_CTX_BYTES (KECCAK_CTX_ALIGNMENT * \ ((_KECCAK_CTX_BYTES + KECCAK_CTX_ALIGNMENT - 1)/KECCAK_CTX_ALIGNMENT)) -#ifndef __STDC_NO_THREADS__ -static once_flag dispatch_once_flag = ONCE_FLAG_INIT; +#ifdef OQS_SHA3_XKCP_DISPATCH_USE_PTHREAD +static pthread_once_t dispatch_once_control = PTHREAD_ONCE_INIT; #endif static KeccakInitFn *Keccak_Initialize_ptr = NULL; @@ -85,8 +85,8 @@ static void Keccak_Dispatch() { * that have not been permuted, or not-yet-squeezed bytes. **************************************************/ static void keccak_inc_reset(uint64_t *s) { -#ifndef __STDC_NO_THREADS__ - call_once(&dispatch_once_flag, Keccak_Dispatch); +#ifdef OQS_SHA3_XKCP_DISPATCH_USE_PTHREAD + pthread_once(&dispatch_once_control, Keccak_Dispatch); #else if (Keccak_Initialize_ptr == NULL) { Keccak_Dispatch(); diff --git a/src/common/sha3/xkcp_sha3x4.c b/src/common/sha3/xkcp_sha3x4.c index c6eca5d8b2..a5bd03bc5c 100644 --- a/src/common/sha3/xkcp_sha3x4.c +++ b/src/common/sha3/xkcp_sha3x4.c @@ -8,21 +8,21 @@ #include #include +#ifdef OQS_SHA3_XKCP_DISPATCH_USE_PTHREAD +#include +#endif #include #include #include #include -#ifndef __STDC_NO_THREADS__ -#include -#endif #define KECCAK_X4_CTX_ALIGNMENT 32 #define _KECCAK_X4_CTX_BYTES (800+sizeof(uint64_t)) #define KECCAK_X4_CTX_BYTES (KECCAK_X4_CTX_ALIGNMENT * \ ((_KECCAK_X4_CTX_BYTES + KECCAK_X4_CTX_ALIGNMENT - 1)/KECCAK_X4_CTX_ALIGNMENT)) -#ifndef __STDC_NO_THREADS__ -static once_flag dispatch_once_flag = ONCE_FLAG_INIT; +#ifdef OQS_SHA3_XKCP_DISPATCH_USE_PTHREAD +static pthread_once_t dispatch_once_control = PTHREAD_ONCE_INIT; #endif static KeccakX4InitFn *Keccak_X4_Initialize_ptr = NULL; @@ -65,8 +65,8 @@ static void Keccak_X4_Dispatch() { } static void keccak_x4_inc_reset(uint64_t *s) { -#ifndef __STDC_NO_THREADS__ - call_once(&dispatch_once_flag, Keccak_X4_Dispatch); +#ifdef OQS_SHA3_XKCP_DISPATCH_USE_PTHREAD + pthread_once(&dispatch_once_control, Keccak_X4_Dispatch); #else if (Keccak_X4_Initialize_ptr == NULL) { Keccak_X4_Dispatch();