Hello,

this patch adds basic support for libatomic for mingw targets using
win32 and for mingw targets using posix threading model.

The win32 implemenation might need for initialization of mutexes a
critical section.  If issue occures we can still add that.  For now
all testcases are passing for native and posix-threading model mingw
(32-bit and 64-bit).

ChangeLog

2014-06-16  Kai Tietz  <kti...@redhat.com>

    * Makefile.am (libatomic_la_LDFLAGS): Add lt_host_flags.
    * configure.ac (ACX_LT_HOST_FLAGS): New.
    (target_thread_file): New.
    * configure.tgt (mingw): Add mingw support.
    * config/mingw/host-config.h: New file.
    * config/mingw/lock.c: Likewise.
    * Makefile.in: Regenerated.
    * configure: Likewise.
    * aclocal.m4: Likewise.
    * testsuite/Makefile.in: Likewise.

Tested for i686-w64-mingw32, and x86_64-w64-mingw32.  Additionally
done regression test for x86_64-unknown-linux-gnu.

Ok for apply?

Regards,
Kai

Index: Makefile.am
===================================================================
--- Makefile.am    (Revision 211705)
+++ Makefile.am    (Arbeitskopie)
@@ -66,7 +66,7 @@ libatomic_version_dep =
 endif
 libatomic_version_info = -version-info $(libtool_VERSION)

-libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script)
+libatomic_la_LDFLAGS = $(libatomic_version_info)
$(libatomic_version_script) $(lt_host_flags)
 libatomic_la_SOURCES = gload.c gstore.c gcas.c gexch.c glfree.c lock.c init.c \
     fenv.c

Index: config/mingw/host-config.h
===================================================================
--- config/mingw/host-config.h    (Revision 0)
+++ config/mingw/host-config.h    (Arbeitskopie)
@@ -0,0 +1,54 @@
+/* Copyright (C) 2014 Free Software Foundation, Inc.
+   Contributed by Kai Tietz <kti...@redhat.com>.
+
+   This file is part of the GNU Atomic Library (libatomic).
+
+   Libatomic is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* Included after all more target-specific host-config.h.  */
+
+#ifndef protect_start_end
+# ifdef HAVE_ATTRIBUTE_VISIBILITY
+#  pragma GCC visibility push(hidden)
+# endif
+
+void libat_lock_1 (void *ptr);
+void libat_unlock_1 (void *ptr);
+
+static inline UWORD
+protect_start (void *ptr)
+{
+  libat_lock_1 (ptr);
+  return 0;
+}
+
+static inline void
+protect_end (void *ptr, UWORD dummy UNUSED)
+{
+  libat_unlock_1 (ptr);
+}
+
+# define protect_start_end 1
+# ifdef HAVE_ATTRIBUTE_VISIBILITY
+#  pragma GCC visibility pop
+# endif
+#endif /* protect_start_end */
+
+#include_next <host-config.h>

