Always use pthread_equal to compare thread IDs

This change replaces direct comparisons of Pthread thread IDs with
calls to pthread_equal.  Directly comparing thread IDs is neither
portable nor reliable since a thread ID is defined as an opaque type
that can be implemented using a structure.
This commit is contained in:
Carl Shapiro 2025-08-27 16:48:40 -07:00 committed by Guangli Dai
parent 5d5f76ee01
commit 5a634a8d0a
2 changed files with 3 additions and 2 deletions

View file

@ -220,7 +220,8 @@ static uint8_t malloc_slow_flags;
/* Used to let the initializing thread recursively allocate. */
# define NO_INITIALIZER ((unsigned long)0)
# define INITIALIZER pthread_self()
# define IS_INITIALIZER (malloc_initializer == pthread_self())
# define IS_INITIALIZER \
(pthread_equal(malloc_initializer, pthread_self()))
static pthread_t malloc_initializer = NO_INITIALIZER;
#else
# define NO_INITIALIZER false

View file

@ -528,7 +528,7 @@ tsd_init_check_recursion(tsd_init_head_t *head, tsd_init_block_t *block) {
/* Check whether this thread has already inserted into the list. */
malloc_mutex_lock(TSDN_NULL, &head->lock);
ql_foreach (iter, &head->blocks, link) {
if (iter->thread == self) {
if (pthread_equal(iter->thread, self)) {
malloc_mutex_unlock(TSDN_NULL, &head->lock);
return iter->data;
}