Skip to content

Commit 14579de

Browse files
committed
merge revision(s) 17874,17886:
* eval.c (rb_thread_join): new API. * ext/thread/thread.c (wait_mutex, lock_mutex): wait until the locking thread exits. [ruby-dev:34856] * eval.c (rb_thread_value): missed to change at r17874. [ruby-core:17595] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@23042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent caaa35f commit 14579de

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
Mon Mar 23 18:12:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* eval.c (rb_thread_value): missed to change at r17874. [ruby-core:17595]
4+
5+
Mon Mar 23 18:12:47 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
6+
7+
* eval.c (rb_thread_join): new API.
8+
9+
* ext/thread/thread.c (wait_mutex, lock_mutex): wait until the locking
10+
thread exits. [ruby-dev:34856]
11+
112
Mon Mar 23 17:39:29 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
213

314
* file.c (file_load_ok): checks if regular file, except for the

eval.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,8 +1441,6 @@ eval_node(self, node)
14411441

14421442
int ruby_in_eval;
14431443

1444-
static int rb_thread_join _((rb_thread_t, double));
1445-
14461444
static void rb_thread_cleanup _((void));
14471445
static void rb_thread_wait_other_threads _((void));
14481446

@@ -11130,8 +11128,11 @@ rb_thread_select(max, read, write, except, timeout)
1113011128
return curr_thread->select_value;
1113111129
}
1113211130

11131+
static int rb_thread_join0 _((rb_thread_t, double));
11132+
int rb_thread_join _((VALUE, double));
11133+
1113311134
static int
11134-
rb_thread_join(th, limit)
11135+
rb_thread_join0(th, limit)
1113511136
rb_thread_t th;
1113611137
double limit;
1113711138
{
@@ -11173,6 +11174,15 @@ rb_thread_join(th, limit)
1117311174
return Qtrue;
1117411175
}
1117511176

11177+
int
11178+
rb_thread_join(thread, limit)
11179+
VALUE thread;
11180+
double limit;
11181+
{
11182+
if (limit < 0) limit = DELAY_INFTY;
11183+
return rb_thread_join0(rb_thread_check(thread), limit);
11184+
}
11185+
1117611186

1117711187
/*
1117811188
* call-seq:
@@ -11222,11 +11232,10 @@ rb_thread_join_m(argc, argv, thread)
1122211232
{
1122311233
VALUE limit;
1122411234
double delay = DELAY_INFTY;
11225-
rb_thread_t th = rb_thread_check(thread);
1122611235

1122711236
rb_scan_args(argc, argv, "01", &limit);
1122811237
if (!NIL_P(limit)) delay = rb_num2dbl(limit);
11229-
if (!rb_thread_join(th, delay))
11238+
if (!rb_thread_join0(rb_thread_check(thread), delay))
1123011239
return Qnil;
1123111240
return thread;
1123211241
}
@@ -12269,7 +12278,7 @@ rb_thread_value(thread)
1226912278
{
1227012279
rb_thread_t th = rb_thread_check(thread);
1227112280

12272-
while (!rb_thread_join(th, DELAY_INFTY));
12281+
while (!rb_thread_join0(th, DELAY_INFTY));
1227312282

1227412283
return th->result;
1227512284
}

ext/thread/thread.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,22 @@ wake_all(List *list)
247247
return Qnil;
248248
}
249249

250+
extern int rb_thread_join _((VALUE thread, double limit));
251+
#define DELAY_INFTY 1E30
252+
250253
static VALUE
251-
wait_list_inner(List *list)
254+
wait_list_inner(VALUE arg)
252255
{
253-
push_list(list, rb_thread_current());
256+
push_list((List *)arg, rb_thread_current());
254257
rb_thread_stop();
255258
return Qnil;
256259
}
257260

258261
static VALUE
259-
wait_list_cleanup(List *list)
262+
wait_list_cleanup(VALUE arg)
260263
{
261264
/* cleanup in case of spurious wakeups */
262-
remove_one(list, rb_thread_current());
265+
remove_one((List *)arg, rb_thread_current());
263266
return Qnil;
264267
}
265268

@@ -395,6 +398,25 @@ rb_mutex_try_lock(VALUE self)
395398
return Qtrue;
396399
}
397400

401+
static VALUE
402+
wait_mutex(VALUE arg)
403+
{
404+
Mutex *mutex = (Mutex *)arg;
405+
VALUE current = rb_thread_current();
406+
407+
push_list(&mutex->waiting, current);
408+
do {
409+
rb_thread_critical = 0;
410+
rb_thread_join(mutex->owner, DELAY_INFTY);
411+
rb_thread_critical = 1;
412+
if (!MUTEX_LOCKED_P(mutex)) {
413+
mutex->owner = current;
414+
break;
415+
}
416+
} while (mutex->owner != current);
417+
return Qnil;
418+
}
419+
398420
/*
399421
* Document-method: lock
400422
* call-seq: lock
@@ -415,14 +437,7 @@ lock_mutex(Mutex *mutex)
415437
mutex->owner = current;
416438
}
417439
else {
418-
do {
419-
wait_list(&mutex->waiting);
420-
rb_thread_critical = 1;
421-
if (!MUTEX_LOCKED_P(mutex)) {
422-
mutex->owner = current;
423-
break;
424-
}
425-
} while (mutex->owner != current);
440+
rb_ensure(wait_mutex, (VALUE)mutex, wait_list_cleanup, (VALUE)&mutex->waiting);
426441
}
427442

428443
rb_thread_critical = 0;

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define RUBY_RELEASE_DATE "2009-03-23"
33
#define RUBY_VERSION_CODE 186
44
#define RUBY_RELEASE_CODE 20090323
5-
#define RUBY_PATCHLEVEL 363
5+
#define RUBY_PATCHLEVEL 364
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8

0 commit comments

Comments
 (0)