Skip to content

Commit c3683aa

Browse files
committed
Use C11 time and sleep functions
1 parent 36c54a1 commit c3683aa

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/sonyflake_turbo/sonyflake.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stdbool.h>
66
#include <stdint.h>
77
#include <time.h>
8+
#include <threads.h>
89

910
#include "sonyflake.h"
1011
#include "machine_ids.h"
@@ -34,7 +35,7 @@ bool incr_combined_sequence(struct sonyflake_state *self) {
3435
}
3536

3637
static inline void get_relative_current_time(struct sonyflake_state *self, struct timespec *now) {
37-
clock_gettime(CLOCK_REALTIME, now);
38+
assert(timespec_get(now, TIME_UTC) != 0);
3839
sub_diff(now, &self->start_time);
3940
}
4041

@@ -329,7 +330,7 @@ static PyObject *sonyflake_iternext(struct sonyflake_state *self) {
329330

330331
if (sonyflake_id && to_nanosleep.tv_sec == 0 && to_nanosleep.tv_nsec == 0) {
331332
Py_BEGIN_ALLOW_THREADS;
332-
nanosleep(&to_nanosleep, NULL);
333+
thrd_sleep(&to_nanosleep, NULL);
333334
Py_END_ALLOW_THREADS;
334335
}
335336

@@ -353,7 +354,7 @@ static PyObject *sonyflake_call(struct sonyflake_state *self, PyObject *args) {
353354

354355
if (sonyflake_ids && to_nanosleep.tv_sec == 0 && to_nanosleep.tv_nsec == 0) {
355356
Py_BEGIN_ALLOW_THREADS;
356-
nanosleep(&to_nanosleep, NULL);
357+
thrd_sleep(&to_nanosleep, NULL);
357358
Py_END_ALLOW_THREADS;
358359
}
359360

0 commit comments

Comments
 (0)