@@ -67,9 +67,13 @@ EventImplPtr Scheduler::addCG(std::unique_ptr<detail::CG> CommandGroup,
67
67
const bool IsKernel = CommandGroup->getType () == CG::KERNEL;
68
68
{
69
69
std::unique_lock<std::shared_timed_mutex> Lock (MGraphLock, std::defer_lock);
70
+ #ifdef _WIN32
70
71
while (!Lock.owns_lock ()) {
71
72
Lock.try_lock ();
72
73
}
74
+ #else
75
+ Lock.lock ();
76
+ #endif // _WIN32
73
77
74
78
switch (CommandGroup->getType ()) {
75
79
case CG::UPDATE_HOST:
@@ -95,9 +99,13 @@ EventImplPtr Scheduler::addCG(std::unique_ptr<detail::CG> CommandGroup,
95
99
96
100
EventImplPtr Scheduler::addCopyBack (Requirement *Req) {
97
101
std::unique_lock<std::shared_timed_mutex> Lock (MGraphLock, std::defer_lock);
102
+ #ifdef _WIN32
98
103
while (!Lock.owns_lock ()) {
99
104
Lock.try_lock ();
100
105
}
106
+ #else
107
+ Lock.lock ();
108
+ #endif // _WIN32
101
109
Command *NewCmd = MGraphBuilder.addCopyBack (Req);
102
110
// Command was not creted because there were no operations with
103
111
// buffer.
@@ -154,9 +162,13 @@ void Scheduler::cleanupFinishedCommands(EventImplPtr FinishedEvent) {
154
162
155
163
void Scheduler::removeMemoryObject (detail::SYCLMemObjI *MemObj) {
156
164
std::unique_lock<std::shared_timed_mutex> Lock (MGraphLock, std::defer_lock);
165
+ #ifdef _WIN32
157
166
while (!Lock.owns_lock ()) {
158
167
Lock.try_lock ();
159
168
}
169
+ #else
170
+ Lock.lock ();
171
+ #endif // _WIN32
160
172
161
173
MemObjRecord *Record = MGraphBuilder.getMemObjRecord (MemObj);
162
174
if (!Record)
@@ -170,14 +182,20 @@ void Scheduler::removeMemoryObject(detail::SYCLMemObjI *MemObj) {
170
182
171
183
EventImplPtr Scheduler::addHostAccessor (Requirement *Req,
172
184
const bool destructor) {
185
+ std::unique_lock<std::shared_timed_mutex> Lock (MGraphLock, std::defer_lock);
173
186
// Avoiding deadlock situation for MSVC. std::shared_timed_mutex specification
174
187
// does not specify a priority for shared and exclusive accesses. It will be a
175
188
// deadlock in MSVC's std::shared_timed_mutex implementation, if exclusive
176
189
// access occurs after shared access.
177
- std::unique_lock<std::shared_timed_mutex> Lock (MGraphLock, std::defer_lock);
190
+ // TODO: after switching to C++17, change std::shared_timed_mutex to
191
+ // std::shared_mutex and use std::lock_guard here both for Windows and Linux.
192
+ #ifdef _WIN32
178
193
while (!Lock.owns_lock ()) {
179
194
Lock.try_lock ();
180
195
}
196
+ #else
197
+ Lock.lock ();
198
+ #endif // _WIN32
181
199
182
200
Command *NewCmd = MGraphBuilder.addHostAccessor (Req, destructor);
183
201
@@ -191,8 +209,8 @@ EventImplPtr Scheduler::addHostAccessor(Requirement *Req,
191
209
}
192
210
193
211
void Scheduler::releaseHostAccessor (Requirement *Req) {
194
- std::shared_lock<std::shared_timed_mutex> Lock (MGraphLock);
195
212
Req->MBlockedCmd ->MEnqueueStatus = EnqueueResultT::SyclEnqueueReady;
213
+ std::shared_lock<std::shared_timed_mutex> Lock (MGraphLock);
196
214
MemObjRecord *Record = Req->MSYCLMemObj ->MRecord .get ();
197
215
auto EnqueueLeaves = [](CircularBuffer<Command *> &Leaves) {
198
216
for (Command *Cmd : Leaves) {
0 commit comments