Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Reyhaneh Karimipour
xtrace-cpp
Commits
917ceef5
Commit
917ceef5
authored
May 21, 2019
by
DEPRECATED (Jonathan Mace) (Use @JonathanMace instead)
Browse files
Add some auto baggage macros
parent
dec5547e
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/baggage.h
View file @
917ceef5
...
...
@@ -91,5 +91,32 @@ namespace ThreadLocalBaggage {
}
#define BAGGAGE(b) BaggageHelpers::AutoBaggageScopeImpl __baggage__auto_baggage_(&b, __FILE__, __LINE__)
namespace
BaggageHelpers
{
// Used by AutoBaggageScope macro to scope the current block to the provided baggage
class
AutoBaggageScopeImpl
{
private:
Baggage
*
baggageSource
;
Baggage
suspendedBaggage
;
const
char
*
file
;
int
line
;
public:
AutoBaggageScopeImpl
(
Baggage
*
b
,
const
char
*
file
,
int
line
)
:
file
(
file
),
line
(
line
)
{
baggageSource
=
b
;
suspendedBaggage
=
ThreadLocalBaggage
::
Swap
(
*
b
,
file
,
line
);
}
~
AutoBaggageScopeImpl
()
{
*
baggageSource
=
ThreadLocalBaggage
::
Swap
(
suspendedBaggage
,
file
,
line
);
}
};
}
#endif
\ No newline at end of file
src/main.cc
View file @
917ceef5
...
...
@@ -33,7 +33,6 @@ int main(int argc, char *argv[]) {
XTRACE
(
"c"
,
{{
"key1"
,
"value1"
},
{
"key2"
,
"value2"
}});
Baggage
branched_baggage
=
BRANCH_CURRENT_BAGGAGE
();
std
::
thread
branched_thread
([
&
branched_baggage
]()
{
SET_CURRENT_BAGGAGE
(
branched_baggage
);
XTRACE
(
"f"
);
...
...
@@ -41,11 +40,35 @@ int main(int argc, char *argv[]) {
branched_baggage
=
TAKE_CURRENT_BAGGAGE
();
});
// Use the auto baggage macro
Baggage
branched_baggage2
=
BRANCH_CURRENT_BAGGAGE
();
std
::
thread
branched_thread2
([
&
branched_baggage2
]()
{
BAGGAGE
(
branched_baggage2
);
XTRACE
(
"f"
);
XTRACE
(
"g"
);
});
Baggage
inline_branched_baggage
=
BRANCH_CURRENT_BAGGAGE
();
{
BAGGAGE
(
inline_branched_baggage
);
XTRACE
(
"hello world"
);
XTRACE
(
"goodbyte world"
);
}
XTRACE
(
"d"
);
XTRACE
(
"e"
);
branched_thread
.
join
();
branched_thread2
.
join
();
JOIN_CURRENT_BAGGAGE
(
branched_baggage
);
JOIN_CURRENT_BAGGAGE
(
branched_baggage2
);
JOIN_CURRENT_BAGGAGE
(
inline_branched_baggage
);
XTRACE
(
"h"
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment