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

ruby-changes:50340

From: normal <ko1@a...>
Date: Sun, 18 Feb 2018 09:38:47 +0900 (JST)
Subject: [ruby-changes:50340] normal:r62455 (trunk): thread.c (timespec_update_expire): improve naming

normal	2018-02-18 09:38:40 +0900 (Sun, 18 Feb 2018)

  New Revision: 62455

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62455

  Log:
    thread.c (timespec_update_expire): improve naming
    
    Naming the constant timespec as "end" should make it more
    apparent is is an absolute time.  Update callers, too.

  Modified files:
    trunk/thread.c
Index: thread.c
===================================================================
--- thread.c	(revision 62454)
+++ thread.c	(revision 62455)
@@ -911,11 +911,11 @@ thread_join_sleep(VALUE arg) https://github.com/ruby/ruby/blob/trunk/thread.c#L911
 {
     struct join_arg *p = (struct join_arg *)arg;
     rb_thread_t *target_th = p->target, *th = p->waiting;
-    struct timespec to;
+    struct timespec end;
 
     if (p->limit) {
-        getclockofday(&to);
-        timespec_add(&to, p->limit);
+        getclockofday(&end);
+        timespec_add(&end, p->limit);
     }
 
     while (target_th->status != THREAD_KILLED) {
@@ -927,7 +927,7 @@ thread_join_sleep(VALUE arg) https://github.com/ruby/ruby/blob/trunk/thread.c#L927
 	    th->vm->sleeper--;
 	}
 	else {
-            if (timespec_update_expire(p->limit, &to)) {
+            if (timespec_update_expire(p->limit, &end)) {
 		thread_debug("thread_join: timeout (thid: %"PRI_THREAD_ID")\n",
 			     thread_id_str(target_th));
 		return Qfalse;
@@ -1197,19 +1197,24 @@ timespec_sub(struct timespec *dst, const https://github.com/ruby/ruby/blob/trunk/thread.c#L1197
     }
 }
 
+/*
+ * @end is the absolute time when @ts is set to expire
+ * Returns true if @end has past
+ * Updates @ts and returns false otherwise
+ */
 static int
-timespec_update_expire(struct timespec *ts, const struct timespec *to)
+timespec_update_expire(struct timespec *ts, const struct timespec *end)
 {
     struct timespec now;
 
     getclockofday(&now);
-    if (to->tv_sec < now.tv_sec) return 1;
-    if (to->tv_sec == now.tv_sec && to->tv_nsec <= now.tv_nsec) return 1;
+    if (end->tv_sec < now.tv_sec) return 1;
+    if (end->tv_sec == now.tv_sec && end->tv_nsec <= now.tv_nsec) return 1;
     thread_debug("timespec_update_expire: "
 		 "%"PRI_TIMET_PREFIX"d.%.6ld > %"PRI_TIMET_PREFIX"d.%.6ld\n",
-		 (time_t)to->tv_sec, (long)to->tv_nsec,
+		 (time_t)end->tv_sec, (long)end->tv_nsec,
 		 (time_t)now.tv_sec, (long)now.tv_nsec);
-    *ts = *to;
+    *ts = *end;
     timespec_sub(ts, &now);
     return 0;
 }
@@ -1217,17 +1222,17 @@ timespec_update_expire(struct timespec * https://github.com/ruby/ruby/blob/trunk/thread.c#L1222
 static void
 sleep_timespec(rb_thread_t *th, struct timespec ts, int spurious_check)
 {
-    struct timespec to;
+    struct timespec end;
     enum rb_thread_status prev_status = th->status;
 
-    getclockofday(&to);
-    timespec_add(&to, &ts);
+    getclockofday(&end);
+    timespec_add(&end, &ts);
     th->status = THREAD_STOPPED;
     RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
     while (th->status == THREAD_STOPPED) {
 	native_sleep(th, &ts);
 	RUBY_VM_CHECK_INTS_BLOCKING(th->ec);
-	if (timespec_update_expire(&ts, &to))
+	if (timespec_update_expire(&ts, &end))
 	    break;
 	if (!spurious_check)
 	    break;

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

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