From 6347519ab1e01f6d6077d36d515baeef311d0f1f Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 10 Apr 2023 11:51:43 -0400 Subject: [PATCH] pthread_once: Add static assertions for ONCE_INITs. Both of these need to be here, they cannot be in the C sources, as the static assertions throw "non-constant expression" when placed there. --- src/system/libroot/posix/pthread/pthread_once.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/system/libroot/posix/pthread/pthread_once.cpp b/src/system/libroot/posix/pthread/pthread_once.cpp index 7ef275452b..95acaedd22 100644 --- a/src/system/libroot/posix/pthread/pthread_once.cpp +++ b/src/system/libroot/posix/pthread/pthread_once.cpp @@ -1,11 +1,14 @@ /* * Copyright 2008-2011, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2023, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #include +#include #include +#include enum { @@ -15,6 +18,11 @@ enum { STATE_INITIALIZED = -4 }; +#if __cplusplus >= 201103L +STATIC_ASSERT(((pthread_once_t)ONCE_FLAG_INIT).state == ((pthread_once_t)PTHREAD_ONCE_INIT).state); +STATIC_ASSERT(((pthread_once_t)PTHREAD_ONCE_INIT).state == STATE_UNINITIALIZED); +#endif + /*! Called when the thread performing the initialization function was canceled.