diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-14 10:05:54 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-14 10:05:54 +0200 |
commit | 1013970853e6acfd60591a89ae08cc40c64bee06 (patch) | |
tree | 7ca081e6adcecebc41e68a659741e0cc0caf77eb /src/tracker.h | |
parent | 0567dc0fc6da09467f65ee2f3c10ab68bb76832c (diff) | |
download | lanes-1013970853e6acfd60591a89ae08cc40c64bee06.tar.gz lanes-1013970853e6acfd60591a89ae08cc40c64bee06.tar.bz2 lanes-1013970853e6acfd60591a89ae08cc40c64bee06.zip |
Moved Lane tracking implementation in a separate file
Diffstat (limited to 'src/tracker.h')
-rw-r--r-- | src/tracker.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/tracker.h b/src/tracker.h new file mode 100644 index 0000000..087598c --- /dev/null +++ b/src/tracker.h | |||
@@ -0,0 +1,35 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <mutex> | ||
4 | |||
5 | // Do we want to activate full lane tracking feature? | ||
6 | #define HAVE_LANE_TRACKING() 1 | ||
7 | |||
8 | #if HAVE_LANE_TRACKING() | ||
9 | |||
10 | class Lane; | ||
11 | struct lua_State; | ||
12 | |||
13 | // The chain is ended by '(Lane*)(-1)', not nullptr: | ||
14 | // 'trackingFirst -> ... -> ... -> (-1)' | ||
15 | #define TRACKING_END ((Lane*) (-1)) | ||
16 | |||
17 | class LaneTracker | ||
18 | { | ||
19 | private: | ||
20 | mutable std::mutex trackingMutex; | ||
21 | Lane* volatile trackingFirst{ nullptr }; // will change to TRACKING_END if we want to activate tracking | ||
22 | |||
23 | public: | ||
24 | void tracking_add(Lane* lane_); | ||
25 | [[nodiscard]] bool tracking_remove(Lane* lane_); | ||
26 | [[nodiscard]] int pushThreadsTable(lua_State* L_) const; | ||
27 | void activate() { | ||
28 | trackingFirst = TRACKING_END; | ||
29 | } | ||
30 | [[nodiscard]] bool isActive() const { | ||
31 | return trackingFirst != nullptr; | ||
32 | } | ||
33 | }; | ||
34 | |||
35 | #endif // HAVE_LANE_TRACKING() | ||