Eigenschaftsänderungen: config/mingw/host-config.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: config/mingw/lock.c
===================================================================
--- config/mingw/lock.c    (Revision 0)
+++ config/mingw/lock.c    (Arbeitskopie)
@@ -0,0 +1,124 @@
+/* Copyright (C) 2014 Free Software Foundation, Inc.
+   Contributed by Kai Tietz <kti...@redhat.com>.
+
+   This file is part of the GNU Atomic Library (libatomic).
+
+   Libatomic is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
+   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   Under Section 7 of GPL version 3, you are granted additional
+   permissions described in the GCC Runtime Library Exception, version
+   3.1, as published by the Free Software Foundation.
+
+   You should have received a copy of the GNU General Public License and
+   a copy of the GCC Runtime Library Exception along with this program;
+   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define UWORD __shadow_UWORD
+#include <windows.h>
+#undef UWORD
+#include "libatomic_i.h"
+
+/* The target page size.  Must be no larger than the runtime page size,
+   lest locking fail with virtual address aliasing (i.e. a page mmaped
+   at two locations).  */
+#ifndef PAGE_SIZE
+#define PAGE_SIZE 4096
+#endif
+
+/* The target cacheline size.  This is an optimization; the padding that
+   should be applied to the locks to keep them from interfering.  */
+#ifndef CACHLINE_SIZE
+#define CACHLINE_SIZE 64
+#endif
+
+/* The granularity at which locks are applied.  Almost certainly the
+   cachline size is the right thing to use here.  */
+#ifndef WATCH_SIZE
+#define WATCH_SIZE CACHLINE_SIZE
+#endif
+
+struct lock
+{
+  HANDLE mutex;
+  char pad[sizeof (HANDLE) < CACHLINE_SIZE
+       ? CACHLINE_SIZE - sizeof (HANDLE)
+       : 0];
+};
+
+#define NLOCKS (PAGE_SIZE / WATCH_SIZE)
+
+static struct lock locks[NLOCKS] = {
+  [0 ... NLOCKS-1].mutex = NULL
+};
+
+static inline uintptr_t
+addr_hash (void *ptr)
+{
+  return ((uintptr_t)ptr / WATCH_SIZE) % NLOCKS;
+}
+
+void
+libat_lock_1 (void *ptr)
+{
+  if (!locks[addr_hash (ptr)].mutex)
+    locks[addr_hash (ptr)].mutex = CreateMutex  (NULL, FALSE, NULL);
+  WaitForSingleObject (locks[addr_hash (ptr)].mutex, INFINITE);
+}
+
+void
+libat_unlock_1 (void *ptr)
+{
+  if (locks[addr_hash (ptr)].mutex)
+    ReleaseMutex (locks[addr_hash (ptr)].mutex);
+}
+
+void
+libat_lock_n (void *ptr, size_t n)
+{
+  uintptr_t h = addr_hash (ptr);
+  size_t i = 0;
+
+  /* Don't lock more than all the locks we have.  */
+  if (n > PAGE_SIZE)
+    n = PAGE_SIZE;
+
+  do
+    {
+      if (!locks[h].mutex)
+    locks[h].mutex = CreateMutex  (NULL, FALSE, NULL);
+      WaitForSingleObject (locks[h].mutex, INFINITE);
+      if (++h == NLOCKS)
+    h = 0;
+      i += WATCH_SIZE;
+    }
+  while (i < n);
+}
+
+void
+libat_unlock_n (void *ptr, size_t n)
+{
+  uintptr_t h = addr_hash (ptr);
+  size_t i = 0;
+
+  if (n > PAGE_SIZE)
+    n = PAGE_SIZE;
+
+  do
+    {
+      if (locks[h].mutex)
+    ReleaseMutex (locks[h].mutex);
+      if (++h == NLOCKS)
+    h = 0;
+      i += WATCH_SIZE;
+    }
+  while (i < n);
+}

Index: configure.ac
===================================================================
--- configure.ac    (Revision 211705)
+++ configure.ac    (Arbeitskopie)
@@ -143,6 +143,7 @@ AC_PROG_INSTALL

 # Configure libtool
 AM_PROG_LIBTOOL
+ACX_LT_HOST_FLAGS
 AC_SUBST(enable_shared)
 AC_SUBST(enable_static)
 AM_MAINTAINER_MODE
@@ -151,6 +152,11 @@ AM_MAINTAINER_MODE
 libtool_VERSION=2:0:1
 AC_SUBST(libtool_VERSION)

+# Check for used threading-model
+AC_MSG_CHECKING([for thread model used by GCC])
+target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
+AC_MSG_RESULT([$target_thread_file])
+
 # Get target configury.
 . ${srcdir}/configure.tgt
 if test -n "$UNSUPPORTED"; then
Index: configure.tgt
===================================================================
--- configure.tgt    (Revision 211705)
+++ configure.tgt    (Arbeitskopie)
@@ -108,6 +108,17 @@ case "${target}" in
     config_path="${config_path} posix"
     ;;

+  *-*-mingw*)
+    # OS support for atomic primitives.
+        case ${target_thread_file} in
+          win32)
+            config_path="${config_path} mingw"
+            ;;
+          posix)
+            config_path="${config_path} posix"
+            ;;
+        esac
+    ;;
   *-*-elf*)
     # ??? No target OS.  We could be targeting bare-metal kernel-mode,
     # or user-mode for some custom OS.  If the target supports TAS,
