@@ -16,7 +16,8 @@ CommandServer::CommandServer(const std::shared_ptr<ILogger>& logger, ICorProfile
16
16
HRESULT CommandServer::Start (
17
17
const std::string& path,
18
18
std::function<HRESULT(const IpcMessage& message)> callback,
19
- std::function<HRESULT(const IpcMessage& message)> validateMessageCallback)
19
+ std::function<HRESULT(const IpcMessage& message)> validateMessageCallback,
20
+ std::function<HRESULT(unsigned short commandSet, bool & unmanagedOnly)> unmanagedOnlyCallback)
20
21
{
21
22
if (_shutdown.load ())
22
23
{
@@ -35,10 +36,12 @@ HRESULT CommandServer::Start(
35
36
36
37
_callback = callback;
37
38
_validateMessageCallback = validateMessageCallback;
39
+ _unmanagedOnlyCallback = unmanagedOnlyCallback;
38
40
39
41
IfFailLogRet_ (_logger, _server.Bind (path));
40
42
_listeningThread = std::thread (&CommandServer::ListeningThread, this );
41
43
_clientThread = std::thread (&CommandServer::ClientProcessingThread, this );
44
+ _unmanagedOnlyThread = std::thread (&CommandServer::UnmanagedOnlyProcessingThread, this );
42
45
return S_OK;
43
46
}
44
47
@@ -48,10 +51,12 @@ void CommandServer::Shutdown()
48
51
if (_shutdown.compare_exchange_strong (shutdown, true ))
49
52
{
50
53
_clientQueue.Complete ();
54
+ _unmanagedOnlyQueue.Complete ();
51
55
_server.Shutdown ();
52
56
53
57
_listeningThread.join ();
54
58
_clientThread.join ();
59
+ _unmanagedOnlyThread.join ();
55
60
}
56
61
}
57
62
@@ -110,7 +115,15 @@ void CommandServer::ListeningThread()
110
115
111
116
if (doEnqueueMessage)
112
117
{
113
- _clientQueue.Enqueue (message);
118
+ bool unmanagedOnly = false ;
119
+ if (SUCCEEDED (_unmanagedOnlyCallback (message.CommandSet , unmanagedOnly)) && unmanagedOnly)
120
+ {
121
+ _unmanagedOnlyQueue.Enqueue (message);
122
+ }
123
+ else
124
+ {
125
+ _clientQueue.Enqueue (message);
126
+ }
114
127
}
115
128
}
116
129
}
@@ -134,6 +147,36 @@ void CommandServer::ClientProcessingThread()
134
147
// We are complete, discard all messages
135
148
break ;
136
149
}
150
+
151
+ // DispatchMessage in the callback serializes all callbacks.
152
+ hr = _callback (message);
153
+ if (hr != S_OK)
154
+ {
155
+ _logger->Log (LogLevel::Warning, _LS (" IpcMessage callback failed: 0x%08x" ), hr);
156
+ }
157
+ }
158
+ }
159
+
160
+ void CommandServer::UnmanagedOnlyProcessingThread ()
161
+ {
162
+ HRESULT hr = _profilerInfo->InitializeCurrentThread ();
163
+
164
+ if (FAILED (hr))
165
+ {
166
+ _logger->Log (LogLevel::Error, _LS (" Unable to initialize thread: 0x%08x" ), hr);
167
+ return ;
168
+ }
169
+
170
+ while (true )
171
+ {
172
+ IpcMessage message;
173
+ hr = _unmanagedOnlyQueue.BlockingDequeue (message);
174
+ if (hr != S_OK)
175
+ {
176
+ // We are complete, discard all messages
177
+ break ;
178
+ }
179
+
137
180
hr = _callback (message);
138
181
if (hr != S_OK)
139
182
{
0 commit comments