Skip to content

Commit ec163a0

Browse files
committed
Make the Plugin Interface tracing thread-safe
1 parent d2fd51c commit ec163a0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

sycl/source/detail/plugin.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <CL/sycl/detail/pi.hpp>
1313
#include <CL/sycl/stl.hpp>
1414
#include <detail/plugin_printers.hpp>
15+
#include <memory>
16+
#include <mutex>
1517

1618
#ifdef XPTI_ENABLE_INSTRUMENTATION
1719
// Include the headers necessary for emitting traces using the trace framework
@@ -33,7 +35,8 @@ class plugin {
3335
plugin() = delete;
3436

3537
plugin(RT::PiPlugin Plugin, backend UseBackend)
36-
: MPlugin(Plugin), MBackend(UseBackend) {}
38+
: MPlugin(Plugin), MBackend(UseBackend),
39+
TracingMutex(std::make_shared<std::mutex>()) {}
3740

3841
plugin &operator=(const plugin &) = default;
3942
plugin(const plugin &) = default;
@@ -73,13 +76,12 @@ class plugin {
7376
std::string PIFnName = PiCallInfo.getFuncName();
7477
uint64_t CorrelationID = pi::emitFunctionBeginTrace(PIFnName.c_str());
7578
#endif
79+
RT::PiResult R = PiCallInfo.getFuncPtr(MPlugin)(Args...);
7680
if (pi::trace(pi::TraceLevel::PI_TRACE_CALLS)) {
81+
std::lock_guard<std::mutex> Guard(*TracingMutex);
7782
std::string FnName = PiCallInfo.getFuncName();
7883
std::cout << "---> " << FnName << "(" << std::endl;
7984
RT::printArgs(Args...);
80-
}
81-
RT::PiResult R = PiCallInfo.getFuncPtr(MPlugin)(Args...);
82-
if (pi::trace(pi::TraceLevel::PI_TRACE_CALLS)) {
8385
std::cout << ") ---> ";
8486
RT::printArgs(R);
8587
RT::printOuts(Args...);
@@ -106,6 +108,7 @@ class plugin {
106108
private:
107109
RT::PiPlugin MPlugin;
108110
backend MBackend;
111+
std::shared_ptr<std::mutex> TracingMutex;
109112
}; // class plugin
110113
} // namespace detail
111114
} // namespace sycl

0 commit comments

Comments
 (0)