File tree 3 files changed +23
-4
lines changed
profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux
3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,14 @@ class AutoResetEvent
21
21
~AutoResetEvent ();
22
22
23
23
void Set ();
24
+
25
+ // Wait will block the execution of the thread until a call to Set is made
26
+ // or until it times out.
27
+ // [parameter] timeout : time to wait before returning.
28
+ // if timeout == InfiniteTimeout, it will wait until Set is called.
29
+ // if timeout != InfiniteTimeout, it will wait either for a call to Set either for the timeout.
30
+ // [Return]
31
+ // true if Set was called, false is the call timed out.
24
32
bool Wait (std::chrono::milliseconds timeout = InfiniteTimeout);
25
33
26
34
private:
Original file line number Diff line number Diff line change @@ -33,8 +33,12 @@ bool LibrariesInfoCache::StartImpl()
33
33
_librariesInfo.reserve (100 );
34
34
s_instance = this ;
35
35
unw_set_iterate_phdr_function (unw_local_addr_space, LibrariesInfoCache::DlIteratePhdr);
36
- _worker = std::thread (&LibrariesInfoCache::Work, this );
37
- return true ;
36
+ auto startEvent = std::make_shared<AutoResetEvent>(false );
37
+ _worker = std::thread (&LibrariesInfoCache::Work, this , startEvent);
38
+ // We must wait for the thread to be fully started and the cache populated
39
+ // before reporting the service start status.
40
+ // 2s for CI
41
+ return startEvent->Wait (2s);
38
42
}
39
43
40
44
bool LibrariesInfoCache::StopImpl ()
@@ -51,7 +55,7 @@ bool LibrariesInfoCache::StopImpl()
51
55
return true ;
52
56
}
53
57
54
- void LibrariesInfoCache::Work ()
58
+ void LibrariesInfoCache::Work (std::shared_ptr<AutoResetEvent> startEvent )
55
59
{
56
60
OpSysTools::SetNativeThreadName (WStr (" DD_LibsCache" ));
57
61
@@ -80,6 +84,12 @@ void LibrariesInfoCache::Work()
80
84
}
81
85
82
86
UpdateCache ();
87
+
88
+ if (startEvent != nullptr )
89
+ {
90
+ startEvent->Set ();
91
+ startEvent.reset ();
92
+ }
83
93
}
84
94
85
95
Log::Debug (" Stopping worker: stop request received." );
Original file line number Diff line number Diff line change 13
13
#include < atomic>
14
14
#include < libunwind.h>
15
15
#include < link.h>
16
+ #include < memory>
16
17
#include < shared_mutex>
17
18
#include < thread>
18
19
#include < vector>
@@ -48,7 +49,7 @@ class LibrariesInfoCache : public ServiceBase
48
49
#ifdef DD_TEST
49
50
private:
50
51
#endif
51
- void Work ();
52
+ void Work (std::shared_ptr<AutoResetEvent> startEvent );
52
53
53
54
static LibrariesInfoCache* s_instance;
54
55
You can’t perform that action at this time.
0 commit comments