gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: clarify time API and usage of UINT64_MAX


From: gnunet
Subject: [gnunet] branch master updated: clarify time API and usage of UINT64_MAX
Date: Mon, 28 Oct 2024 09:47:23 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 808eee57f clarify time API and usage of UINT64_MAX
808eee57f is described below

commit 808eee57fb7884aa60b1eeb9d26e7408fa1b00e9
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Oct 28 09:46:47 2024 +0100

    clarify time API and usage of UINT64_MAX
---
 src/include/gnunet_time_lib.h | 40 ++++++++++++++++++++++++----------------
 src/lib/util/time.c           | 14 +++++++++-----
 2 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index 729ea8aee..cd14f89a8 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -54,6 +54,7 @@ struct GNUNET_TIME_Absolute
 {
   /**
    * The actual value.
+   * UINT64_MAX to represents "never".
    */
   uint64_t abs_value_us;
 };
@@ -64,7 +65,8 @@ struct GNUNET_TIME_Absolute
 struct GNUNET_TIME_Timestamp
 {
   /**
-   * The actual value. Must be a round number of seconds in microseconds.
+   * The actual value. Must be a round number of seconds in microseconds,
+   * or UINT64_MAX to represent "never".
    */
   struct GNUNET_TIME_Absolute abs_time;
 };
@@ -77,6 +79,7 @@ struct GNUNET_TIME_Relative
 {
   /**
    * The actual value.
+   * UINT64_MAX represents "forever".
    */
   uint64_t rel_value_us;
 };
@@ -90,6 +93,7 @@ struct GNUNET_TIME_RelativeNBO
 {
   /**
    * The actual value (in network byte order).
+   * UINT64_MAX represents "forever".
    */
   uint64_t rel_value_us__ GNUNET_PACKED;
 };
@@ -102,6 +106,7 @@ struct GNUNET_TIME_AbsoluteNBO
 {
   /**
    * The actual value (in network byte order).
+   * UINT64_MAX represents "never".
    */
   uint64_t abs_value_us__ GNUNET_PACKED;
 };
@@ -112,7 +117,8 @@ struct GNUNET_TIME_AbsoluteNBO
 struct GNUNET_TIME_TimestampNBO
 {
   /**
-   * The actual value. Must be round number in seconds.
+   * The actual value. Must be round number in seconds *or*
+   * UINT64_MAX to represent "never".
    */
   struct GNUNET_TIME_AbsoluteNBO abs_time_nbo;
 };
@@ -163,53 +169,55 @@ GNUNET_NETWORK_STRUCT_END
  * One day.
  */
 #define GNUNET_TIME_UNIT_DAYS    GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_HOURS, 24)
+          GNUNET_TIME_UNIT_HOURS, 24)
 
 /**
  * One week.
  */
 #define GNUNET_TIME_UNIT_WEEKS   GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_DAYS, 7)
+          GNUNET_TIME_UNIT_DAYS, 7)
 
 /**
  * One month (30 days).
  */
 #define GNUNET_TIME_UNIT_MONTHS  GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_DAYS, 30)
+          GNUNET_TIME_UNIT_DAYS, 30)
 
 /**
  * One year (365 days).
  */
 #define GNUNET_TIME_UNIT_YEARS   GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_DAYS, 365)
+          GNUNET_TIME_UNIT_DAYS, 365)
 
 /**
  * Constant used to specify "forever".  This constant
  * will be treated specially in all time operations.
  */
 #define GNUNET_TIME_UNIT_FOREVER_REL \
-  ((struct GNUNET_TIME_Relative){UINT64_MAX})
+        ((struct GNUNET_TIME_Relative){UINT64_MAX})
 
 /**
  * Constant used to specify "forever".  This constant
  * will be treated specially in all time operations.
  */
 #define GNUNET_TIME_UNIT_FOREVER_ABS \
-  ((struct GNUNET_TIME_Absolute){UINT64_MAX})
+        ((struct GNUNET_TIME_Absolute){UINT64_MAX})
+#define GNUNET_TIME_UNIT_NEVER_ABS \
+        ((struct GNUNET_TIME_Absolute){UINT64_MAX})
 
 /**
  * Constant used to specify "forever".  This constant
  * will be treated specially in all time operations.
  */
 #define GNUNET_TIME_UNIT_FOREVER_TS \
-  ((struct GNUNET_TIME_Timestamp){{UINT64_MAX}})
+        ((struct GNUNET_TIME_Timestamp){{UINT64_MAX}})
 
 
 /**
  * Threshold after which exponential backoff should not increase (15 m).
  */
 #define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD \
