summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-03-10 07:59:13 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-03-10 12:00:33 +0300
commitcf0689ec6ec2e5e9b975a2c3626fef42006b7d62 (patch)
tree49694421c5b9419159a89bc617137a6d271f6737
parent5a8c02852532169ad81a87b553dc5fb3142d9e61 (diff)
downloadbdwgc-cf0689ec6ec2e5e9b975a2c3626fef42006b7d62.tar.gz
Move platform-dependent getspecific() call to a dedicated function
(refactoring) * include/private/thread_local_alloc.h: Reformat comment. * pthread_stop_world.c [NACL] (GC_nacl_gc_thread_sel): Add TODO item. * pthread_support.c (GC_thread_is_registered): Likewise. * thread_local_alloc.c [THREAD_LOCAL_ALLOC] (GC_get_tlfs): New STATIC function (move part of code from GC_malloc_kind). * thread_local_alloc.c [THREAD_LOCAL_ALLOC] (GC_malloc_kind): Use GC_get_tlfs().
-rw-r--r--include/private/thread_local_alloc.h2
-rw-r--r--pthread_stop_world.c2
-rw-r--r--pthread_support.c1
-rw-r--r--thread_local_alloc.c39
4 files changed, 24 insertions, 20 deletions
diff --git a/include/private/thread_local_alloc.h b/include/private/thread_local_alloc.h
index 12048209..aaf14213 100644
--- a/include/private/thread_local_alloc.h
+++ b/include/private/thread_local_alloc.h
@@ -15,7 +15,7 @@
/* This is the interface for thread-local allocation, whose */
/* implementation is mostly thread-library-independent. */
/* Here we describe only the interface that needs to be known */
-/* and invoked from the thread support layer; the actual */
+/* and invoked from the thread support layer; the actual */
/* implementation also exports GC_malloc and friends, which */
/* are declared in gc.h. */
diff --git a/pthread_stop_world.c b/pthread_stop_world.c
index 3db01761..f1ff6ea2 100644
--- a/pthread_stop_world.c
+++ b/pthread_stop_world.c
@@ -57,7 +57,9 @@ GC_INLINE void GC_usleep(unsigned us)
STATIC volatile pthread_t GC_nacl_thread_parker = -1;
STATIC __thread int GC_nacl_thread_idx = -1;
+
STATIC __thread GC_thread GC_nacl_gc_thread_self = NULL;
+ /* TODO: Use GC_get_tlfs() instead. */
volatile int GC_nacl_thread_parked[MAX_NACL_GC_THREADS];
int GC_nacl_thread_used[MAX_NACL_GC_THREADS];
diff --git a/pthread_support.c b/pthread_support.c
index 1bd48eab..ad952256 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -856,6 +856,7 @@ STATIC GC_thread GC_self_thread(void) {
GC_API int GC_CALL GC_thread_is_registered(void)
{
+ /* TODO: Use GC_get_tlfs() instead. */
GC_thread me = GC_self_thread();
return me != NULL && !KNOWN_FINISHED(me);
diff --git a/thread_local_alloc.c b/thread_local_alloc.c
index 3e7681f1..5c73c8b0 100644
--- a/thread_local_alloc.c
+++ b/thread_local_alloc.c
@@ -143,6 +143,24 @@ GC_INNER void GC_destroy_thread_local(GC_tlfs p)
# endif
}
+STATIC void *GC_get_tlfs(void)
+{
+# if !defined(USE_PTHREAD_SPECIFIC) && !defined(USE_WIN32_SPECIFIC)
+ GC_key_t k = GC_thread_key;
+
+ if (EXPECT(0 == k, FALSE)) {
+ /* We have not yet run GC_init_parallel. That means we also */
+ /* are not locking, so GC_malloc_kind_global is fairly cheap. */
+ return NULL;
+ }
+ return GC_getspecific(k);
+# else
+ if (EXPECT(!keys_initialized, FALSE)) return NULL;
+
+ return GC_getspecific(GC_thread_key);
+# endif
+}
+
GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_kind(size_t bytes, int kind)
{
size_t granules;
@@ -154,27 +172,10 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_kind(size_t bytes, int kind)
return GC_malloc_kind_global(bytes, kind);
}
# endif
-# if !defined(USE_PTHREAD_SPECIFIC) && !defined(USE_WIN32_SPECIFIC)
- {
- GC_key_t k = GC_thread_key;
-
- if (EXPECT(0 == k, FALSE)) {
- /* We haven't yet run GC_init_parallel. That means */
- /* we also aren't locking, so this is fairly cheap. */
+ tsd = GC_get_tlfs();
+ if (EXPECT(NULL == tsd, FALSE)) {
return GC_malloc_kind_global(bytes, kind);
- }
- tsd = GC_getspecific(k);
}
-# else
- if (!EXPECT(keys_initialized, TRUE))
- return GC_malloc_kind_global(bytes, kind);
- tsd = GC_getspecific(GC_thread_key);
-# endif
-# if !defined(USE_COMPILER_TLS) && !defined(USE_WIN32_COMPILER_TLS)
- if (EXPECT(0 == tsd, FALSE)) {
- return GC_malloc_kind_global(bytes, kind);
- }
-# endif
GC_ASSERT(GC_is_initialized);
GC_ASSERT(GC_is_thread_tsd_valid(tsd));
granules = ROUNDED_UP_GRANULES(bytes);