Skip to content

Commit bd119a9

Browse files
committed
Resolve deadlock caused by cyclic call
1 parent a722227 commit bd119a9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

sycl/source/detail/scheduler/scheduler.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ void Scheduler::cleanupFinishedCommands(EventImplPtr FinishedEvent) {
189189
if (FinishedCmd)
190190
MGraphBuilder.cleanupFinishedCommands(FinishedCmd, StreamsToDeallocate);
191191
}
192-
deallocateStreams(StreamsToDeallocate);
193192
}
193+
deallocateStreams(StreamsToDeallocate);
194194
}
195195

196196
void Scheduler::removeMemoryObject(detail::SYCLMemObjI *MemObj) {
@@ -226,9 +226,9 @@ void Scheduler::removeMemoryObject(detail::SYCLMemObjI *MemObj) {
226226
MGraphBuilder.decrementLeafCountersForRecord(Record);
227227
MGraphBuilder.cleanupCommandsForRecord(Record, StreamsToDeallocate);
228228
MGraphBuilder.removeRecordForMemObj(MemObj);
229-
deallocateStreams(StreamsToDeallocate);
230229
}
231230
}
231+
deallocateStreams(StreamsToDeallocate);
232232
}
233233

234234
EventImplPtr Scheduler::addHostAccessor(Requirement *Req) {
@@ -276,13 +276,13 @@ void Scheduler::enqueueLeavesOfReqUnlocked(const Requirement *const Req) {
276276
void Scheduler::allocateStreamBuffers(stream_impl *Impl,
277277
size_t StreamBufferSize,
278278
size_t FlushBufferSize) {
279-
std::lock_guard<std::mutex> lock(StreamBuffersPoolMutex);
279+
std::lock_guard<std::recursive_mutex> lock(StreamBuffersPoolMutex);
280280
StreamBuffersPool.insert(
281281
{Impl, new StreamBuffers(StreamBufferSize, FlushBufferSize)});
282282
}
283283

284284
void Scheduler::deallocateStreamBuffers(stream_impl *Impl) {
285-
std::lock_guard<std::mutex> lock(StreamBuffersPoolMutex);
285+
std::lock_guard<std::recursive_mutex> lock(StreamBuffersPoolMutex);
286286
delete StreamBuffersPool[Impl];
287287
StreamBuffersPool.erase(Impl);
288288
}
@@ -302,7 +302,7 @@ Scheduler::~Scheduler() {
302302
// the kernel. Otherwise resources for stream will not be released, issue a
303303
// warning in this case.
304304
if (pi::trace(pi::TraceLevel::PI_TRACE_BASIC)) {
305-
std::lock_guard<std::mutex> lock(StreamBuffersPoolMutex);
305+
std::lock_guard<std::recursive_mutex> lock(StreamBuffersPoolMutex);
306306
if (!StreamBuffersPool.empty())
307307
fprintf(
308308
stderr,

sycl/source/detail/scheduler/scheduler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ class Scheduler {
766766
friend class stream_impl;
767767

768768
// Protects stream buffers pool
769-
std::mutex StreamBuffersPoolMutex;
769+
std::recursive_mutex StreamBuffersPoolMutex;
770770

771771
// We need to store a pointer to the structure with stream buffers because we
772772
// want to avoid a situation when buffers are destructed during destruction of

0 commit comments

Comments
 (0)