]> granicus.if.org Git - gc/commitdiff
Always include gc_atomic_ops.h unless threads are disabled
authorIvan Maidanski <ivmai@mail.ru>
Mon, 26 Feb 2018 19:03:30 +0000 (22:03 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 26 Feb 2018 20:25:47 +0000 (23:25 +0300)
(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
include/private/gc_locks.h
include/private/gc_priv.h
include/private/specific.h
mark.c
pthread_stop_world.c
tests/test.c
tests/test_atomic_ops.c
thread_local_alloc.c
typd_mlc.c
win32_threads.c

index 3bdf5647800619496b59741cc82e7e99753ba9fb..9b585ec5a549d210f0fbe890d250d30bb2688508 100644 (file)
   /* 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 */
index 5657606ab76fec4d18abdfe7eaf0068755bf6309..fad4ad2d9909e5d73f0b293ea0f1770ff8f13456 100644 (file)
  */
 # 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 <base/PCR_Base.h>
 #    include <th/PCR_Th.h>
index a7a6bdf7d730b82a222727de2f4dc8de5d962320..156bee5a8e250e06dd512c3a47b4fd463452a3da 100644 (file)
@@ -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 <setjmp.h>
@@ -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.            */
index ab864750e464d641acaf73eb9fe91d00f1a13f5d..1367a25218eac80b24c417c0e6a20ea4232752d5 100644 (file)
@@ -14,8 +14,6 @@
 
 #include <errno.h>
 
-#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 b4f448b104db4cee8361718b03c29e77cc3ddf05..8347bfc52fc6a1b0c5439c586245fa68a4151810 100644 (file)
--- 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);
index 45435aa0d456c3d1b9b717e2258c24e6db826319..35ca4b0578346058d6ea29c7842c16dfde43fb14 100644 (file)
@@ -48,8 +48,6 @@
 #include <time.h> /* for nanosleep() */
 #include <unistd.h>
 
-#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;
index 1240180cb5d27f56f8f9879a41ee2e6dd5dc6211..452ad7200fe922b81cc9f357fb5ff6d6117efd96 100644 (file)
               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. */
index c99da725f76c19705f0ae2f15ecef9424b983dfc..a70fe47145b50704bc598284d2fe1662a57c69d0 100644 (file)
@@ -20,9 +20,7 @@
 
 #include <stdio.h>
 
-#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 <stdlib.h>
 
index 545812a405ddfded2c4a33f1aeecb5133fe03734..4a6624ddb338dc1dab65e54f8ce9946a928af4f2 100644 (file)
@@ -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         */
index a67671af74baaa21a713a8b4f0e2dc147b87db8c..0092547ff457496d564d0d541ed6fd8c13240274 100644 (file)
@@ -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
index 03eb6b5ae5e73237822427cc64869012230c063c..f8fa1449e40f2dbae6e32a4b78de28a4957ebd8e 100644 (file)
@@ -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.                       */