Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
emper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Fischer
emper
Commits
09d7edbd
Commit
09d7edbd
authored
4 years ago
by
Florian Fischer
Browse files
Options
Downloads
Patches
Plain Diff
[DEBUG] change "#ifndef NDEBUG" code to "if constexpr"
parent
17a4ce05
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
emper/BinaryPrivateSemaphore.cpp
+15
-14
15 additions, 14 deletions
emper/BinaryPrivateSemaphore.cpp
emper/Context.hpp
+15
-17
15 additions, 17 deletions
emper/Context.hpp
with
30 additions
and
31 deletions
emper/BinaryPrivateSemaphore.cpp
+
15
−
14
View file @
09d7edbd
...
@@ -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 N
DEBUG
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 N
DEBUG
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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
emper/Context.hpp
+
15
−
17
View file @
09d7edbd
...
@@ -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 N
DEBUG
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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment