From 510fb9f634b3374da6de7f6849e0a4f44f945723 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 8 May 2018 21:36:41 +0300 Subject: Keep pointer to the start of previous entry in remove_specific_after_fork (code refactoring) * specific.c [USE_CUSTOM_SPECIFIC] (GC_remove_specific_after_fork): Replace tse** link local variable with tse* prev one; replace *link with either key->hash[hash_val].p or prev->next. --- specific.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'specific.c') diff --git a/specific.c b/specific.c index 954b2156..d0bda44b 100644 --- a/specific.c +++ b/specific.c @@ -81,7 +81,7 @@ GC_INNER void GC_remove_specific_after_fork(tsd * key, pthread_t t) { unsigned hash_val = HASH(t); tse *entry; - tse **link = &key->hash[hash_val].p; + tse *prev = NULL; # ifdef CAN_HANDLE_FORK /* Both GC_setspecific and GC_remove_specific should be called */ @@ -90,16 +90,20 @@ GC_INNER void GC_remove_specific_after_fork(tsd * key, pthread_t t) GC_ASSERT(I_HOLD_LOCK()); # endif pthread_mutex_lock(&(key -> lock)); - entry = *link; + entry = key->hash[hash_val].p; while (entry != NULL && !THREAD_EQUAL(entry->thread, t)) { - link = &(entry -> next); - entry = *link; + prev = entry; + entry = entry->next; } /* Invalidate qtid field, since qtids may be reused, and a later */ /* cache lookup could otherwise find this entry. */ if (entry != NULL) { entry -> qtid = INVALID_QTID; - *link = entry -> next; + if (NULL == prev) { + key->hash[hash_val].p = entry->next; + } else { + prev->next = entry->next; + } /* Atomic! concurrent accesses still work. */ /* They must, since readers don't lock. */ /* We shouldn't need a volatile access here, */ -- cgit v1.2.1