cesium-native 0.43.0
Loading...
Searching...
No Matches
WithTracing.h
1#pragma once
2
3#include "unwrapFuture.h"
4
5#include <CesiumUtility/Tracing.h>
6
7namespace CesiumAsync {
8namespace CesiumImpl {
9// Begin omitting doxgen warnings for Impl namespace
11
12template <typename T> struct WithTracing {
13 template <typename Func>
14 static auto
15 begin([[maybe_unused]] const char* tracingName, [[maybe_unused]] Func&& f) {
16#if CESIUM_TRACING_ENABLED
17 return
18 [tracingName, CESIUM_TRACE_LAMBDA_CAPTURE_TRACK()](T&& result) mutable {
19 CESIUM_TRACE_USE_CAPTURED_TRACK();
20 if (tracingName) {
21 CESIUM_TRACE_BEGIN_IN_TRACK(tracingName);
22 }
23 return std::move(result);
24 };
25#else
26 return CesiumImpl::unwrapFuture<Func, T>(std::forward<Func>(f));
27#endif
28 }
29
30 template <typename Func>
31 static auto end([[maybe_unused]] const char* tracingName, Func&& f) {
32#if CESIUM_TRACING_ENABLED
33 return [tracingName,
34 f = CesiumImpl::unwrapFuture<Func, T>(std::forward<Func>(f)),
35 CESIUM_TRACE_LAMBDA_CAPTURE_TRACK()](T&& result) mutable {
36 CESIUM_TRACE_USE_CAPTURED_TRACK();
37 if (tracingName) {
38 CESIUM_TRACE_END_IN_TRACK(tracingName);
39 }
40 return f(std::move(result));
41 };
42#else
43 return CesiumImpl::unwrapFuture<Func, T>(std::forward<Func>(f));
44#endif
45 }
46};
47
48template <typename T> struct WithTracingShared {
49 template <typename Func>
50 static auto
51 begin([[maybe_unused]] const char* tracingName, [[maybe_unused]] Func&& f) {
52#if CESIUM_TRACING_ENABLED
53 return [tracingName,
54 CESIUM_TRACE_LAMBDA_CAPTURE_TRACK()](const T& result) mutable {
55 CESIUM_TRACE_USE_CAPTURED_TRACK();
56 if (tracingName) {
57 CESIUM_TRACE_BEGIN_IN_TRACK(tracingName);
58 }
59 return result;
60 };
61#else
62 return CesiumImpl::unwrapSharedFuture<Func, T>(std::forward<Func>(f));
63#endif
64 }
65
66 template <typename Func>
67 static auto end([[maybe_unused]] const char* tracingName, Func&& f) {
68#if CESIUM_TRACING_ENABLED
69 return [tracingName,
70 f = CesiumImpl::unwrapSharedFuture<Func, T>(std::forward<Func>(f)),
71 CESIUM_TRACE_LAMBDA_CAPTURE_TRACK()](const T& result) mutable {
72 CESIUM_TRACE_USE_CAPTURED_TRACK();
73 if (tracingName) {
74 CESIUM_TRACE_END_IN_TRACK(tracingName);
75 }
76 return f(result);
77 };
78#else
79 return CesiumImpl::unwrapSharedFuture<Func, T>(std::forward<Func>(f));
80#endif
81 }
82};
83
84template <> struct WithTracing<void> {
85 template <typename Func>
86 static auto
87 begin([[maybe_unused]] const char* tracingName, [[maybe_unused]] Func&& f) {
88#if CESIUM_TRACING_ENABLED
89 return [tracingName, CESIUM_TRACE_LAMBDA_CAPTURE_TRACK()]() mutable {
90 CESIUM_TRACE_USE_CAPTURED_TRACK();
91 if (tracingName) {
92 CESIUM_TRACE_END_IN_TRACK(tracingName);
93 }
94 };
95#else
96 return CesiumImpl::unwrapFuture<Func>(std::forward<Func>(f));
97#endif
98 }
99
100 template <typename Func>
101 static auto end([[maybe_unused]] const char* tracingName, Func&& f) {
102#if CESIUM_TRACING_ENABLED
103 return [tracingName,
104 f = CesiumImpl::unwrapFuture<Func>(std::forward<Func>(f)),
105 CESIUM_TRACE_LAMBDA_CAPTURE_TRACK()]() mutable {
106 CESIUM_TRACE_USE_CAPTURED_TRACK();
107 if (tracingName) {
108 CESIUM_TRACE_END_IN_TRACK(tracingName);
109 }
110 return f();
111 };
112#else
113 return CesiumImpl::unwrapFuture<Func>(std::forward<Func>(f));
114#endif
115 }
116};
117
118// With a void Future, shared and non-shared are identical.
119template <> struct WithTracingShared<void> : public WithTracing<void> {};
120
122// End omitting doxgen warnings for Impl namespace
123} // namespace CesiumImpl
124} // namespace CesiumAsync
Classes that support asynchronous operations.