summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-10-13 23:49:01 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-11-14 22:01:35 +0300
commit50e4e7b3ca1737be718dc9a620eeb1e2d360d7d5 (patch)
tree5f0b03f288d9347af9d35b53a23f38529aba8d44
parent3607a595f433d6dd4aead7520de6b13b1124688c (diff)
downloadbdwgc-50e4e7b3ca1737be718dc9a620eeb1e2d360d7d5.tar.gz
Fix double initialization of main thread local free lists on Win32
(a cherry-pick of commit 4b101ee06 from 'release-8_2') * win32_threads.c [THREAD_LOCAL_ALLOC] (GC_register_my_thread_inner): Update comment; do not call GC_init_thread_local(). * win32_threads.c [THREAD_LOCAL_ALLOC] (GC_register_my_thread): Call GC_init_thread_local() both after GC_register_my_thread_inner() and GC_record_stack_base() calls (in case of return GC_SUCCESS). * win32_threads.c [GC_PTHREADS && THREAD_LOCAL_ALLOC] (GC_pthread_start_inner): Call GC_init_thread_local().
-rw-r--r--win32_threads.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/win32_threads.c b/win32_threads.c
index f3edc34f..3e04445d 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -417,6 +417,7 @@ GC_INLINE void GC_record_stack_base(GC_vthread me,
/* GC_win32_dll_threads is set. Always called from the thread being */
/* added. If GC_win32_dll_threads is not set, we already hold the */
/* allocation lock except possibly during single-threaded startup code. */
+/* Does not initialize thread local free lists. */
STATIC GC_thread GC_register_my_thread_inner(const struct GC_stack_base *sb,
DWORD thread_id)
{
@@ -507,9 +508,6 @@ STATIC GC_thread GC_register_my_thread_inner(const struct GC_stack_base *sb,
/* Up until this point, this entry is viewed as reserved but invalid */
/* by GC_delete_thread. */
me -> id = thread_id;
-# if defined(THREAD_LOCAL_ALLOC)
- GC_init_thread_local((GC_tlfs)(&(me->tlfs)));
-# endif
# ifndef GC_NO_THREADS_DISCOVERY
if (GC_win32_dll_threads) {
if (GC_please_stop) {
@@ -801,32 +799,31 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
LOCK();
me = GC_lookup_thread_inner(thread_id);
if (me == 0) {
+ me = GC_register_my_thread_inner(sb, thread_id);
# ifdef GC_PTHREADS
- me = GC_register_my_thread_inner(sb, thread_id);
me -> flags |= DETACHED;
/* Treat as detached, since we do not need to worry about */
/* pointer results. */
# else
- GC_register_my_thread_inner(sb, thread_id);
+ (void)me;
# endif
- UNLOCK();
- return GC_SUCCESS;
} else
# ifdef GC_PTHREADS
/* else */ if ((me -> flags & FINISHED) != 0) {
GC_record_stack_base(me, sb);
me -> flags &= ~FINISHED; /* but not DETACHED */
-# ifdef THREAD_LOCAL_ALLOC
- GC_init_thread_local((GC_tlfs)(&me->tlfs));
-# endif
- UNLOCK();
- return GC_SUCCESS;
} else
# endif
/* else */ {
UNLOCK();
return GC_DUPLICATE;
}
+
+# ifdef THREAD_LOCAL_ALLOC
+ GC_init_thread_local(&me->tlfs);
+# endif
+ UNLOCK();
+ return GC_SUCCESS;
}
#ifdef GC_DISABLE_INCREMENTAL
@@ -2885,6 +2882,9 @@ GC_INNER void GC_thr_init(void)
GC_ASSERT(me != &first_thread);
me -> pthread_id = pthread_id;
if (si->detached) me -> flags |= DETACHED;
+# ifdef THREAD_LOCAL_ALLOC
+ GC_init_thread_local(&me->tlfs);
+# endif
UNLOCK();
start = si -> start_routine;