Skip to content

Commit f9af611

Browse files
committed
Fix MacOS build
1 parent 5a633a8 commit f9af611

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/sonyflake_turbo/sonyflake.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#include <stdbool.h>
66
#include <stdint.h>
77
#include <time.h>
8+
9+
#if !__STDC_NO_THREADS__
810
#include <threads.h>
11+
#endif
912

1013
#include "sonyflake.h"
1114
#include "machine_ids.h"
@@ -193,20 +196,30 @@ static PyObject *sonyflake_sleep(PyObject *obj, struct timespec *to_nanosleep) {
193196
int ret = 0;
194197

195198
Py_BEGIN_ALLOW_THREADS;
199+
#if __STDC_NO_THREADS__
200+
ret = nanosleep(to_nanosleep, NULL);
201+
#else
196202
ret = thrd_sleep(to_nanosleep, NULL);
203+
#endif
197204
Py_END_ALLOW_THREADS;
198205

199206
if (ret == 0) {
200207
return obj;
201208
}
202209

210+
#if __STDC_NO_THREADS__
211+
if (ret < 0 && errno == EINTR && PyErr_CheckSignals()) {
212+
goto err;
213+
}
214+
#else
203215
if (ret == -1) {
204216
if (PyErr_CheckSignals()) {
205217
goto err;
206218
}
207219

208220
return obj;
209221
}
222+
#endif
210223

211224
PyErr_SetFromErrno(PyExc_OSError);
212225
err:

0 commit comments

Comments
 (0)