aboutsummaryrefslogtreecommitdiff
path: root/src/util/time.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-12-30 23:23:45 +0100
committerChristian Grothoff <christian@grothoff.org>2018-12-30 23:24:04 +0100
commit019808f152cc0856ee9617038e5aa517adc2ee45 (patch)
tree8dad766530677ea4c3fb2c6200f7fcecfeebbc2d /src/util/time.c
parent88b2d2d6c814c4eb41ac3b0ab15b7564706e5d7c (diff)
downloadgnunet-019808f152cc0856ee9617038e5aa517adc2ee45.tar.gz
gnunet-019808f152cc0856ee9617038e5aa517adc2ee45.zip
fix #5505
Diffstat (limited to 'src/util/time.c')
-rw-r--r--src/util/time.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/util/time.c b/src/util/time.c
index 741ca1ad2..382265aa1 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/ 17*/
@@ -24,11 +24,14 @@
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__ 26#if __STDC_NO_ATOMICS__
27#define ATOMIC
27#else 28#else
28#ifdef HAVE_STDATOMIC_H 29#ifdef HAVE_STDATOMIC_H
29#include <stdatomic.h> 30#include <stdatomic.h>
31#define ATOMIC _Atomic
30#else 32#else
31#define __STDC_NO_ATOMICS__ 1 33#define __STDC_NO_ATOMICS__ 1
34#define ATOMIC
32#endif 35#endif
33#endif 36#endif
34 37
@@ -769,15 +772,15 @@ GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIM
769 * increasing. Guards against systems without an RTC or 772 * increasing. Guards against systems without an RTC or
770 * clocks running backwards and other nasty surprises. Does 773 * clocks running backwards and other nasty surprises. Does
771 * not guarantee that the returned time is near the current 774 * not guarantee that the returned time is near the current
772 * time returned by #GNUNET_TIME_absolute_get(). Two 775 * time returned by #GNUNET_TIME_absolute_get(). Two
773 * subsequent calls (within a short time period) may return the 776 * subsequent calls (within a short time period) may return the
774 * same value. Persists the last returned time on disk to 777 * same value. Persists the last returned time on disk to
775 * ensure that time never goes backwards. As a result, the 778 * ensure that time never goes backwards. As a result, the
776 * resulting value can be used to check if a message is the 779 * resulting value can be used to check if a message is the
777 * "most recent" value and replays of older messages (from 780 * "most recent" value and replays of older messages (from
778 * the same origin) would be discarded. 781 * the same origin) would be discarded.
779 * 782 *
780 * @param cfg configuration, used to determine where to 783 * @param cfg configuration, used to determine where to
781 * store the time; user can also insist RTC is working 784 * store the time; user can also insist RTC is working
782 * nicely and disable the feature 785 * nicely and disable the feature
783 * @return monotonically increasing time 786 * @return monotonically increasing time
@@ -788,7 +791,7 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
788 static const struct GNUNET_CONFIGURATION_Handle *last_cfg; 791 static const struct GNUNET_CONFIGURATION_Handle *last_cfg;
789 static struct GNUNET_TIME_Absolute last_time; 792 static struct GNUNET_TIME_Absolute last_time;
790 static struct GNUNET_DISK_MapHandle *map_handle; 793 static struct GNUNET_DISK_MapHandle *map_handle;
791 static uint64_t *map; 794 static ATOMIC volatile uint64_t *map;
792 struct GNUNET_TIME_Absolute now; 795 struct GNUNET_TIME_Absolute now;
793 796
794 now = GNUNET_TIME_absolute_get (); 797 now = GNUNET_TIME_absolute_get ();
@@ -802,7 +805,7 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
802 map_handle = NULL; 805 map_handle = NULL;
803 } 806 }
804 map = NULL; 807 map = NULL;
805 808
806 last_cfg = cfg; 809 last_cfg = cfg;
807 if ( (NULL != cfg) && 810 if ( (NULL != cfg) &&
808 (GNUNET_OK == 811 (GNUNET_OK ==
@@ -824,7 +827,7 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
824 filename); 827 filename);
825 } 828 }
826 else 829 else
827 { 830 {
828 off_t size; 831 off_t size;
829 832
830 size = 0; 833 size = 0;
@@ -897,7 +900,7 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
897#else 900#else
898 atomic_store (map, 901 atomic_store (map,
899 val); 902 val);
900#endif 903#endif
901 } 904 }
902 return now; 905 return now;
903} 906}