make sure mono time uses atomics
authorChristian Grothoff <christian@grothoff.org>
Thu, 13 Dec 2018 16:58:39 +0000 (17:58 +0100)
committerChristian Grothoff <christian@grothoff.org>
Thu, 13 Dec 2018 16:58:39 +0000 (17:58 +0100)
configure.ac
po/POTFILES.in
src/util/time.c

index 35b2ef65930a1fdccabfbebfa353b11560420588..5d570ddad7857d12924b6212521ce538401feac0 100644 (file)
@@ -992,7 +992,7 @@ AC_CHECK_HEADERS([fcntl.h math.h errno.h ctype.h limits.h stdio.h stdlib.h strin
 
 
 # Checks for headers that are only required on some systems or opional (and where we do NOT abort if they are not there)
-AC_CHECK_HEADERS([malloc.h malloc/malloc.h malloc/malloc_np.h langinfo.h sys/param.h sys/mount.h sys/statvfs.h sys/select.h sockLib.h sys/mman.h sys/msg.h sys/vfs.h arpa/inet.h fcntl.h libintl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h sys/time.h unistd.h kstat.h sys/sysinfo.h kvm.h sys/file.h sys/resource.h ifaddrs.h mach/mach.h stddef.h sys/timeb.h terminos.h argz.h ucred.h sys/ucred.h endian.h sys/endian.h execinfo.h byteswap.h])
+AC_CHECK_HEADERS([stdatomic.h malloc.h malloc/malloc.h malloc/malloc_np.h langinfo.h sys/param.h sys/mount.h sys/statvfs.h sys/select.h sockLib.h sys/mman.h sys/msg.h sys/vfs.h arpa/inet.h fcntl.h libintl.h netdb.h netinet/in.h sys/ioctl.h sys/socket.h sys/time.h unistd.h kstat.h sys/sysinfo.h kvm.h sys/file.h sys/resource.h ifaddrs.h mach/mach.h stddef.h sys/timeb.h terminos.h argz.h ucred.h sys/ucred.h endian.h sys/endian.h execinfo.h byteswap.h])
 
 # FreeBSD requires something more funky for netinet/in_systm.h and netinet/ip.h...
 AC_CHECK_HEADERS([sys/types.h netinet/in_systm.h netinet/in.h netinet/ip.h],,,
index 57160115c8df05b75e8a83b2455947414a9fe8a5..1cc880b2e51d655f7101d0bfd9d5e5d85226123e 100644 (file)
@@ -14,12 +14,15 @@ src/ats/gnunet-ats-solver-eval.c
 src/ats/gnunet-service-ats_addresses.c
 src/ats/gnunet-service-ats.c
 src/ats/gnunet-service-ats_connectivity.c
+src/ats/gnunet-service-ats-new.c
 src/ats/gnunet-service-ats_normalization.c
 src/ats/gnunet-service-ats_performance.c
 src/ats/gnunet-service-ats_plugins.c
 src/ats/gnunet-service-ats_preferences.c
 src/ats/gnunet-service-ats_reservations.c
 src/ats/gnunet-service-ats_scheduling.c
+src/ats/plugin_ats2_common.c
+src/ats/plugin_ats2_simple.c
 src/ats/plugin_ats_mlp.c
 src/ats/plugin_ats_proportional.c
 src/ats/plugin_ats_ril.c
index 46d3a2b6574b41a29a4b3899edf77ad6521dbdc3..741ca1ad26054cc643753e0f7adb001472c6d9b6 100644 (file)
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
+#if __STDC_NO_ATOMICS__
+#else
+#ifdef HAVE_STDATOMIC_H
+#include <stdatomic.h>
+#else
+#define __STDC_NO_ATOMICS__ 1
+#endif
+#endif
 
 #define LOG(kind,...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
 
@@ -780,7 +788,7 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
   static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
   static struct GNUNET_TIME_Absolute last_time;
   static struct GNUNET_DISK_MapHandle *map_handle;
-  static struct GNUNET_TIME_AbsoluteNBO *map;
+  static uint64_t *map;
   struct GNUNET_TIME_Absolute now;
 
   now = GNUNET_TIME_absolute_get ();
@@ -859,13 +867,38 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
     }
   }
   if (NULL != map)
-    last_time = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (*map),
+  {
+    struct GNUNET_TIME_AbsoluteNBO mt;
+
+#if __STDC_NO_ATOMICS__
+#if __GNUC__
+    mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
+#else
+    mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
+#endif
+#else
+    mt.abs_value_us__ = atomic_load (map);
+#endif
+    last_time = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (mt),
                                          last_time);
+  }
   if (now.abs_value_us <= last_time.abs_value_us)
     now.abs_value_us = last_time.abs_value_us+1;
   last_time = now;
   if (NULL != map)
-    *map = GNUNET_TIME_absolute_hton (now);
+  {
+    uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
+#if __STDC_NO_ATOMICS__
+#if __GNUC__
+    (void) __sync_lock_test_and_set (map, val);
+#else
+    *map = val;  /* godspeed, pray this is atomic */
+#endif
+#else
+    atomic_store (map,
+                 val);
+#endif                              
+  }
   return now;
 }