Skip to content

Commit e76778d

Browse files
committed
missing headers, avoid naming clash with unistd.h
1 parent 7ce0e33 commit e76778d

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

include/nanothread/nanothread.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
#include <stddef.h>
1414
#include <stdio.h>
1515

16-
#if !defined(__cplusplus)
17-
#include <stdbool.h>
16+
#if defined(__cplusplus)
17+
# include <type_traits>
18+
#else
19+
# include <stdbool.h>
1820
#endif
1921

2022
#if defined(NANOTHREAD_STATIC)

src/queue.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define NANOTHREAD_MAX_ATTEMPTS 500000
2727

2828
/// Reduce power usage in busy-wait CAS loops
29-
static void pause() {
29+
static void cas_pause() {
3030
#if defined(_M_X64) || defined(__SSE2__)
3131
_mm_pause();
3232
#endif
@@ -137,7 +137,7 @@ Task *TaskQueue::alloc(uint32_t size) {
137137
if (cas(recycle, node, node.update_task(next.task)))
138138
break;
139139

140-
pause();
140+
cas_pause();
141141
}
142142

143143
Task *task;
@@ -236,7 +236,7 @@ void TaskQueue::release(Task *task, bool high) {
236236
if (cas(recycle, node, node.update_task(task)))
237237
break;
238238

239-
pause();
239+
cas_pause();
240240
}
241241
}
242242
}
@@ -272,7 +272,7 @@ void TaskQueue::add_dependency(Task *parent, Task *child) {
272272
std::memory_order_relaxed))
273273
break;
274274

275-
pause();
275+
cas_pause();
276276
}
277277

278278
// Otherwise, register the child task with the parent
@@ -321,7 +321,7 @@ void TaskQueue::push(Task *task) {
321321
}
322322
}
323323

324-
pause();
324+
cas_pause();
325325
}
326326

327327
// Wake sleeping threads, if any
@@ -368,7 +368,7 @@ std::pair<Task *, uint32_t> TaskQueue::pop() {
368368
if (!next_c.task) {
369369
task = nullptr;
370370
index = 0;
371-
pause();
371+
cas_pause();
372372
break;
373373
} else {
374374
// Advance the tail, it's falling behind
@@ -377,7 +377,7 @@ std::pair<Task *, uint32_t> TaskQueue::pop() {
377377
}
378378
}
379379

380-
pause();
380+
cas_pause();
381381
}
382382

383383
if (task) {
@@ -462,7 +462,7 @@ TaskQueue::pop_or_sleep(bool (*stopping_criterion)(void *), void *payload,
462462
break;
463463
if ((value & high_mask) != phase)
464464
break;
465-
pause();
465+
cas_pause();
466466
}
467467
break;
468468
}

src/queue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <atomic>
1313
#include <vector>
1414
#include <condition_variable>
15+
#include <type_traits>
16+
#include <exception>
1517
#include <cstring>
1618
#include <cstdlib>
1719

0 commit comments

Comments
 (0)