Skip to content

Commit 1ec10ef

Browse files
committed
Fix UnitTests on Linux
1 parent ebb304b commit 1ec10ef

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

RadeonRays/src/accelerator/bvh2.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,14 @@ THE SOFTWARE.
2828
#define PARALLEL_BUILD
2929

3030
// Macro for allocating 16-byte aligned stack memory
31-
#define STACK_ALLOC(COUNT, TYPE) static_cast<TYPE *>(Align(16, (COUNT) * sizeof(TYPE), alloca(RoundUp(16, (COUNT) * sizeof(TYPE)))))
31+
#define STACK_ALLOC(COUNT, TYPE) static_cast<TYPE *>(Align(16u, (COUNT) * sizeof(TYPE), (COUNT) * sizeof(TYPE) + 15u, alloca((COUNT) * sizeof(TYPE) + 15u)))
3232

3333
namespace RadeonRays
3434
{
3535
inline
36-
std::size_t RoundUp(std::size_t alignment, std::size_t size)
36+
void *Align(std::size_t alignment, std::size_t size, std::size_t space, void *ptr)
3737
{
38-
return (size + alignment - 1) & ~(alignment - 1);
39-
}
40-
41-
inline
42-
void *Align(std::size_t alignment, std::size_t size, void *ptr)
43-
{
44-
std::size_t space;
45-
void *aligned_ptr = std::align(alignment, RoundUp(alignment, size), ptr, space);
46-
return aligned_ptr;
38+
return std::align(alignment, size, ptr, space);
4739
}
4840

4941
#ifdef __GNUC__
@@ -225,16 +217,21 @@ namespace RadeonRays
225217
}
226218
}
227219
#else
228-
std::mutex mutex;
220+
// Parallel build variables
221+
// Global requests stack
222+
std::stack<SplitRequest> requests;
223+
// Condition to wait on the global stack
229224
std::condition_variable cv;
230-
std::atomic_bool shutdown;
225+
// Mutex to guard cv
226+
std::mutex mutex;
227+
// Indicates if we need to shutdown all the threads
228+
std::atomic<bool> shutdown;
229+
// Number of primitives processed so far
231230
std::atomic<std::uint32_t> num_refs_processed;
232231

233232
num_refs_processed.store(0);
234233
shutdown.store(false);
235234

236-
std::stack<SplitRequest> requests;
237-
238235
requests.push(SplitRequest{
239236
scene_min,
240237
scene_max,
@@ -311,16 +308,23 @@ namespace RadeonRays
311308

312309
for (auto i = 0u; i < num_threads; ++i)
313310
{
314-
threads[i] = std::move(std::thread(worker_thread));
315-
threads[i].detach();
311+
threads[i] = std::thread(worker_thread);
316312
}
317313

318314
while (num_refs_processed != num_aabbs)
319315
{
320316
std::this_thread::sleep_for(std::chrono::milliseconds(20));
321317
}
322318

323-
shutdown = true;
319+
// Signal shutdown and wake up all the threads
320+
shutdown.store(true);
321+
cv.notify_all();
322+
323+
// Wait for all the threads to finish
324+
for (auto i = 0u; i < num_threads; ++i)
325+
{
326+
threads[i].join();
327+
}
324328
#endif
325329
}
326330

0 commit comments

Comments
 (0)