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)
5050 Py_CLEAR (state -> str_const );
5151}
5252
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+
5373static int
5474init_state (module_state * state )
5575{
@@ -58,9 +78,7 @@ init_state(module_state *state)
5878 state -> int_const == NULL &&
5979 state -> str_const == NULL );
6080
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 ) {
6482 goto error ;
6583 }
6684 assert (state -> initialized > 0 );
You can’t perform that action at this time.
0 commit comments