d: Remove the d_critsec_size target hook.
authorIain Buclaw <ibuclaw@gdcproject.org>
Fri, 23 Oct 2020 14:48:25 +0000 (16:48 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Tue, 27 Oct 2020 10:50:35 +0000 (11:50 +0100)
The allocation of mutex objects for synchronized statements has been
moved to the library as of merging druntime 58560d51.  All support code
in the compiler for getting the OS critical section size has been
removed along with it.

Reviewed-on: https://github.com/dlang/dmd/pull/11902
     https://github.com/dlang/druntime/pull/3248

gcc/ChangeLog:

* config/aarch64/aarch64-linux.h (GNU_USER_TARGET_D_CRITSEC_SIZE):
Remove.
* config/glibc-d.c (glibc_d_critsec_size): Likewise.
(TARGET_D_CRITSEC_SIZE): Likewise.
* config/i386/linux-common.h (GNU_USER_TARGET_D_CRITSEC_SIZE):
Likewise.
* config/sol2-d.c (solaris_d_critsec_size): Likewise.
(TARGET_D_CRITSEC_SIZE):  Likewise.
* doc/tm.texi.in (TARGET_D_CRITSEC_SIZE): Likewise.
* doc/tm.texi: Regenerate.

gcc/d/ChangeLog:

* dmd/MERGE: Merge upstream dmd bec5973b0.
* d-target.cc (Target::critsecsize): Remove.
* d-target.def: Remove d_critsec_size.

libphobos/ChangeLog:

* libdruntime/MERGE: Merge upstream druntime 58560d51.

14 files changed:
gcc/config/aarch64/aarch64-linux.h
gcc/config/glibc-d.c
gcc/config/i386/linux-common.h
gcc/config/sol2-d.c
gcc/d/d-target.cc
gcc/d/d-target.def
gcc/d/dmd/MERGE
gcc/d/dmd/idgen.c
gcc/d/dmd/statementsem.c
gcc/d/dmd/target.h
gcc/doc/tm.texi
gcc/doc/tm.texi.in
libphobos/libdruntime/MERGE
libphobos/libdruntime/rt/critical_.d

index e587e2e9ad6763995aaf2023066db44ca17ff297..b1d1f671fc531b86e9d28f8b86b4507b0b543f13 100644 (file)
@@ -64,8 +64,6 @@
     }                                          \
   while (0)
 
-#define GNU_USER_TARGET_D_CRITSEC_SIZE 48
-
 #define TARGET_ASM_FILE_END aarch64_file_end_indicate_exec_stack
 
 /* Uninitialized common symbols in non-PIE executables, even with
index bdacdace0c3a65599e3ab07753920e964e6b471f..7eb9e315f009fda022a877ae61383e173bd49139 100644 (file)
@@ -42,23 +42,7 @@ glibc_d_os_builtins (void)
 #endif
 }
 
-/* Implement TARGET_D_CRITSEC_SIZE for Glibc targets.  */
-
-static unsigned
-glibc_d_critsec_size (void)
-{
-  /* This is the sizeof pthread_mutex_t.  */
-#ifdef GNU_USER_TARGET_D_CRITSEC_SIZE
-  return GNU_USER_TARGET_D_CRITSEC_SIZE;
-#else
-  return (POINTER_SIZE == 64) ? 40 : 24;
-#endif
-}
-
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS glibc_d_os_builtins
 
-#undef TARGET_D_CRITSEC_SIZE
-#define TARGET_D_CRITSEC_SIZE glibc_d_critsec_size
-
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
index 1ae6b3f3939566fe269ee389b831430e16afbf30..982390d7f3e800e8d33b5fc2acb9645a0cff81cf 100644 (file)
@@ -30,9 +30,6 @@ along with GCC; see the file COPYING3.  If not see
 #define EXTRA_TARGET_D_OS_VERSIONS()           \
   ANDROID_TARGET_D_OS_VERSIONS();
 
-#define GNU_USER_TARGET_D_CRITSEC_SIZE         \
-  (TARGET_64BIT ? (POINTER_SIZE == 64 ? 40 : 32) : 24)
-
 #undef CC1_SPEC
 #define CC1_SPEC \
   LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
index 73ca78698b2b967236a5ca0497ec2e53bb4e22d0..27068f8308255ec1f141a10dcd9f4b3ab09df657 100644 (file)
@@ -33,19 +33,7 @@ solaris_d_os_builtins (void)
   d_add_builtin_version ("Solaris");                   \
 }
 
