-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardize async id creation and setting
This will make sure we don't forget to reset async ids in 'create_reset_ids' and also makes sure we're incrementing the id whenever we get it (instead of doing it at some later, random instruction). This is follow up to a conversation here: bpftrace/bpftrace#3249 (comment)
- Loading branch information
1 parent
8b0a62a
commit 7b9b4e9
Showing
5 changed files
with
102 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
namespace bpftrace { | ||
namespace ast { | ||
|
||
// Add new ids here | ||
#define FOR_LIST_OF_ASYNC_IDS(DO) \ | ||
DO(cat) \ | ||
DO(cgroup_path) \ | ||
DO(helper_error) \ | ||
DO(join) \ | ||
DO(mapped_printf) \ | ||
DO(non_map_print) \ | ||
DO(printf) \ | ||
DO(skb_output) \ | ||
DO(strftime) \ | ||
DO(str) \ | ||
DO(system) \ | ||
DO(time) \ | ||
DO(watchpoint) | ||
|
||
#define DEFINE_MEMBER_VAR(id, ...) int _##id = 0; | ||
#define DEFINE_ACCESS_METHOD(id, ...) \ | ||
int id() \ | ||
{ \ | ||
return _##id++; \ | ||
} | ||
#define LOCAL_SAVE(id, ...) local_##id = _##id, | ||
#define LOCAL_RESTORE(id, ...) this->_##id = local_##id; | ||
|
||
class AsyncIds { | ||
public: | ||
explicit AsyncIds() = default; | ||
|
||
FOR_LIST_OF_ASYNC_IDS(DEFINE_ACCESS_METHOD) | ||
|
||
/* | ||
* For 'create_reset_ids' return a lambda that has captured-by-value | ||
* CodegenLLVM's async id state. Running the returned lambda will restore | ||
* `CodegenLLVM`s async id state back to when this function was first called. | ||
*/ | ||
std::function<void()> create_reset_ids() | ||
{ | ||
return [FOR_LIST_OF_ASYNC_IDS(LOCAL_SAVE) this] { | ||
FOR_LIST_OF_ASYNC_IDS(LOCAL_RESTORE) | ||
}; | ||
} | ||
|
||
private: | ||
FOR_LIST_OF_ASYNC_IDS(DEFINE_MEMBER_VAR) | ||
}; | ||
|
||
} // namespace ast | ||
} // namespace bpftrace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.