Skip to content

Commit

Permalink
Handle signals after pthread_cond_wait is interrupted
Browse files Browse the repository at this point in the history
There might be signals that need to be run if pthread_cond_wait is
interrupted. Fixes rubinius#2093
  • Loading branch information
dbussink committed Feb 5, 2013
1 parent 72b94d3 commit 761cafc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
8 changes: 7 additions & 1 deletion vm/builtin/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ namespace rubinius {

self->waiters_++;

bool exception = false;

for(;;) {
{
GCIndependent gc_guard(state, call_frame);
Expand All @@ -192,6 +194,10 @@ namespace rubinius {

// or there are values available.
if(self->semaphore_count_ > 0 || !self->value()->empty_p()) break;
if(!state->check_async(call_frame)) {
exception = true;
break;
}
}

state->vm()->clear_waiter();
Expand All @@ -200,7 +206,7 @@ namespace rubinius {
self->unpin();
self->waiters_--;

if(!state->check_async(call_frame)) return NULL;
if(exception || !state->check_async(call_frame)) return NULL;

if(self->semaphore_count_ > 0) {
self->semaphore_count_--;
Expand Down
28 changes: 21 additions & 7 deletions vm/park.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ namespace rubinius {
sleeping_ = true;
state->vm()->thread->sleep(state, cTrue);

Object* result = cNil;
while(!wake_) {
GCIndependent gc_guard(state, call_frame);
{
GCIndependent gc_guard(state, call_frame);

cond_.wait(mutex_);
cond_.wait(mutex_);
}
if(!state->check_async(call_frame)) {
result = NULL;
break;
}
}

sleeping_ = false;
state->vm()->thread->sleep(state, cFalse);
return cNil;
return result;
}

Object* Park::park_timed(STATE, CallFrame* call_frame, struct timespec* ts) {
Expand All @@ -33,10 +40,17 @@ namespace rubinius {
Object* timeout = cFalse;

while(!wake_) {
GCIndependent gc_guard(state, call_frame);

if(cond_.wait_until(mutex_, ts) == utilities::thread::cTimedOut) {
timeout = cTrue;
{
GCIndependent gc_guard(state, call_frame);

utilities::thread::Code status = cond_.wait_until(mutex_, ts);
if(status == utilities::thread::cTimedOut) {
timeout = cTrue;
break;
}
}
if(!state->check_async(call_frame)) {
timeout = NULL;
break;
}
}
Expand Down

0 comments on commit 761cafc

Please sign in to comment.