[前][次][番号順一覧][スレッド一覧]

ruby-changes:71555

From: Yusuke <ko1@a...>
Date: Wed, 30 Mar 2022 16:51:01 +0900 (JST)
Subject: [ruby-changes:71555] a94002115b (master): thread.c: Move double2hrtime and hrtime2double to hrtime.h

https://git.ruby-lang.org/ruby.git/commit/?id=a94002115b

From a94002115beaf989aec4c9b2a746ac8d19440e57 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Wed, 23 Mar 2022 18:41:36 +0900
Subject: thread.c: Move double2hrtime and hrtime2double to hrtime.h

... to make them available in other places than thread.c
---
 hrtime.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 thread.c | 40 ----------------------------------------
 2 files changed, 48 insertions(+), 40 deletions(-)

diff --git a/hrtime.h b/hrtime.h
index f133bdb1ac..4ac3d54723 100644
--- a/hrtime.h
+++ b/hrtime.h
@@ -165,4 +165,52 @@ rb_hrtime2timeval(struct timeval *tv, const rb_hrtime_t *hrt) https://github.com/ruby/ruby/blob/trunk/hrtime.h#L165
     }
     return 0;
 }
+
+#include "internal/warnings.h"
+#include "internal/time.h"
+
+/*
+ * Back when we used "struct timeval", not all platforms implemented
+ * tv_sec as time_t.  Nowadays we use "struct timespec" and tv_sec
+ * seems to be implemented more consistently across platforms.
+ * At least other parts of our code hasn't had to deal with non-time_t
+ * tv_sec in timespec...
+ */
+#define TIMESPEC_SEC_MAX TIMET_MAX
+#define TIMESPEC_SEC_MIN TIMET_MIN
+
+COMPILER_WARNING_PUSH
+#if __has_warning("-Wimplicit-int-float-conversion")
+COMPILER_WARNING_IGNORED(-Wimplicit-int-float-conversion)
+#elif defined(_MSC_VER)
+/* C4305: 'initializing': truncation from '__int64' to 'const double' */
+COMPILER_WARNING_IGNORED(4305)
+#endif
+static const double TIMESPEC_SEC_MAX_as_double = TIMESPEC_SEC_MAX;
+COMPILER_WARNING_POP
+
+static inline rb_hrtime_t *
+double2hrtime(rb_hrtime_t *hrt, double d)
+{
+    /* assume timespec.tv_sec has same signedness as time_t */
+    const double TIMESPEC_SEC_MAX_PLUS_ONE = 2.0 * (TIMESPEC_SEC_MAX_as_double / 2.0 + 1.0);
+
+    if (TIMESPEC_SEC_MAX_PLUS_ONE <= d) {
+        return NULL;
+    }
+    else if (d <= 0) {
+        *hrt = 0;
+    }
+    else {
+        *hrt = (rb_hrtime_t)(d * (double)RB_HRTIME_PER_SEC);
+    }
+    return hrt;
+}
+
+static inline double
+hrtime2double(rb_hrtime_t hrt)
+{
+    return (double)hrt / (double)RB_HRTIME_PER_SEC;
+}
+
 #endif /* RB_HRTIME_H */
diff --git a/thread.c b/thread.c
index 5df4d68b45..def684fd56 100644
--- a/thread.c
+++ b/thread.c
@@ -1144,8 +1144,6 @@ remove_from_join_list(VALUE arg) https://github.com/ruby/ruby/blob/trunk/thread.c#L1144
     return Qnil;
 }
 
-static rb_hrtime_t *double2hrtime(rb_hrtime_t *, double);
-
 static int
 thread_finished(rb_thread_t *th)
 {
@@ -1352,44 +1350,6 @@ thread_value(VALUE self) https://github.com/ruby/ruby/blob/trunk/thread.c#L1350
  * Thread Scheduling
  */
 
-/*
- * Back when we used "struct timeval", not all platforms implemented
- * tv_sec as time_t.  Nowadays we use "struct timespec" and tv_sec
- * seems to be implemented more consistently across platforms.
- * At least other parts of our code hasn't had to deal with non-time_t
- * tv_sec in timespec...
- */
-#define TIMESPEC_SEC_MAX TIMET_MAX
-#define TIMESPEC_SEC_MIN TIMET_MIN
-
-COMPILER_WARNING_PUSH
-#if __has_warning("-Wimplicit-int-float-conversion")
-COMPILER_WARNING_IGNORED(-Wimplicit-int-float-conversion)
-#elif defined(_MSC_VER)
-/* C4305: 'initializing': truncation from '__int64' to 'const double' */
-COMPILER_WARNING_IGNORED(4305)
-#endif
-static const double TIMESPEC_SEC_MAX_as_double = TIMESPEC_SEC_MAX;
-COMPILER_WARNING_POP
-
-static rb_hrtime_t *
-double2hrtime(rb_hrtime_t *hrt, double d)
-{
-    /* assume timespec.tv_sec has same signedness as time_t */
-    const double TIMESPEC_SEC_MAX_PLUS_ONE = 2.0 * (TIMESPEC_SEC_MAX_as_double / 2.0 + 1.0);
-
-    if (TIMESPEC_SEC_MAX_PLUS_ONE <= d) {
-        return NULL;
-    }
-    else if (d <= 0) {
-        *hrt = 0;
-    }
-    else {
-        *hrt = (rb_hrtime_t)(d * (double)RB_HRTIME_PER_SEC);
-    }
-    return hrt;
-}
-
 static void
 getclockofday(struct timespec *ts)
 {
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]