summaryrefslogtreecommitdiff
path: root/ext/thread
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-27 11:51:55 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-27 11:51:55 +0000
commit9369118f8f4ed02c76839c6a67c268a2de9acde9 (patch)
tree1c5e7235b590e1431f70ab743b4ac7314c7a0d81 /ext/thread
parentb7111d382c16ee89dae3c19c756ce2272190d55a (diff)
Merge changes between r11871 and r11907 from ruby_1_8.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@11908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/thread')
-rw-r--r--ext/thread/thread.c57
1 files changed, 21 insertions, 36 deletions
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index c65c4bbe52..354e1445e7 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -18,21 +18,14 @@ static VALUE rb_cConditionVariable;
static VALUE rb_cQueue;
static VALUE rb_cSizedQueue;
-static VALUE
-thread_exclusive_do()
-{
- rb_thread_critical = Qtrue;
-
- return rb_yield(Qundef);
-}
+static VALUE set_critical(VALUE value);
static VALUE
-thread_exclusive_ensure(val)
- VALUE val;
+thread_exclusive_do(void)
{
- rb_thread_critical = val;
+ rb_thread_critical = 1;
- return Qundef;
+ return rb_yield(Qundef);
}
/*
@@ -45,9 +38,9 @@ thread_exclusive_ensure(val)
*/
static VALUE
-rb_thread_exclusive()
+rb_thread_exclusive(void)
{
- return rb_ensure(thread_exclusive_do, Qundef, thread_exclusive_ensure, rb_thread_critical);
+ return rb_ensure(thread_exclusive_do, Qundef, set_critical, rb_thread_critical);
}
typedef struct _Entry {
@@ -86,7 +79,7 @@ free_entries(Entry *first)
Entry *next;
while (first) {
next = first->next;
- free(first);
+ xfree(first);
first = next;
}
}
@@ -107,7 +100,7 @@ push_list(List *list, VALUE value)
entry = list->entry_pool;
list->entry_pool = entry->next;
} else {
- entry = (Entry *)malloc(sizeof(Entry));
+ entry = (Entry *)xmalloc(sizeof(Entry));
}
entry->value = value;
@@ -254,9 +247,7 @@ static VALUE
wait_list_cleanup(List *list)
{
/* cleanup in case of spurious wakeups */
- rb_thread_critical = 1;
remove_one(list, rb_thread_current());
- rb_thread_critical = 0;
return Qnil;
}
@@ -325,7 +316,7 @@ free_mutex(Mutex *mutex)
{
assert_no_survivors(&mutex->waiting, "mutex", mutex);
finalize_mutex(mutex);
- free(mutex);
+ xfree(mutex);
}
static void
@@ -347,7 +338,7 @@ static VALUE
rb_mutex_alloc(VALUE klass)
{
Mutex *mutex;
- mutex = (Mutex *)malloc(sizeof(Mutex));
+ mutex = (Mutex *)xmalloc(sizeof(Mutex));
init_mutex(mutex);
return Data_Wrap_Struct(klass, mark_mutex, free_mutex, mutex);
}
@@ -381,20 +372,14 @@ static VALUE
rb_mutex_try_lock(VALUE self)
{
Mutex *mutex;
- VALUE result;
Data_Get_Struct(self, Mutex, mutex);
- result = Qfalse;
-
- rb_thread_critical = 1;
- if (!RTEST(mutex->owner)) {
- mutex->owner = rb_thread_current();
- result = Qtrue;
- }
- rb_thread_critical = 0;
+ if (RTEST(mutex->owner))
+ return Qfalse;
- return result;
+ mutex->owner = rb_thread_current();
+ return Qtrue;
}
/*
@@ -456,7 +441,7 @@ static VALUE
set_critical(VALUE value)
{
rb_thread_critical = (int)value;
- return Qnil;
+ return Qundef;
}
static VALUE
@@ -598,7 +583,7 @@ free_condvar(ConditionVariable *condvar)
{
assert_no_survivors(&condvar->waiting, "condition variable", condvar);
finalize_condvar(condvar);
- free(condvar);
+ xfree(condvar);
}
static void
@@ -620,7 +605,7 @@ rb_condvar_alloc(VALUE klass)
{
ConditionVariable *condvar;
- condvar = (ConditionVariable *)malloc(sizeof(ConditionVariable));
+ condvar = (ConditionVariable *)xmalloc(sizeof(ConditionVariable));
init_condvar(condvar);
return Data_Wrap_Struct(klass, mark_condvar, free_condvar, condvar);
@@ -639,11 +624,11 @@ wait_condvar(ConditionVariable *condvar, Mutex *mutex)
{
rb_thread_critical = 1;
if (!RTEST(mutex->owner)) {
- rb_thread_critical = Qfalse;
+ rb_thread_critical = 0;
return;
}
if (mutex->owner != rb_thread_current()) {
- rb_thread_critical = Qfalse;
+ rb_thread_critical = 0;
rb_raise(rb_eThreadError, "Not owner");
}
mutex->owner = Qnil;
@@ -806,7 +791,7 @@ free_queue(Queue *queue)
assert_no_survivors(&queue->space_available.waiting, "queue", queue);
assert_no_survivors(&queue->value_available.waiting, "queue", queue);
finalize_queue(queue);
- free(queue);
+ xfree(queue);
}
static void
@@ -831,7 +816,7 @@ static VALUE
rb_queue_alloc(VALUE klass)
{
Queue *queue;
- queue = (Queue *)malloc(sizeof(Queue));
+ queue = (Queue *)xmalloc(sizeof(Queue));
init_queue(queue);
return Data_Wrap_Struct(klass, mark_queue, free_queue, queue);
}