-/* Implement TARGET_D_CRITSEC_SIZE for Solaris targets.  */
-
-static unsigned
-solaris_d_critsec_size (void)
-{
-  /* This is the sizeof pthread_mutex_t.  */
-  return 24;
-}
-
 #undef TARGET_D_OS_VERSIONS
 #define TARGET_D_OS_VERSIONS solaris_d_os_builtins
 
-#undef TARGET_D_CRITSEC_SIZE
-#define TARGET_D_CRITSEC_SIZE solaris_d_critsec_size
-
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
index 78f14203b5cc129e53eaaf5ef5ef9207491157f8..692fce6a65544c1096244716d30209094c4b9c63 100644 (file)
@@ -202,16 +202,6 @@ Target::fieldalign (Type *type)
   return align / BITS_PER_UNIT;
 }
 
-/* Return size of OS critical section.
-   Can't use the sizeof () calls directly since cross compiling is supported
-   and would end up using the host sizes rather than the target sizes.  */
-
-unsigned
-Target::critsecsize (void)
-{
-  return targetdm.d_critsec_size ();
-}
-
 /* Returns a Type for the va_list type of the target.  */
 
 Type *
index d641c74342968a641da7c1ca029b1d94690b37ef..41b31723188a79178104a2118c30beca162ee9cb 100644 (file)
@@ -46,15 +46,5 @@ relating to the target operating system.",
  void, (void),
  hook_void_void)
 
-/* The sizeof CRITICAL_SECTION or pthread_mutex_t.  */
-DEFHOOK
-(d_critsec_size,
- "Returns the size of the data structure used by the target operating system\n\
-for critical sections and monitors.  For example, on Microsoft Windows this\n\
-would return the @code{sizeof(CRITICAL_SECTION)}, while other platforms that\n\
-implement pthreads would return @code{sizeof(pthread_mutex_t)}.",
- unsigned, (void),
- hook_uint_void_0)
-
 /* Close the 'struct gcc_targetdm' definition.  */
 HOOK_VECTOR_END (C90_EMPTY_HACK)
index 7b561e4044ec98be560f4de12e23099c846dd0e5..39e424f2a98034404bf7ca865385eb2844d2a022 100644 (file)
@@ -1,4 +1,4 @@
-0fcdaab32c7645820820f6e1474343ccfb7560e5
+bec5973b0203c95adbda2a049ccdf3cd3a4378f6
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
index 2944a79af2a8a73fe1c6951fe01c4fc20c80b624..a6267c515de85f0bdf947a856e7dc0a06cbd46a4 100644 (file)
@@ -262,7 +262,7 @@ Msgtable msgtable[] =
     { "aaRehash", "_aaRehash" },
     { "monitorenter", "_d_monitorenter" },
     { "monitorexit", "_d_monitorexit" },
-    { "criticalenter", "_d_criticalenter" },
+    { "criticalenter", "_d_criticalenter2" },
     { "criticalexit", "_d_criticalexit" },
     { "__ArrayEq", NULL },
     { "__ArrayPostblit", NULL },
