summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-20 10:47:53 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-20 10:47:53 +0000
commit3453b2bd0e186788bb81deff5d723cf48e10881f (patch)
tree329d42bdbd0d45463caf6b6f3c67c9443f9153be /thread.c
parentd481323b9211cc0823fba407253d0432fa7f1734 (diff)
* gc.h, vm_core.h: decl of rb_gc_save_machine_context()
should be at vm_core.h. * include/ruby/ruby.h, intern.h: remove type rb_thread_t. * include/ruby/intern.h: change rb_unblock_function_t, rb_unblock_function_t. * file.c, process.c: apply above changes. * thread.c, thread_pthread.ci, thread_win32.ci: ditto. * io.c: support blocking open (2). [ruby-core:13614] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/thread.c b/thread.c
index 070433e4fc..1655ce0548 100644
--- a/thread.c
+++ b/thread.c
@@ -220,7 +220,7 @@ rb_thread_interrupt(rb_thread_t *th)
native_mutex_lock(&th->interrupt_lock);
th->interrupt_flag = 1;
if (th->unblock_function) {
- (th->unblock_function)(th, th->unblock_function_arg);
+ (th->unblock_function)(th->unblock_function_arg);
}
else {
/* none */
@@ -671,10 +671,11 @@ rb_thread_blocking_region(
if (ubf == RB_UBF_DFL) {
ubf = ubf_select;
+ data2 = th;
}
BLOCKING_REGION({
- val = func(th, data1);
+ val = func(data1);
}, ubf, data2);
return val;
@@ -1757,7 +1758,7 @@ do_select(int n, fd_set *read, fd_set *write, fd_set *except,
BLOCKING_REGION({
result = select(n, read, write, except, timeout);
if (result < 0) lerrno = errno;
- }, ubf_select, 0);
+ }, ubf_select, GET_THREAD());
#endif
errno = lerrno;
@@ -2253,38 +2254,37 @@ rb_mutex_trylock(VALUE self)
}
static VALUE
-lock_func(rb_thread_t *th, void *ptr)
+lock_func(rb_thread_t *th, mutex_t *mutex)
{
int locked = 0;
- mutex_t *mutex = (mutex_t *)ptr;
while (locked == 0) {
native_mutex_lock(&mutex->lock);
-
- if (mutex->th == 0) {
- mutex->th = th;
- locked = 1;
- }
- else {
- mutex->cond_waiting++;
- native_cond_wait(&mutex->cond, &mutex->lock);
-
- if (th->interrupt_flag) {
- locked = 1;
- }
- else if (mutex->th == 0) {
+ {
+ if (mutex->th == 0) {
mutex->th = th;
locked = 1;
}
- }
+ else {
+ mutex->cond_waiting++;
+ native_cond_wait(&mutex->cond, &mutex->lock);
+ if (th->interrupt_flag) {
+ locked = 1;
+ }
+ else if (mutex->th == 0) {
+ mutex->th = th;
+ locked = 1;
+ }
+ }
+ }
native_mutex_unlock(&mutex->lock);
}
return Qnil;
}
static void
-lock_interrupt(rb_thread_t *th, void *ptr)
+lock_interrupt(void *ptr)
{
mutex_t *mutex = (mutex_t *)ptr;
native_mutex_lock(&mutex->lock);
@@ -2311,11 +2311,13 @@ rb_mutex_lock(VALUE self)
GetMutexPtr(self, mutex);
while (mutex->th != th) {
- rb_thread_blocking_region(lock_func, mutex, lock_interrupt, mutex);
+ BLOCKING_REGION({
+ lock_func(th, mutex);
+ }, lock_interrupt, mutex);
+
RUBY_VM_CHECK_INTS();
}
}
-
return self;
}