mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-34297 get_rnd_value() of ib_counter_t is unnecessarily complex
The shared counter template ib_counter_t uses the function my_timer_cycles() as a source of pseudo-random numbers to pick a shard. On some platforms, my_timer_cycles() could return the constant value 0. get_rnd_value(): Remove. my_pseudo_random(): Implement as an alias of my_timer_cycles() or a wrapper for pthread_self(). Reviewed by: Vladislav Vaintroub
This commit is contained in:
@@ -177,10 +177,23 @@ static inline ulonglong my_timer_cycles(void)
|
||||
/* gethrtime may appear as either cycle or nanosecond counter */
|
||||
return (ulonglong) gethrtime();
|
||||
#else
|
||||
# define MY_TIMER_CYCLES_IS_ZERO
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MY_TIMER_CYCLES_IS_ZERO
|
||||
static inline size_t my_pseudo_random(void)
|
||||
{
|
||||
/* In some platforms, pthread_self() might return a structure
|
||||
that cannot be converted to a number like this. Possible alternatives
|
||||
could include gettid() or sched_getcpu(). */
|
||||
return ((size_t) pthread_self()) / 16;
|
||||
}
|
||||
#else
|
||||
# define my_pseudo_random my_timer_cycles
|
||||
#endif
|
||||
|
||||
/**
|
||||
A nanosecond timer.
|
||||
@return the current timer value, in nanoseconds.
|
||||
|
Reference in New Issue
Block a user