index 42f885d4175c6d3a71f9e716dbb07945f3ad82c3..4ff07f6f2ebaaef5503a73ff823deceeb164972e 100644 (file)
@@ -3213,14 +3213,15 @@ public:
         else
         {
             /* Generate our own critical section, then rewrite as:
-             *  __gshared byte[CriticalSection.sizeof] critsec;
-             *  _d_criticalenter(critsec.ptr);
-             *  try { body } finally { _d_criticalexit(critsec.ptr); }
+             *  __gshared void* __critsec;
+             *  _d_criticalenter2(&__critsec);
+             *  try { body } finally { _d_criticalexit(__critsec); }
              */
             Identifier *id = Identifier::generateId("__critsec");
-            Type *t = Type::tint8->sarrayOf(target.ptrsize + target.critsecsize());
+            Type *t = Type::tvoidptr;
             VarDeclaration *tmp = new VarDeclaration(ss->loc, t, id, NULL);
             tmp->storage_class |= STCtemp | STCgshared | STCstatic;
+            Expression *tmpExp = new VarExp(ss->loc, tmp);
 
             Statements *cs = new Statements();
             cs->push(new ExpStatement(ss->loc, tmp));
@@ -3236,15 +3237,14 @@ public:
             args->push(new Parameter(0, t->pointerTo(), NULL, NULL));
 
             FuncDeclaration *fdenter = FuncDeclaration::genCfunc(args, Type::tvoid, Id::criticalenter, STCnothrow);
-            Expression *e = new DotIdExp(ss->loc, new VarExp(ss->loc, tmp), Id::ptr);
+            Expression *e = new AddrExp(ss->loc, tmpExp);
             e = semantic(e, sc);
             e = new CallExp(ss->loc, new VarExp(ss->loc, fdenter, false), e);
             e->type = Type::tvoid;                  // do not run semantic on e
             cs->push(new ExpStatement(ss->loc, e));
 
             FuncDeclaration *fdexit = FuncDeclaration::genCfunc(args, Type::tvoid, Id::criticalexit, STCnothrow);
-            e = new DotIdExp(ss->loc, new VarExp(ss->loc, tmp), Id::ptr);
-            e = semantic(e, sc);
+            e = semantic(tmpExp, sc);
             e = new CallExp(ss->loc, new VarExp(ss->loc, fdexit, false), e);
             e->type = Type::tvoid;                  // do not run semantic on e
             Statement *s = new ExpStatement(ss->loc, e);
index d76a9f89abd0025f933c3d55380cf28f8509835d..c34826af3044af3aad19b4f65a4316022adab4c7 100644 (file)
@@ -28,7 +28,6 @@ struct TargetC
 {
     unsigned longsize;            // size of a C 'long' or 'unsigned long' type
     unsigned long_doublesize;     // size of a C 'long double'
-    unsigned criticalSectionSize; // size of os critical section
 };
 
 struct TargetCPP
@@ -98,7 +97,6 @@ public:
     // Type sizes and support.
     unsigned alignsize(Type *type);
     unsigned fieldalign(Type *type);
-    unsigned critsecsize();
     Type *va_listType(const Loc &loc, Scope *sc);  // get type of va_list
     int isVectorTypeSupported(int sz, Type *type);
     bool isVectorOpSupported(Type *type, TOK op, Type *t2 = NULL);
index 97437e8274fdf17b4e9c3b4b1d19fc6012fae704..24c37f655c88b3a7138f9a9d44270cd24aded47d 100644 (file)
@@ -10817,13 +10817,6 @@ Similarly to @code{TARGET_D_CPU_VERSIONS}, but is used for versions
 relating to the target operating system.
 @end deftypefn
 
-@deftypefn {D Target Hook} unsigned TARGET_D_CRITSEC_SIZE (void)
-Returns the size of the data structure used by the target operating system
-for critical sections and monitors.  For example, on Microsoft Windows this
-would return the @code{sizeof(CRITICAL_SECTION)}, while other platforms that
-implement pthreads would return @code{sizeof(pthread_mutex_t)}.
-@end deftypefn
-
 @node Named Address Spaces
 @section Adding support for named address spaces
 @cindex named address spaces
index 412e22c89ab9d8dbea0cfe5536d75827191418d4..2b8d29f235a9df3e091a10bdc0ca3f79e5113537 100644 (file)
@@ -7351,8 +7351,6 @@ floating-point support; they are not included in this mechanism.
 
 @hook TARGET_D_OS_VERSIONS
 
-@hook TARGET_D_CRITSEC_SIZE
-
 @node Named Address Spaces
 @section Adding support for named address spaces
 @cindex named address spaces
index bcde10514ec685b4d656a7fcab7591752955f8dc..485f8e999d6968af21313d97f834fcfed79d749e 100644 (file)
@@ -1,4 +1,4 @@
-d05ebaad15fbffce6d707c138c84d7b60fcf5ffd
+58560d5163381b0f1c893bd0d035b7a0a1631f92
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/druntime repository.
index c2ef8220901a05de81ac6006424c7119a53271ae..40030ad35b8025311deb638510c4c5b0c4d980d5 100644 (file)
@@ -31,12 +31,30 @@ extern (C) void _d_critical_term()
 
 extern (C) void _d_criticalenter(D_CRITICAL_SECTION* cs)
 {
+    assert(cs !is null);
     ensureMutex(cast(shared(D_CRITICAL_SECTION*)) cs);
     lockMutex(&cs.mtx);
 }
 
+extern (C) void _d_criticalenter2(D_CRITICAL_SECTION** pcs)
+{
+    if (atomicLoad!(MemoryOrder.acq)(*cast(shared) pcs) is null)
+    {
+        lockMutex(cast(Mutex*)&gcs.mtx);
+        if (atomicLoad!(MemoryOrder.raw)(*cast(shared) pcs) is null)
+        {
+            auto cs = new shared D_CRITICAL_SECTION;
+            initMutex(cast(Mutex*)&cs.mtx);
+            atomicStore!(MemoryOrder.rel)(*cast(shared) pcs, cs);
+        }
+        unlockMutex(cast(Mutex*)&gcs.mtx);
+    }
+    lockMutex(&(*pcs).mtx);
+}
+
 extern (C) void _d_criticalexit(D_CRITICAL_SECTION* cs)
 {
+    assert(cs !is null);
     unlockMutex(&cs.mtx);
 }