Skip to content
Snippets Groups Projects
Commit 09d7edbd authored by Florian Fischer's avatar Florian Fischer
Browse files

[DEBUG] change "#ifndef NDEBUG" code to "if constexpr"

parent 17a4ce05
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "Common.hpp" // for unlikely #include "Common.hpp" // for unlikely
#include "Context.hpp" // for Context #include "Context.hpp" // for Context
#include "Debug.hpp" // for LOGDD #include "Debug.hpp" // for LOGDD
#include "Emper.hpp" // for emper::DEBUG
void BinaryPrivateSemaphore::wait() { void BinaryPrivateSemaphore::wait() {
State state = bpsState.load(); State state = bpsState.load();
...@@ -28,13 +29,13 @@ void BinaryPrivateSemaphore::wait() { ...@@ -28,13 +29,13 @@ void BinaryPrivateSemaphore::wait() {
State newState = blocked; State newState = blocked;
State previousState = bpsState.exchange(newState); State previousState = bpsState.exchange(newState);
if (previousState == signaled) { if (previousState == signaled) {
#ifndef NDEBUG if constexpr (emper::DEBUG) {
// Reset the real signal state only in debug // Reset the real signal state only in debug
// builds. As it is not required to set the state here // builds. As it is not required to set the state here
// for the correctnes of the synchronization primitive. // for the correctnes of the synchronization primitive.
newState = signaled; newState = signaled;
bpsState.store(newState, std::memory_order_relaxed); bpsState.store(newState, std::memory_order_relaxed);
#endif }
unblock(blockedContext); unblock(blockedContext);
} }
}); });
...@@ -48,13 +49,13 @@ auto BinaryPrivateSemaphore::signalInternal() -> Context* { ...@@ -48,13 +49,13 @@ auto BinaryPrivateSemaphore::signalInternal() -> Context* {
if (currentState != initial) { if (currentState != initial) {
// Fast path: If the state is not initial then someone is // Fast path: If the state is not initial then someone is
// waiting, because the state can't be signaled. // waiting, because the state can't be signaled.
#ifndef NDEBUG if constexpr (emper::DEBUG) {
State newState = signaled; State newState = signaled;
// Reset the real signal state only in debug // Reset the real signal state only in debug
// builds. As it is not required to set the state here // builds. As it is not required to set the state here
// for the correctnes of the synchronization primitive. // for the correctnes of the synchronization primitive.
bpsState.store(newState); bpsState.store(newState);
#endif }
LOGDD("unblock in fast path"); LOGDD("unblock in fast path");
return blockedContext; return blockedContext;
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <cassert> // for assert #include <cassert> // for assert
#include <cstdint> // for uintptr_t #include <cstdint> // for uintptr_t
#include <cstring> // for memset
#include <functional> // for function #include <functional> // for function
#include <iosfwd> // for ostream #include <iosfwd> // for ostream
#include <type_traits> // for remove_reference<>::type // IWYU pragma: keep #include <type_traits> // for remove_reference<>::type // IWYU pragma: keep
...@@ -11,10 +12,7 @@ ...@@ -11,10 +12,7 @@
#include "Common.hpp" // for func_t, DIE, ALIGN_TO_CACHE_LINE #include "Common.hpp" // for func_t, DIE, ALIGN_TO_CACHE_LINE
#include "Debug.hpp" // for LOGD, LogSubsystem, LogSubsystem::C, Logger #include "Debug.hpp" // for LOGD, LogSubsystem, LogSubsystem::C, Logger
#include "Emper.hpp" // for Emper::DEBUG
#ifndef NDEBUG
#include <cstring> // for memset
#endif
class Fiber; class Fiber;
...@@ -70,19 +68,19 @@ class ALIGN_TO_CACHE_LINE Context : Logger<LogSubsystem::C> { ...@@ -70,19 +68,19 @@ class ALIGN_TO_CACHE_LINE Context : Logger<LogSubsystem::C> {
mainFunction(std::move(std::move(mainFunction))) { mainFunction(std::move(std::move(mainFunction))) {
// valgrindStackId = VALGRIND_STACK_REGISTER(context, context + CONTEXT_SI); // valgrindStackId = VALGRIND_STACK_REGISTER(context, context + CONTEXT_SI);
#ifndef NDEBUG if constexpr (emper::DEBUG) {
// Write the stack full of 0xcc bytes, which just happen to be // Write the stack full of 0xcc bytes, which just happen to be
// the 'int3' instruction, which will trigger a breakpoint // the 'int3' instruction, which will trigger a breakpoint
// when executed. // when executed.
void* res = memset(context, 0xcc, (char*)tos - context); void* res = memset(context, 0xcc, (char*)tos - context);
if (!res) DIE; if (!res) DIE;
// Mark the last valid 16 bytes just below the top of stack. // Mark the last valid 16 bytes just below the top of stack.
res = memset(((uintptr_t*)tos) - 1, 0xab, sizeof(uintptr_t)); res = memset(((uintptr_t*)tos) - 1, 0xab, sizeof(uintptr_t));
if (!res) DIE; if (!res) DIE;
// Mark the eventually existing unused top stack bytes // Mark the eventually existing unused top stack bytes
res = memset(tos, 0xee, &context[CONTEXT_SIZE] - (char*)tos); res = memset(tos, 0xee, &context[CONTEXT_SIZE] - (char*)tos);
if (!res) DIE; if (!res) DIE;
#endif }
setEmptyHook(); setEmptyHook();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment