summaryrefslogtreecommitdiff
path: root/pthread_stop_world.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-12-30 20:44:34 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-12-30 20:44:34 +0300
commit97a45c6e245b3214d2686d2f3b191e70f5c90c97 (patch)
tree5314da1b9f3f5d2613db230378bc5b77946157ab /pthread_stop_world.c
parenta6cd81cbd4a0f41cbea04f2045b25f0601b915d0 (diff)
downloadbdwgc-97a45c6e245b3214d2686d2f3b191e70f5c90c97.tar.gz
Do not expose GC_nacl_gc_thread_self variable outside pthread_stop_world.c
(refactoring) * include/private/pthread_support.h [NACL] (GC_nacl_gc_thread_self): Remove declaration. * include/private/pthread_support.h [NACL] (GC_nacl_initialize_gc_thread): Add GC_thread argument. * pthread_stop_world.c [NACL] (GC_nacl_initialize_gc_thread): Likewise. * pthread_stop_world.c [NACL] (GC_nacl_thread_idx): Move definition down to be close to GC_nacl_gc_thread_self. * pthread_stop_world.c [NACL] (GC_nacl_gc_thread_self): Change to STATIC. * pthread_stop_world.c [NACL] (GC_nacl_initialize_gc_thread): Add assertion that GC_nacl_gc_thread_self is null on entrance; set GC_nacl_gc_thread_self to me (argument). * pthread_stop_world.c [NACL] (GC_nacl_shutdown_gc_thread): Add assertion that GC_nacl_gc_thread_self is non-null and matches the current thread; set GC_nacl_gc_thread_self value to null. * pthread_support.c [NACL] (GC_new_thread, GC_register_my_thread): Pass me (result) to GC_nacl_initialize_gc_thread() instead of setting GC_nacl_gc_thread_self variable. * pthread_support.c [NACL] (GC_unregister_my_thread_inner): Do not set value of GC_nacl_gc_thread_self variable.
Diffstat (limited to 'pthread_stop_world.c')
-rw-r--r--pthread_stop_world.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/pthread_stop_world.c b/pthread_stop_world.c
index 4099ae95..ff3c3411 100644
--- a/pthread_stop_world.c
+++ b/pthread_stop_world.c
@@ -53,11 +53,11 @@ GC_INLINE void GC_usleep(unsigned us)
#ifdef NACL
STATIC int GC_nacl_num_gc_threads = 0;
- STATIC __thread int GC_nacl_thread_idx = -1;
STATIC volatile int GC_nacl_park_threads_now = 0;
STATIC volatile pthread_t GC_nacl_thread_parker = -1;
- GC_INNER __thread GC_thread GC_nacl_gc_thread_self = NULL;
+ STATIC __thread int GC_nacl_thread_idx = -1;
+ STATIC __thread GC_thread GC_nacl_gc_thread_self = NULL;
volatile int GC_nacl_thread_parked[MAX_NACL_GC_THREADS];
int GC_nacl_thread_used[MAX_NACL_GC_THREADS];
@@ -1190,11 +1190,13 @@ GC_INNER void GC_stop_world(void)
void *table, size_t tablesize);
EXTERN_C_END
- GC_INNER void GC_nacl_initialize_gc_thread(void)
+ GC_INNER void GC_nacl_initialize_gc_thread(GC_thread me)
{
int i;
static struct nacl_irt_blockhook gc_hook;
+ GC_ASSERT(NULL == GC_nacl_gc_thread_self);
+ GC_nacl_gc_thread_self = me;
pthread_mutex_lock(&GC_nacl_thread_alloc_lock);
if (!EXPECT(GC_nacl_thread_parking_inited, TRUE)) {
BZERO(GC_nacl_thread_parked, sizeof(GC_nacl_thread_parked));
@@ -1221,6 +1223,8 @@ GC_INNER void GC_stop_world(void)
GC_INNER void GC_nacl_shutdown_gc_thread(void)
{
+ GC_ASSERT(GC_nacl_gc_thread_self != NULL
+ && GC_lookup_thread(pthread_self()) == GC_nacl_gc_thread_self);
pthread_mutex_lock(&GC_nacl_thread_alloc_lock);
GC_ASSERT(GC_nacl_thread_idx >= 0);
GC_ASSERT(GC_nacl_thread_idx < MAX_NACL_GC_THREADS);
@@ -1229,6 +1233,7 @@ GC_INNER void GC_stop_world(void)
GC_nacl_thread_idx = -1;
GC_nacl_num_gc_threads--;
pthread_mutex_unlock(&GC_nacl_thread_alloc_lock);
+ GC_nacl_gc_thread_self = NULL;
}
#else /* !NACL */