aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-12-13 17:58:39 +0100
committerChristian Grothoff <christian@grothoff.org>2018-12-13 17:58:39 +0100
commit63462a4dddd238e439360e2e70ecaa9366066fc5 (patch)
tree483dec5d9857707ce731eba5f6fdd51dcc1cc367
parentbdb3420bc937f0ab9187695a56f0e63d7c227f00 (diff)
downloadgnunet-63462a4dddd238e439360e2e70ecaa9366066fc5.tar.gz
gnunet-63462a4dddd238e439360e2e70ecaa9366066fc5.zip
make sure mono time uses atomics
-rw-r--r--configure.ac2
-rw-r--r--po/POTFILES.in3
-rw-r--r--src/util/time.c39
3 files changed, 40 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index 35b2ef659..5d570ddad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -992,7 +992,7 @@ AC_CHECK_HEADERS([fcntl.h math.h errno.h ctype.h limits.h stdio.h stdlib.h strin
992 992
993 993
994# Checks for headers that are only required on some systems or opional (and where we do NOT abort if they are not there) 994# Checks for headers that are only required on some systems or opional (and where we do NOT abort if they are not there)
995AC_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]) 995AC_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])
996 996
997# FreeBSD requires something more funky for netinet/in_systm.h and netinet/ip.h... 997# FreeBSD requires something more funky for netinet/in_systm.h and netinet/ip.h...
998AC_CHECK_HEADERS([sys/types.h netinet/in_systm.h netinet/in.h netinet/ip.h],,, 998AC_CHECK_HEADERS([sys/types.h netinet/in_systm.h netinet/in.h netinet/ip.h],,,
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 57160115c..1cc880b2e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,12 +14,15 @@ src/ats/gnunet-ats-solver-eval.c
14src/ats/gnunet-service-ats_addresses.c 14src/ats/gnunet-service-ats_addresses.c
15src/ats/gnunet-service-ats.c 15src/ats/gnunet-service-ats.c
16src/ats/gnunet-service-ats_connectivity.c 16src/ats/gnunet-service-ats_connectivity.c
17src/ats/gnunet-service-ats-new.c
17src/ats/gnunet-service-ats_normalization.c 18src/ats/gnunet-service-ats_normalization.c
18src/ats/gnunet-service-ats_performance.c 19src/ats/gnunet-service-ats_performance.c
19src/ats/gnunet-service-ats_plugins.c 20src/ats/gnunet-service-ats_plugins.c
20src/ats/gnunet-service-ats_preferences.c 21src/ats/gnunet-service-ats_preferences.c
21src/ats/gnunet-service-ats_reservations.c 22src/ats/gnunet-service-ats_reservations.c
22src/ats/gnunet-service-ats_scheduling.c 23src/ats/gnunet-service-ats_scheduling.c
24src/ats/plugin_ats2_common.c
25src/ats/plugin_ats2_simple.c
23src/ats/plugin_ats_mlp.c 26src/ats/plugin_ats_mlp.c
24src/ats/plugin_ats_proportional.c 27src/ats/plugin_ats_proportional.c
25src/ats/plugin_ats_ril.c 28src/ats/plugin_ats_ril.c
diff --git a/src/util/time.c b/src/util/time.c
index 46d3a2b65..741ca1ad2 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -23,6 +23,14 @@
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_util_lib.h" 25#include "gnunet_util_lib.h"
26#if __STDC_NO_ATOMICS__
27#else
28#ifdef HAVE_STDATOMIC_H
29#include <stdatomic.h>
30#else
31#define __STDC_NO_ATOMICS__ 1
32#endif
33#endif
26 34
27#define LOG(kind,...) GNUNET_log_from (kind, "util-time", __VA_ARGS__) 35#define LOG(kind,...) GNUNET_log_from (kind, "util-time", __VA_ARGS__)
28 36
@@ -780,7 +788,7 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
780 static const struct GNUNET_CONFIGURATION_Handle *last_cfg; 788 static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
781 static struct GNUNET_TIME_Absolute last_time; 789 static struct GNUNET_TIME_Absolute last_time;
782 static struct GNUNET_DISK_MapHandle *map_handle; 790 static struct GNUNET_DISK_MapHandle *map_handle;
783 static struct GNUNET_TIME_AbsoluteNBO *map; 791 static uint64_t *map;
784 struct GNUNET_TIME_Absolute now; 792 struct GNUNET_TIME_Absolute now;
785 793
786 now = GNUNET_TIME_absolute_get (); 794 now = GNUNET_TIME_absolute_get ();
@@ -859,13 +867,38 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
859 } 867 }
860 } 868 }
861 if (NULL != map) 869 if (NULL != map)
862 last_time = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (*map), 870 {
871 struct GNUNET_TIME_AbsoluteNBO mt;
872
873#if __STDC_NO_ATOMICS__
874#if __GNUC__
875 mt.abs_value_us__ = __sync_fetch_and_or (map, 0);
876#else
877 mt.abs_value_us__ = *map; /* godspeed, pray this is atomic */
878#endif
879#else
880 mt.abs_value_us__ = atomic_load (map);
881#endif
882 last_time = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_ntoh (mt),
863 last_time); 883 last_time);
884 }
864 if (now.abs_value_us <= last_time.abs_value_us) 885 if (now.abs_value_us <= last_time.abs_value_us)
865 now.abs_value_us = last_time.abs_value_us+1; 886 now.abs_value_us = last_time.abs_value_us+1;
866 last_time = now; 887 last_time = now;
867 if (NULL != map) 888 if (NULL != map)
868 *map = GNUNET_TIME_absolute_hton (now); 889 {
890 uint64_t val = GNUNET_TIME_absolute_hton (now).abs_value_us__;
891#if __STDC_NO_ATOMICS__
892#if __GNUC__
893 (void) __sync_lock_test_and_set (map, val);
894#else
895 *map = val; /* godspeed, pray this is atomic */
896#endif
897#else
898 atomic_store (map,
899 val);
900#endif
901 }
869 return now; 902 return now;
870} 903}
871 904