@@ -35,15 +35,11 @@ extern "C" {
3535#define BACKOFF_MASK 7
3636#define MAX_BACKOFF 6
3737#define UNREACHABLE_BACKOFF 7
38+ #define MAX_VALUE 0x1FFF
3839
3940#define MAKE_VALUE_AND_BACKOFF (value , backoff ) \
4041 ((value << BACKOFF_BITS) | backoff)
4142
42- #define MAKE_BACKOFF_COUNTER (value , backoff ) \
43- ((_Py_BackoffCounter){ \
44- .value_and_backoff = MAKE_VALUE_AND_BACKOFF(value, backoff) \
45- })
46-
4743// We only use values x and backoffs b such that
4844// x + 1 is near to 2**(2*b+1) and x + 1 is prime.
4945static uint16_t value_and_backoff_next [] = {
@@ -58,6 +54,16 @@ static uint16_t value_and_backoff_next[] = {
5854 MAKE_VALUE_AND_BACKOFF (8190 , 6 ),
5955};
6056
57+ static inline _Py_BackoffCounter
58+ make_backoff_counter (uint16_t value , uint16_t backoff )
59+ {
60+ assert (backoff <= UNREACHABLE_BACKOFF );
61+ assert (value <= MAX_VALUE );
62+ return ((_Py_BackoffCounter ){
63+ .value_and_backoff = MAKE_VALUE_AND_BACKOFF (value , backoff )
64+ });
65+ }
66+
6167static inline _Py_BackoffCounter
6268restart_backoff_counter (_Py_BackoffCounter counter )
6369{
@@ -113,7 +119,7 @@ trigger_backoff_counter(void)
113119static inline _Py_BackoffCounter
114120initial_jump_backoff_counter (void )
115121{
116- return MAKE_BACKOFF_COUNTER (JUMP_BACKWARD_INITIAL_VALUE ,
122+ return make_backoff_counter (JUMP_BACKWARD_INITIAL_VALUE ,
117123 JUMP_BACKWARD_INITIAL_BACKOFF );
118124}
119125
@@ -127,15 +133,15 @@ initial_jump_backoff_counter(void)
127133static inline _Py_BackoffCounter
128134initial_temperature_backoff_counter (void )
129135{
130- return MAKE_BACKOFF_COUNTER (SIDE_EXIT_INITIAL_VALUE ,
136+ return make_backoff_counter (SIDE_EXIT_INITIAL_VALUE ,
131137 SIDE_EXIT_INITIAL_BACKOFF );
132138}
133139
134140/* Unreachable backoff counter. */
135141static inline _Py_BackoffCounter
136142initial_unreachable_backoff_counter (void )
137143{
138- return MAKE_BACKOFF_COUNTER (0 , UNREACHABLE_BACKOFF );
144+ return make_backoff_counter (0 , UNREACHABLE_BACKOFF );
139145}
140146
141147#ifdef __cplusplus
0 commit comments