summaryrefslogtreecommitdiff
path: root/thread_sync.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-07 01:57:14 (GMT)
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-07 01:57:14 (GMT)
commit0abd9b7f252129aae0c3f164e64dcb8479f661bc (patch)
tree0a5272569d2e9cd8dff1eee82daf942ac1143710 /thread_sync.c
parentb16eaf86324b000c4c349e072e15b97dde701e48 (diff)
thread.c: favor timespec internally
This results in fewer conversion on common modern systems with support for clock_gettime, pthread_cond_timedwait and ppoll. gettimeofday is declared obsolete by POSIX.1-2008, so it is yet another reason to move away from it. This also appears to result in the reduction of compatibility code required for dealing with inconsistent implementations of "struct timeval".tv_sec In the future, this will also result in fewer conversions for kqueue and pselect if we elect to use them. [ruby-core:85416] [Feature #14452] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread_sync.c')
-rw-r--r--thread_sync.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/thread_sync.c b/thread_sync.c
index 094d9b8..8506bff 100644
--- a/thread_sync.c
+++ b/thread_sync.c
@@ -252,8 +252,8 @@ rb_mutex_lock(VALUE self)
while (mutex->th != th) {
enum rb_thread_status prev_status = th->status;
- struct timeval *timeout = 0;
- struct timeval tv = { 0, 100000 }; /* 100ms */
+ struct timespec *timeout = 0;
+ struct timespec ts = { 0, 100000000 }; /* 100ms */
th->status = THREAD_STOPPED_FOREVER;
th->locking_mutex = self;
@@ -265,7 +265,7 @@ rb_mutex_lock(VALUE self)
*/
if ((vm_living_thread_num(th->vm) == th->vm->sleeper) &&
!patrol_thread) {
- timeout = &tv;
+ timeout = &ts;
patrol_thread = th;
}
@@ -427,8 +427,8 @@ rb_mutex_sleep_forever(VALUE time)
static VALUE
rb_mutex_wait_for(VALUE time)
{
- struct timeval *t = (struct timeval *)time;
- sleep_timeval(GET_THREAD(), *t, 0); /* permit spurious check */
+ struct timespec *t = (struct timespec*)time;
+ sleep_timespec(GET_THREAD(), *t, 0); /* permit spurious check */
return Qnil;
}
@@ -447,7 +447,10 @@ rb_mutex_sleep(VALUE self, VALUE timeout)
rb_ensure(rb_mutex_sleep_forever, Qnil, rb_mutex_lock, self);
}
else {
- rb_ensure(rb_mutex_wait_for, (VALUE)&t, rb_mutex_lock, self);
+ struct timespec ts;
+ VALUE tsp = (VALUE)timespec_for(&ts, &t);
+
+ rb_ensure(rb_mutex_wait_for, tsp, rb_mutex_lock, self);
}
end = time(0) - beg;
return INT2FIX(end);