Skip to content

Commit 50f6c54

Browse files
gwoltmanpreda
authored andcommitted
At Mihai's suggestion, use a portable method to sleep N microseconds.
1 parent 75dd76b commit 50f6c54

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Queue.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "log.h"
88

99
#include <cassert>
10+
#include <chrono>
11+
#include <thread>
1012

1113
void Events::clearCompleted() { while (!empty() && front().isComplete()) { pop_front(); } }
1214

@@ -101,11 +103,8 @@ void Queue::waitForMarkerEvent() {
101103
// By default, nVidia finish causes a CPU busy wait. Instead, sleep for a while. Since we know how many items are enqueued after the marker we can make an
102104
// educated guess of how long to sleep to keep CPU overhead low.
103105
while (getEventInfo(markerEvent) != CL_COMPLETE) {
104-
#if defined(__CYGWIN__)
105-
sleep(1); // 1 second. A very steep overhead as 500 iterations won't take that long.
106-
#else
107-
usleep(1 + queueCount * squareTime / 10); // There are 4 kernels per squaring. Don't overestimate sleep time. Divide by 10 instead of 4.
108-
#endif
106+
// There are 4 kernels per squaring. Don't overestimate sleep time. Divide by 10 instead of 4.
107+
std::this_thread::sleep_for(std::chrono::microseconds(1 + queueCount * squareTime / 10));
109108
}
110109
markerQueued = false;
111110
}

0 commit comments

Comments
 (0)