File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,26 @@ clear_state(module_state *state)
50
50
Py_CLEAR (state -> str_const );
51
51
}
52
52
53
+ static int
54
+ _set_initialized (_PyTime_t * initialized )
55
+ {
56
+ /* We go strictly monotonic to ensure each time is unique. */
57
+ _PyTime_t prev ;
58
+ if (_PyTime_GetMonotonicClockWithInfo (& prev , NULL ) != 0 ) {
59
+ return -1 ;
60
+ }
61
+ /* We do a busy sleep since the interval should be super short. */
62
+ _PyTime_t t ;
63
+ do {
64
+ if (_PyTime_GetMonotonicClockWithInfo (& t , NULL ) != 0 ) {
65
+ return -1 ;
66
+ }
67
+ } while (t == prev );
68
+
69
+ * initialized = t ;
70
+ return 0 ;
71
+ }
72
+
53
73
static int
54
74
init_state (module_state * state )
55
75
{
@@ -58,9 +78,7 @@ init_state(module_state *state)
58
78
state -> int_const == NULL &&
59
79
state -> str_const == NULL );
60
80
61
- state -> initialized = _PyTime_GetMonotonicClock ();
62
- if (state -> initialized == 0 ) {
63
- PyErr_SetString (PyExc_RuntimeError , "could not get current time" );
81
+ if (_set_initialized (& state -> initialized ) != 0 ) {
64
82
goto error ;
65
83
}
66
84
assert (state -> initialized > 0 );
You can’t perform that action at this time.
0 commit comments