From 272283d5b0ebf35326187c12973ee540c19eae67 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 26 Feb 2018 22:03:30 +0300 Subject: [PATCH] Always include gc_atomic_ops.h unless threads are disabled (code refactoring) * include/private/gc_atomic_ops.h [!GC_BUILTIN_ATOMIC]: Issue #error if AO_HAVE_load or AO_HAVE_store is not defined after include atomic_ops.h. * include/private/gc_locks.h: Do not include gc_atomic_ops.h. * include/private/specific.h: Likewise. * pthread_stop_world.c: Likewise. * tests/test.c [THREADS && (GC_BUILTIN_ATOMIC || PARALLEL_MARK || !GC_WIN32_THREADS)]: Likewise. * thread_local_alloc.c: Likewise. * typd_mlc.c [GC_FORCE_INCLUDE_ATOMIC_OPS || GC_BUILTIN_ATOMIC]: Likewise. * win32_threads.c [(GC_DLL || GC_INSIDE_DLL) && !THREAD_LOCAL_ALLOC && !GC_NO_THREADS_DISCOVERY && !MSWINCE && !GC_PTHREADS]: Likewise. * include/private/gc_priv.h [THREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2]: Include gc_atomic_ops.h (after GC_INLINE definition). * include/private/gc_priv.h (counter_t): Do not define. * include/private/gc_priv.h (hblkhdr): Change type of hb_n_marks to either volatile AO_t (if PARALLEL_MARK) or size_t * mark.c (GC_noop6): Check AO_CLEAR macro presence instead of GC_PTHREADS and !GC_WIN32_THREADS or PARALLEL_MARK. * tests/test_atomic_ops.c [_WIN32 || _MSC_VER || __CYGWIN__ || __MINGW32__] (main): Do not skip the test. --- include/private/gc_atomic_ops.h | 4 ++++ include/private/gc_locks.h | 5 ----- include/private/gc_priv.h | 22 +++++++++------------- include/private/specific.h | 2 -- mark.c | 3 +-- pthread_stop_world.c | 2 -- tests/test.c | 6 ------ tests/test_atomic_ops.c | 4 +--- thread_local_alloc.c | 2 -- typd_mlc.c | 4 ---- win32_threads.c | 1 - 11 files changed, 15 insertions(+), 40 deletions(-) diff --git a/include/private/gc_atomic_ops.h b/include/private/gc_atomic_ops.h index 3bdf5647..9b585ec5 100644 --- a/include/private/gc_atomic_ops.h +++ b/include/private/gc_atomic_ops.h @@ -101,6 +101,10 @@ /* only if AO_REQUIRE_CAS is defined (or if the corresponding */ /* AO_HAVE_x macro is defined). x86/x64 targets have AO_nop_full, */ /* AO_load_acquire, AO_store_release, at least. */ +# if !defined(AO_HAVE_load) || !defined(AO_HAVE_store) +# error AO_load or AO_store is missing; probably old version of atomic_ops +# endif + #endif /* !GC_BUILTIN_ATOMIC */ #endif /* GC_ATOMIC_OPS_H */ diff --git a/include/private/gc_locks.h b/include/private/gc_locks.h index 5657606a..fad4ad2d 100644 --- a/include/private/gc_locks.h +++ b/include/private/gc_locks.h @@ -28,11 +28,6 @@ */ # ifdef THREADS -# if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS) \ - && !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) -# include "gc_atomic_ops.h" -# endif - # ifdef PCR # include # include diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index a7a6bdf7..156bee5a 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -250,6 +250,10 @@ typedef char * ptr_t; /* A generic pointer to which we can add */ # define GC_API_PRIV GC_API #endif +#if defined(THREADS) && !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) +# include "gc_atomic_ops.h" +#endif + #ifndef GC_LOCKS_H # include "gc_locks.h" #endif @@ -754,17 +758,6 @@ GC_EXTERN GC_warn_proc GC_current_warn_proc; # endif #endif /* DARWIN */ -#ifdef PARALLEL_MARK -# include "gc_atomic_ops.h" -# define counter_t volatile AO_t -#else - typedef size_t counter_t; -# if defined(THREADS) && (defined(MPROTECT_VDB) || defined(THREAD_SANITIZER) \ - || (defined(GC_ASSERTIONS) && defined(THREAD_LOCAL_ALLOC))) -# include "gc_atomic_ops.h" -# endif -#endif /* !PARALLEL_MARK */ - #include "../gc_tiny_fl.h" #include @@ -1090,7 +1083,8 @@ struct hblkhdr { /* mod BYTES_TO_GRANULES(hb_sz), except */ /* for large blocks. See GC_obj_map. */ # endif - counter_t hb_n_marks; /* Number of set mark bits, excluding */ +# ifdef PARALLEL_MARK + volatile AO_t hb_n_marks; /* Number of set mark bits, excluding */ /* the one always set at the end. */ /* Currently it is concurrently */ /* updated and hence only approximate. */ @@ -1108,8 +1102,10 @@ struct hblkhdr { /* The count may also be too high if */ /* multiple mark threads mark the */ /* same object due to a race. */ - /* Without parallel marking, the count */ +# else + size_t hb_n_marks; /* Without parallel marking, the count */ /* is accurate. */ +# endif # ifdef USE_MARK_BYTES # define MARK_BITS_SZ (MARK_BITS_PER_HBLK + 1) /* Unlike the other case, this is in units of bytes. */ diff --git a/include/private/specific.h b/include/private/specific.h index ab864750..1367a252 100644 --- a/include/private/specific.h +++ b/include/private/specific.h @@ -14,8 +14,6 @@ #include -#include "gc_atomic_ops.h" - /* Note: never put extern "C" around an #include. */ #ifdef __cplusplus extern "C" { diff --git a/mark.c b/mark.c index b4f448b1..8347bfc5 100644 --- a/mark.c +++ b/mark.c @@ -40,8 +40,7 @@ void GC_noop6(word arg1 GC_ATTR_UNUSED, word arg2 GC_ATTR_UNUSED, word arg5 GC_ATTR_UNUSED, word arg6 GC_ATTR_UNUSED) { /* Avoid GC_noop6 calls to be optimized away. */ -# if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS) \ - || defined(PARALLEL_MARK) +# ifdef AO_CLEAR AO_compiler_barrier(); /* to serve as a special side-effect */ # else GC_noop1(0); diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 45435aa0..35ca4b05 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -48,8 +48,6 @@ #include /* for nanosleep() */ #include -#include "private/gc_atomic_ops.h" - #if (!defined(AO_HAVE_load_acquire) || !defined(AO_HAVE_store_release)) \ && !defined(CPPCHECK) # error AO_load_acquire and/or AO_store_release are missing; diff --git a/tests/test.c b/tests/test.c index 1240180c..452ad720 100644 --- a/tests/test.c +++ b/tests/test.c @@ -171,12 +171,6 @@ exit(1); \ } -#if defined(THREADS) && (defined(GC_BUILTIN_ATOMIC) \ - || defined(PARALLEL_MARK) \ - || !defined(GC_WIN32_THREADS)) -# include "private/gc_atomic_ops.h" /* for counters */ -#endif - /* Define AO primitives for a single-threaded mode. */ #ifndef AO_CLEAR /* AO_t not defined. */ diff --git a/tests/test_atomic_ops.c b/tests/test_atomic_ops.c index c99da725..a70fe471 100644 --- a/tests/test_atomic_ops.c +++ b/tests/test_atomic_ops.c @@ -20,9 +20,7 @@ #include -#if defined(GC_BUILTIN_ATOMIC) || defined(PARALLEL_MARK) \ - || (defined(GC_THREADS) && !defined(_WIN32) && !defined(_MSC_VER) \ - && !defined(__CYGWIN__) && !defined(__MINGW32__)) +#if defined(GC_BUILTIN_ATOMIC) || defined(GC_THREADS) # include diff --git a/thread_local_alloc.c b/thread_local_alloc.c index 545812a4..4a6624dd 100644 --- a/thread_local_alloc.c +++ b/thread_local_alloc.c @@ -196,8 +196,6 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_malloc_kind(size_t bytes, int knd) #ifdef GC_GCJ_SUPPORT -# include "private/gc_atomic_ops.h" /* for AO_compiler_barrier() */ - # include "include/gc_gcj.h" /* Gcj-style allocation without locks is extremely tricky. The */ diff --git a/typd_mlc.c b/typd_mlc.c index a67671af..0092547f 100644 --- a/typd_mlc.c +++ b/typd_mlc.c @@ -106,10 +106,6 @@ STATIC size_t GC_avail_descr = 0; /* Next available slot. */ STATIC int GC_typed_mark_proc_index = 0; /* Indices of my mark */ STATIC int GC_array_mark_proc_index = 0; /* procedures. */ -#if defined(GC_FORCE_INCLUDE_ATOMIC_OPS) || defined(GC_BUILTIN_ATOMIC) -# include "private/gc_atomic_ops.h" -#endif - #ifdef AO_HAVE_load_acquire STATIC volatile AO_t GC_explicit_typing_initialized = FALSE; #else diff --git a/win32_threads.c b/win32_threads.c index 03eb6b5a..f8fa1449 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -79,7 +79,6 @@ #if (defined(GC_DLL) || defined(GC_INSIDE_DLL)) \ && !defined(GC_NO_THREADS_DISCOVERY) && !defined(MSWINCE) \ && !defined(THREAD_LOCAL_ALLOC) && !defined(GC_PTHREADS) -# include "private/gc_atomic_ops.h" /* This code operates in two distinct modes, depending on */ /* the setting of GC_win32_dll_threads. */ -- 2.40.0