Skip to content

Commit 0d48a14

Browse files
committed
Use C11 time and sleep functions
1 parent f1fdfc7 commit 0d48a14

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from setuptools import Extension, setup
66

77
options: Dict[str, Any] = {}
8-
define_macros: List[Tuple[str, Optional[str]]] = [("_POSIX_C_SOURCE", "200809L")]
8+
define_macros: List[Tuple[str, Optional[str]]] = []
99
py_limited_api: bool = not sysconfig.get_config_var("Py_GIL_DISABLED")
1010
cflags: List[str] = []
1111

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+
timespec_get(now, TIME_UTC);
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)