-  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+        GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
 
 
 /**
@@ -219,9 +227,9 @@ GNUNET_NETWORK_STRUCT_END
  * @param r current backoff time, initially zero
  */
 #define GNUNET_TIME_STD_BACKOFF(r) GNUNET_TIME_relative_min ( \
-    GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, \
-    GNUNET_TIME_relative_multiply ( \
-      GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, (r)), 2))
+          GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, \
+          GNUNET_TIME_relative_multiply ( \
+            GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, (r)), 2))
 
 
 /**
@@ -411,7 +419,7 @@ GNUNET_TIME_timestamp_get (void);
  * @return true if @a t1 @a op @a t2
  */
 #define GNUNET_TIME_absolute_cmp(t1,op,t2) \
-  ((void) (1 op 2), (t1).abs_value_us op (t2).abs_value_us)
+        ((void) (1 op 2), (t1).abs_value_us op (t2).abs_value_us)
 
 
 /**
@@ -423,7 +431,7 @@ GNUNET_TIME_timestamp_get (void);
  * @return true if @a t1 @a op @a t2
  */
 #define GNUNET_TIME_timestamp_cmp(t1,op,t2) \
-  GNUNET_TIME_absolute_cmp ((t1).abs_time,op,(t2).abs_time)
+        GNUNET_TIME_absolute_cmp ((t1).abs_time,op,(t2).abs_time)
 
 
 /**
@@ -435,7 +443,7 @@ GNUNET_TIME_timestamp_get (void);
  * @return true if @a t1 @a op @a t2
  */
 #define GNUNET_TIME_relative_cmp(t1,op,t2) \
-  ((void) (1 op 2), (t1).rel_value_us op (t2).rel_value_us)
+        ((void) (1 op 2), (t1).rel_value_us op (t2).rel_value_us)
 
 
 /**
diff --git a/src/lib/util/time.c b/src/lib/util/time.c
index aec4ded4f..04bf92870 100644
--- a/src/lib/util/time.c
+++ b/src/lib/util/time.c
@@ -218,7 +218,7 @@ GNUNET_TIME_timestamp2s (struct GNUNET_TIME_Timestamp ts)
   struct tm *tp;
 
   if (GNUNET_TIME_absolute_is_never (ts.abs_time))
-    return "end of time";
+    return "never";
   tt = ts.abs_time.abs_value_us / 1000LL / 1000LL;
   tp = localtime (&tt);
   /* This is hacky, but i don't know a way to detect libc character encoding.
@@ -243,7 +243,7 @@ GNUNET_TIME_absolute2s (struct GNUNET_TIME_Absolute t)
   struct tm *tp;
 
   if (GNUNET_TIME_absolute_is_never (t))
-    return "end of time";
+    return "never";
   tt = t.abs_value_us / 1000LL / 1000LL;
   tp = localtime (&tt);
   /* This is hacky, but i don't know a way to detect libc character encoding.
@@ -397,7 +397,7 @@ GNUNET_TIME_absolute_round_down (struct 
GNUNET_TIME_Absolute at,
   GNUNET_assert (! GNUNET_TIME_relative_is_zero (rt));
   ret.abs_value_us
     = at.abs_value_us
-    - at.abs_value_us % rt.rel_value_us;
+      - at.abs_value_us % rt.rel_value_us;
   return ret;
 }
 
@@ -504,7 +504,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative 
rel,
 
 struct GNUNET_TIME_Relative
 GNUNET_TIME_relative_multiply_double (struct GNUNET_TIME_Relative rel,
-                          double factor)
+                                      double factor)
 {
   struct GNUNET_TIME_Relative out;
   double m;
@@ -731,6 +731,8 @@ GNUNET_TIME_timestamp_from_s (uint64_t s_after_epoch)
 uint64_t
 GNUNET_TIME_timestamp_to_s (struct GNUNET_TIME_Timestamp ts)
 {
+  if (GNUNET_TIME_absolute_is_never (ts.abs_value))
+    return UINT64_MAX;
   return ts.abs_time.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us;
 }
 
@@ -928,7 +930,8 @@ GNUNET_TIME_absolute_get_monotonic (
           if (NULL == map)
             GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                         _ (
-                          "Failed to map `%s', cannot assure monotonic 
time!\n"),
+                          "Failed to map `%s', cannot assure monotonic 
time!\n")
+                        ,
                         filename);
         }
         else
@@ -979,6 +982,7 @@ GNUNET_TIME_absolute_get_monotonic (
   return now;
 }
 
+
 void
 GNUNET_util_time_fini (void);
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]