Index: testsuite/Makefile.in
===================================================================
--- testsuite/Makefile.in    (Revision 211705)
+++ testsuite/Makefile.in    (Arbeitskopie)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@

 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -15,6 +15,23 @@

 @SET_MAKE@
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \    ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -40,6 +57,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
     $(top_srcdir)/../config/depstand.m4 \
     $(top_srcdir)/../config/lead-dot.m4 \
+    $(top_srcdir)/../config/lthostflags.m4 \
     $(top_srcdir)/../config/multi.m4 \
     $(top_srcdir)/../config/override.m4 \
     $(top_srcdir)/../config/stdint.m4 \
@@ -54,6 +72,11 @@ CONFIG_HEADER = $(top_builddir)/auto-config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
 SOURCES =
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 DEJATOOL = $(PACKAGE)
 RUNTESTDEFAULTFLAGS = --tool $$tool --srcdir $$srcdir
 ACLOCAL = @ACLOCAL@
@@ -165,6 +188,7 @@ libexecdir = @libexecdir@
 libtool_VERSION = @libtool_VERSION@
 localedir = @localedir@
 localstatedir = @localstatedir@
+lt_host_flags = @lt_host_flags@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 multi_basedir = @multi_basedir@
@@ -245,7 +269,7 @@ CTAGS:


 check-DEJAGNU: site.exp
-    srcdir=`$(am__cd) $(srcdir) && pwd`; export srcdir; \
+    srcdir='$(srcdir)'; export srcdir; \
     EXPECT=$(EXPECT); export EXPECT; \
     runtest=$(RUNTEST); \
     if $(SHELL) -c "$$runtest --version" > /dev/null 2>&1; then \
@@ -256,12 +280,12 @@ check-DEJAGNU: site.exp
     else echo "WARNING: could not find \`runtest'" 1>&2; :;\
     fi; \
     exit $$exit_status
-site.exp: Makefile
+site.exp: Makefile $(EXTRA_DEJAGNU_SITE_CONFIG)
     @echo 'Making a new site.exp file...'
     @echo '## these variables are automatically generated by make ##' >site.tmp
     @echo '# Do not edit here.  If you wish to override these values'
>>site.tmp
     @echo '# edit the last section' >>site.tmp
-    @echo 'set srcdir $(srcdir)' >>site.tmp
+    @echo 'set srcdir "$(srcdir)"' >>site.tmp
     @echo "set objdir `pwd`" >>site.tmp
     @echo 'set build_alias "$(build_alias)"' >>site.tmp
     @echo 'set build_triplet $(build_triplet)' >>site.tmp
@@ -269,9 +293,16 @@ check-DEJAGNU: site.exp
     @echo 'set host_triplet $(host_triplet)' >>site.tmp
     @echo 'set target_alias "$(target_alias)"' >>site.tmp
     @echo 'set target_triplet $(target_triplet)' >>site.tmp
-    @echo '## All variables above are generated by configure. Do Not
Edit ##' >>site.tmp
-    @test ! -f site.exp || \
-      sed '1,/^## All variables above are.*##/ d' site.exp >> site.tmp
+    @list='$(EXTRA_DEJAGNU_SITE_CONFIG)'; for f in $$list; do \
+      echo "## Begin content included from file $$f.  Do not modify. ##" \
+       && cat `test -f "$$f" || echo '$(srcdir)/'`$$f \
+       && echo "## End content included from file $$f. ##" \
+       || exit 1; \
+     done >> site.tmp
+    @echo "## End of auto-generated content; you can edit from here.
##" >> site.tmp
+    @if test -f site.exp; then \
+       sed -e '1,/^## End of auto-generated content.*##/d' site.exp
>> site.tmp; \
+     fi
     @-rm -f site.bak
     @test ! -f site.exp || mv site.exp site.bak
     @mv site.tmp site.exp
@@ -296,10 +327,15 @@ install-am: all-am

 installcheck: installcheck-am
 install-strip:
-    $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-      install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-      `test -z '$(STRIP)' || \
-        echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+    if test -z '$(STRIP)'; then \
+      $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+        install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+          install; \
+    else \
+      $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+        install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+        "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+    fi
 mostlyclean-generic:

 clean-generic:

Reply via email to