summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-09 11:48:34 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-09 11:48:34 +0000
commitb28988b4f18f34ced254373593de702fa97cff63 (patch)
tree0b2b65031eef87df776e14a24c7727621519d7f9 /ext
parentfff0db9dfe21f0cfb9394e8968d493ad1d5eaa6e (diff)
* ext/thread: Make style fixes (mostly de-K&R'ism) to match the
rest of the source code. * ext/thread: Make USE_MEM_POOLS an extconf option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/thread/extconf.rb5
-rw-r--r--ext/thread/thread.c1198
2 files changed, 507 insertions, 696 deletions
diff --git a/ext/thread/extconf.rb b/ext/thread/extconf.rb
index f83daca..efe1d5d 100644
--- a/ext/thread/extconf.rb
+++ b/ext/thread/extconf.rb
@@ -1,2 +1,7 @@
require 'mkmf'
+
+if with_config('mem-pools', true)
+ $CPPFLAGS << ' -DUSE_MEM_POOLS'
+end
+
create_makefile("thread")
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index d4443ba..1ca5ee6 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -13,249 +13,199 @@
#include <intern.h>
#include <rubysig.h>
-#define USE_MEM_POOLS 1
-
static VALUE rb_cMutex;
static VALUE rb_cConditionVariable;
static VALUE rb_cQueue;
static VALUE rb_cSizedQueue;
static VALUE
-return_value(value)
- VALUE value;
+return_value(VALUE value)
{
- return value;
+ return value;
}
typedef struct _Entry {
- VALUE value;
- struct _Entry *next;
+ VALUE value;
+ struct _Entry *next;
} Entry;
typedef struct _List {
- Entry *entries;
- Entry *last_entry;
- Entry *entry_pool;
- unsigned long size;
+ Entry *entries;
+ Entry *last_entry;
+ Entry *entry_pool;
+ unsigned long size;
} List;
-static void init_list _((List *));
-
static void
-init_list(list)
- List *list;
+init_list(List *list)
{
- list->entries = NULL;
- list->last_entry = NULL;
- list->entry_pool = NULL;
- list->size = 0;
+ list->entries = NULL;
+ list->last_entry = NULL;
+ list->entry_pool = NULL;
+ list->size = 0;
}
-static void mark_list _((List *));
-
static void
-mark_list(list)
- List *list;
+mark_list(List *list)
{
- Entry *entry;
- for ( entry = list->entries ; entry ; entry = entry->next ) {
- rb_gc_mark(entry->value);
- }
+ Entry *entry;
+ for (entry = list->entries; entry; entry = entry->next) {
+ rb_gc_mark(entry->value);
+ }
}
-static void free_entries _((Entry *));
-
static void
-free_entries(first)
- Entry *first;
+free_entries(Entry *first)
{
- Entry *next;
- while (first) {
- next = first->next;
- free(first);
- first = next;
- }
+ Entry *next;
+ while (first) {
+ next = first->next;
+ free(first);
+ first = next;
+ }
}
-static void finalize_list _((List *));
-
static void
-finalize_list(list)
- List *list;
+finalize_list(List *list)
{
- free_entries(list->entries);
- free_entries(list->entry_pool);
+ free_entries(list->entries);
+ free_entries(list->entry_pool);
}
-static void push_list _((List *, VALUE));
-
static void
-push_list(list, value)
- List *list;
- VALUE value;
+push_list(List *list, VALUE value)
{
- Entry *entry;
-
- if (list->entry_pool) {
- entry = list->entry_pool;
- list->entry_pool = entry->next;
- } else {
- entry = (Entry *)malloc(sizeof(Entry));
- }
-
- entry->value = value;
- entry->next = NULL;
-
- if (list->last_entry) {
- list->last_entry->next = entry;
- } else {
- list->entries = entry;
- }
- list->last_entry = entry;
-
- ++list->size;
-}
+ Entry *entry;
+
+ if (list->entry_pool) {
+ entry = list->entry_pool;
+ list->entry_pool = entry->next;
+ } else {
+ entry = (Entry *)malloc(sizeof(Entry));
+ }
+
+ entry->value = value;
+ entry->next = NULL;
-static void push_multiple_list _((List *, VALUE *, unsigned));
+ if (list->last_entry) {
+ list->last_entry->next = entry;
+ } else {
+ list->entries = entry;
+ }
+ list->last_entry = entry;
+
+ ++list->size;
+}
static void
-push_multiple_list(list, values, count)
- List *list;
- VALUE *values;
- unsigned count;
+push_multiple_list(List *list, VALUE *values, unsigned count)
{
- unsigned i;
- for ( i = 0 ; i < count ; i++ ) {
- push_list(list, values[i]);
- }
+ unsigned i;
+ for (i = 0; i < count; i++) {
+ push_list(list, values[i]);
+ }
}
-static VALUE shift_list _((List *));
-
static VALUE
-shift_list(list)
- List *list;
+shift_list(List *list)
{
- Entry *entry;
- VALUE value;
+ Entry *entry;
+ VALUE value;
- entry = list->entries;
- if (!entry) return Qundef;
+ entry = list->entries;
+ if (!entry) return Qundef;
- list->entries = entry->next;
- if ( entry == list->last_entry ) {
- list->last_entry = NULL;
- }
+ list->entries = entry->next;
+ if (entry == list->last_entry) {
+ list->last_entry = NULL;
+ }
- --list->size;
+ --list->size;
- value = entry->value;
- if (USE_MEM_POOLS) {
+ value = entry->value;
+#ifdef USE_MEM_POOLS
entry->next = list->entry_pool;
list->entry_pool = entry;
- } else {
+#else
free(entry);
- }
+#endif
- return value;
+ return value;
}
-static void clear_list _((List *));
-
static void
-clear_list(list)
- List *list;
+clear_list(List *list)
{
- if (list->last_entry) {
- if (USE_MEM_POOLS) {
- list->last_entry->next = list->entry_pool;
- list->entry_pool = list->entries;
- } else {
- free_entries(list->entries);
+ if (list->last_entry) {
+#ifdef USE_MEM_POOLS
+ list->last_entry->next = list->entry_pool;
+ list->entry_pool = list->entries;
+#else
+ free_entries(list->entries);
+#endif
+ list->entries = NULL;
+ list->last_entry = NULL;
+ list->size = 0;
}
- list->entries = NULL;
- list->last_entry = NULL;
- list->size = 0;
- }
}
-static VALUE array_from_list _((List const *));
-
static VALUE
-array_from_list(list)
- List const *list;
+array_from_list(List const *list)
{
- VALUE ary;
- Entry *entry;
- ary = rb_ary_new();
- for ( entry = list->entries ; entry ; entry = entry->next ) {
- rb_ary_push(ary, entry->value);
- }
- return ary;
+ VALUE ary;
+ Entry *entry;
+ ary = rb_ary_new();
+ for (entry = list->entries; entry; entry = entry->next) {
+ rb_ary_push(ary, entry->value);
+ }
+ return ary;
}
-static VALUE wake_thread _((VALUE));
-
static VALUE
-wake_thread(thread)
- VALUE thread;
+wake_thread(VALUE thread)
{
- return rb_rescue2(rb_thread_wakeup, thread,
- return_value, Qnil, rb_eThreadError, 0);
+ return rb_rescue2(rb_thread_wakeup, thread,
+ return_value, Qnil, rb_eThreadError, 0);
}
-static VALUE run_thread _((VALUE));
-
static VALUE
-run_thread(thread)
- VALUE thread;
+run_thread(VALUE thread)
{
- return rb_rescue2(rb_thread_run, thread,
- return_value, Qnil, rb_eThreadError, 0);
+ return rb_rescue2(rb_thread_run, thread,
+ return_value, Qnil, rb_eThreadError, 0);
}
-static VALUE wake_one _((List *));
-
static VALUE
-wake_one(list)
- List *list;
+wake_one(List *list)
{
- VALUE waking;
+ VALUE waking;
- waking = Qnil;
- while ( list->entries && !RTEST(waking) ) {
- waking = wake_thread(shift_list(list));
- }
+ waking = Qnil;
+ while (list->entries && !RTEST(waking)) {
+ waking = wake_thread(shift_list(list));
+ }
- return waking;
+ return waking;
}
-static VALUE wake_all _((List *));
-
static VALUE
-wake_all(list)
- List *list;
+wake_all(List *list)
{
- while (list->entries) {
- wake_one(list);
- }
- return Qnil;
+ while (list->entries) {
+ wake_one(list);
+ }
+ return Qnil;
}
-static void assert_no_survivors _((List *, const char *, void *));
-
static void
-assert_no_survivors(waiting, label, addr)
- List *waiting;
- const char *label;
- void *addr;
+assert_no_survivors(List *waiting, const char *label, void *addr)
{
- Entry *entry;
- for ( entry = waiting->entries ; entry ; entry = entry->next ) {
- if (RTEST(wake_thread(entry->value))) {
- rb_bug("%s %p freed with live thread(s) waiting", label, addr);
+ Entry *entry;
+ for (entry = waiting->entries; entry; entry = entry->next) {
+ if (RTEST(wake_thread(entry->value))) {
+ rb_bug("%s %p freed with live thread(s) waiting", label, addr);
+ }
}
- }
}
/*
@@ -284,48 +234,36 @@ assert_no_survivors(waiting, label, addr)
*/
typedef struct _Mutex {
- VALUE owner;
- List waiting;
+ VALUE owner;
+ List waiting;
} Mutex;
-static void mark_mutex _((Mutex *));
-
static void
-mark_mutex(mutex)
- Mutex *mutex;
+mark_mutex(Mutex *mutex)
{
- rb_gc_mark(mutex->owner);
- mark_list(&mutex->waiting);
+ rb_gc_mark(mutex->owner);
+ mark_list(&mutex->waiting);
}
-static void finalize_mutex _((Mutex *));
-
static void
-finalize_mutex(mutex)
- Mutex *mutex;
+finalize_mutex(Mutex *mutex)
{
- finalize_list(&mutex->waiting);
+ finalize_list(&mutex->waiting);
}
-static void free_mutex _((Mutex *));
-
static void
-free_mutex(mutex)
- Mutex *mutex;
+free_mutex(Mutex *mutex)
{
- assert_no_survivors(&mutex->waiting, "mutex", mutex);
- finalize_mutex(mutex);
- free(mutex);
+ assert_no_survivors(&mutex->waiting, "mutex", mutex);
+ finalize_mutex(mutex);
+ free(mutex);
}
-static void init_mutex _((Mutex *));
-
static void
-init_mutex(mutex)
- Mutex *mutex;
+init_mutex(Mutex *mutex)
{
- mutex->owner = Qnil;
- init_list(&mutex->waiting);
+ mutex->owner = Qnil;
+ init_list(&mutex->waiting);
}
/*
@@ -336,16 +274,13 @@ init_mutex(mutex)
*
*/
-static VALUE rb_mutex_alloc _((VALUE));
-
static VALUE
-rb_mutex_alloc(klass)
- VALUE klass;
+rb_mutex_alloc(VALUE klass)
{
- Mutex *mutex;
- mutex = (Mutex *)malloc(sizeof(Mutex));
- init_mutex(mutex);
- return Data_Wrap_Struct(klass, mark_mutex, free_mutex, mutex);
+ Mutex *mutex;
+ mutex = (Mutex *)malloc(sizeof(Mutex));
+ init_mutex(mutex);
+ return Data_Wrap_Struct(klass, mark_mutex, free_mutex, mutex);
}
/*
@@ -356,15 +291,12 @@ rb_mutex_alloc(klass)
*
*/
-static VALUE rb_mutex_locked_p _((VALUE));
-
static VALUE
-rb_mutex_locked_p(self)
- VALUE self;
+rb_mutex_locked_p(VALUE self)
{
- Mutex *mutex;
- Data_Get_Struct(self, Mutex, mutex);
- return ( RTEST(mutex->owner) ? Qtrue : Qfalse );
+ Mutex *mutex;
+ Data_Get_Struct(self, Mutex, mutex);
+ return RTEST(mutex->owner) ? Qtrue : Qfalse;
}
/*
@@ -376,27 +308,24 @@ rb_mutex_locked_p(self)
*
*/
-static VALUE rb_mutex_try_lock _((VALUE));
-
static VALUE
-rb_mutex_try_lock(self)
- VALUE self;
+rb_mutex_try_lock(VALUE self)
{
- Mutex *mutex;
- VALUE result;
+ Mutex *mutex;
+ VALUE result;
- Data_Get_Struct(self, Mutex, mutex);
+ Data_Get_Struct(self, Mutex, mutex);
- result = Qfalse;
+ result = Qfalse;
- rb_thread_critical = 1;
- if (!RTEST(mutex->owner)) {
- mutex->owner = rb_thread_current();
- result = Qtrue;
- }
- rb_thread_critical = 0;
+ rb_thread_critical = 1;
+ if (!RTEST(mutex->owner)) {
+ mutex->owner = rb_thread_current();
+ result = Qtrue;
+ }
+ rb_thread_critical = 0;
- return result;
+ return result;
}
/*
@@ -407,38 +336,32 @@ rb_mutex_try_lock(self)
*
*/
-static void lock_mutex _((Mutex *));
-
static void
-lock_mutex(mutex)
- Mutex *mutex;
+lock_mutex(Mutex *mutex)
{
- VALUE current;
- current = rb_thread_current();
+ VALUE current;
+ current = rb_thread_current();
- rb_thread_critical = 1;
+ rb_thread_critical = 1;
- while (RTEST(mutex->owner)) {
- push_list(&mutex->waiting, current);
- rb_thread_stop();
+ while (RTEST(mutex->owner)) {
+ push_list(&mutex->waiting, current);
+ rb_thread_stop();
- rb_thread_critical = 1;
- }
- mutex->owner = current;
+ rb_thread_critical = 1;
+ }
+ mutex->owner = current;
- rb_thread_critical = 0;
+ rb_thread_critical = 0;
}
-static VALUE rb_mutex_lock _((VALUE));
-
static VALUE
-rb_mutex_lock(self)
- VALUE self;
+rb_mutex_lock(VALUE self)
{
- Mutex *mutex;
- Data_Get_Struct(self, Mutex, mutex);
- lock_mutex(mutex);
- return self;
+ Mutex *mutex;
+ Data_Get_Struct(self, Mutex, mutex);
+ lock_mutex(mutex);
+ return self;
}
/*
@@ -448,69 +371,57 @@ rb_mutex_lock(self)
*
*/
-static VALUE unlock_mutex_inner _((Mutex *));
-
static VALUE
-unlock_mutex_inner(mutex)
- Mutex *mutex;
+unlock_mutex_inner(Mutex *mutex)
{
- VALUE waking;
+ VALUE waking;
- if (!RTEST(mutex->owner)) {
- return Qundef;
- }
- mutex->owner = Qnil;
- waking = wake_one(&mutex->waiting);
+ if (!RTEST(mutex->owner)) {
+ return Qundef;
+ }
+ mutex->owner = Qnil;
+ waking = wake_one(&mutex->waiting);
- return waking;
+ return waking;
}
-static VALUE set_critical _((VALUE));
-
static VALUE
-set_critical(value)
- VALUE value;
+set_critical(VALUE value)
{
- rb_thread_critical = (int)value;
- return Qnil;
+ rb_thread_critical = (int)value;
+ return Qnil;
}
-static VALUE unlock_mutex _((Mutex *));
-
static VALUE
-unlock_mutex(mutex)
- Mutex *mutex;
+unlock_mutex(Mutex *mutex)
{
- VALUE waking;
+ VALUE waking;
- rb_thread_critical = 1;
- waking = rb_ensure(unlock_mutex_inner, (VALUE)mutex, set_critical, 0);
+ rb_thread_critical = 1;
+ waking = rb_ensure(unlock_mutex_inner, (VALUE)mutex, set_critical, 0);
- if ( waking == Qundef ) {
- return Qfalse;
- }
+ if (waking == Qundef) {
+ return Qfalse;
+ }
- if (RTEST(waking)) {
- run_thread(waking);
- }
+ if (RTEST(waking)) {
+ run_thread(waking);
+ }
- return Qtrue;
+ return Qtrue;
}
-static VALUE rb_mutex_unlock _((VALUE));
-
static VALUE
-rb_mutex_unlock(self)
- VALUE self;
+rb_mutex_unlock(VALUE self)
{
- Mutex *mutex;
- Data_Get_Struct(self, Mutex, mutex);
+ Mutex *mutex;
+ Data_Get_Struct(self, Mutex, mutex);
- if (RTEST(unlock_mutex(mutex))) {
- return self;
- } else {
- return Qnil;
- }
+ if (RTEST(unlock_mutex(mutex))) {
+ return self;
+ } else {
+ return Qnil;
+ }
}
/*
@@ -522,40 +433,34 @@ rb_mutex_unlock(self)
*
*/
-static VALUE rb_mutex_exclusive_unlock_inner _((Mutex *));
-
static VALUE
-rb_mutex_exclusive_unlock_inner(mutex)
- Mutex *mutex;
+rb_mutex_exclusive_unlock_inner(Mutex *mutex)
{
- VALUE waking;
- waking = unlock_mutex_inner(mutex);
- rb_yield(Qundef);
- return waking;
+ VALUE waking;
+ waking = unlock_mutex_inner(mutex);
+ rb_yield(Qundef);
+ return waking;
}
-static VALUE rb_mutex_exclusive_unlock _((VALUE));
-
static VALUE
-rb_mutex_exclusive_unlock(self)
- VALUE self;
+rb_mutex_exclusive_unlock(VALUE self)
{
- Mutex *mutex;
- VALUE waking;
- Data_Get_Struct(self, Mutex, mutex);
+ Mutex *mutex;
+ VALUE waking;
+ Data_Get_Struct(self, Mutex, mutex);
- rb_thread_critical = 1;
- waking = rb_ensure(rb_mutex_exclusive_unlock_inner, (VALUE)mutex, set_critical, 0);
+ rb_thread_critical = 1;
+ waking = rb_ensure(rb_mutex_exclusive_unlock_inner, (VALUE)mutex, set_critical, 0);
- if ( waking == Qundef ) {
- return Qnil;
- }
+ if (waking == Qundef) {
+ return Qnil;
+ }
- if (RTEST(waking)) {
- run_thread(waking);
- }
+ if (RTEST(waking)) {
+ run_thread(waking);
+ }
- return self;
+ return self;
}
/*
@@ -567,14 +472,11 @@ rb_mutex_exclusive_unlock(self)
*
*/
-static VALUE rb_mutex_synchronize _((VALUE));
-
static VALUE
-rb_mutex_synchronize(self)
- VALUE self;
+rb_mutex_synchronize(VALUE self)
{
- rb_mutex_lock(self);
- return rb_ensure(rb_yield, Qundef, rb_mutex_unlock, self);
+ rb_mutex_lock(self);
+ return rb_ensure(rb_yield, Qundef, rb_mutex_unlock, self);
}
/*
@@ -609,45 +511,33 @@ rb_mutex_synchronize(self)
*/
typedef struct _ConditionVariable {
- List waiting;
+ List waiting;
} ConditionVariable;
-static void mark_condvar _((ConditionVariable *));
-
static void
-mark_condvar(condvar)
- ConditionVariable *condvar;
+mark_condvar(ConditionVariable *condvar)
{
- mark_list(&condvar->waiting);
+ mark_list(&condvar->waiting);
}
-static void finalize_condvar _((ConditionVariable *));
-
static void
-finalize_condvar(condvar)
- ConditionVariable *condvar;
+finalize_condvar(ConditionVariable *condvar)
{
- finalize_list(&condvar->waiting);
+ finalize_list(&condvar->waiting);
}
-static void free_condvar _((ConditionVariable *));
-
static void
-free_condvar(condvar)
- ConditionVariable *condvar;
+free_condvar(ConditionVariable *condvar)
{
- assert_no_survivors(&condvar->waiting, "condition variable", condvar);
- finalize_condvar(condvar);
- free(condvar);
+ assert_no_survivors(&condvar->waiting, "condition variable", condvar);
+ finalize_condvar(condvar);
+ free(condvar);
}
-static void init_condvar _((ConditionVariable *));
-
static void
-init_condvar(condvar)
- ConditionVariable *condvar;
+init_condvar(ConditionVariable *condvar)
{
- init_list(&condvar->waiting);
+ init_list(&condvar->waiting);
}
/*
@@ -658,18 +548,15 @@ init_condvar(condvar)
*
*/
-static VALUE rb_condvar_alloc _((VALUE));
-
static VALUE
-rb_condvar_alloc(klass)
- VALUE klass;
+rb_condvar_alloc(VALUE klass)
{
- ConditionVariable *condvar;
+ ConditionVariable *condvar;
- condvar = (ConditionVariable *)malloc(sizeof(ConditionVariable));
- init_condvar(condvar);
+ condvar = (ConditionVariable *)malloc(sizeof(ConditionVariable));
+ init_condvar(condvar);
- return Data_Wrap_Struct(klass, mark_condvar, free_condvar, condvar);
+ return Data_Wrap_Struct(klass, mark_condvar, free_condvar, condvar);
}
/*
@@ -680,79 +567,64 @@ rb_condvar_alloc(klass)
*
*/
-static void wait_condvar _((ConditionVariable *, Mutex *));
-
static void
-wait_condvar(condvar, mutex)
- ConditionVariable *condvar;
- Mutex *mutex;
+wait_condvar(ConditionVariable *condvar, Mutex *mutex)
{
- rb_thread_critical = 1;
- if (!RTEST(mutex->owner)) {
- rb_thread_critical = Qfalse;
- return;
- }
- if ( mutex->owner != rb_thread_current() ) {
- rb_thread_critical = Qfalse;
- rb_raise(rb_eThreadError, "Not owner");
- }
- mutex->owner = Qnil;
- push_list(&condvar->waiting, rb_thread_current());
- rb_thread_stop();
-
- lock_mutex(mutex);
-}
+ rb_thread_critical = 1;
+ if (!RTEST(mutex->owner)) {
+ rb_thread_critical = Qfalse;
+ return;
+ }
+ if (mutex->owner != rb_thread_current()) {
+ rb_thread_critical = Qfalse;
+ rb_raise(rb_eThreadError, "Not owner");
+ }
+ mutex->owner = Qnil;
+ push_list(&condvar->waiting, rb_thread_current());
+ rb_thread_stop();
-static VALUE legacy_exclusive_unlock _((VALUE));
+ lock_mutex(mutex);
+}
static VALUE
-legacy_exclusive_unlock(mutex)
- VALUE mutex;
+legacy_exclusive_unlock(VALUE mutex)
{
- return rb_funcall(mutex, rb_intern("exclusive_unlock"), 0);
+ return rb_funcall(mutex, rb_intern("exclusive_unlock"), 0);
}
typedef struct {
- ConditionVariable *condvar;
- VALUE mutex;
+ ConditionVariable *condvar;
+ VALUE mutex;
} legacy_wait_args;
-static VALUE legacy_wait _((VALUE, legacy_wait_args *));
-
static VALUE
-legacy_wait(unused, args)
- VALUE unused;
- legacy_wait_args *args;
+legacy_wait(VALUE unused, legacy_wait_args *args)
{
- push_list(&args->condvar->waiting, rb_thread_current());
- rb_thread_stop();
- rb_funcall(args->mutex, rb_intern("lock"), 0);
- return Qnil;
+ push_list(&args->condvar->waiting, rb_thread_current());
+ rb_thread_stop();
+ rb_funcall(args->mutex, rb_intern("lock"), 0);
+ return Qnil;
}
-static VALUE rb_condvar_wait _((VALUE, VALUE));
-
static VALUE
-rb_condvar_wait(self, mutex_v)
- VALUE self;
- VALUE mutex_v;
+rb_condvar_wait(VALUE self, VALUE mutex_v)
{
- ConditionVariable *condvar;
- Data_Get_Struct(self, ConditionVariable, condvar);
-
- if ( CLASS_OF(mutex_v) != rb_cMutex ) {
- /* interoperate with legacy mutex */
- legacy_wait_args args;
- args.condvar = condvar;
- args.mutex = mutex_v;
- rb_iterate(legacy_exclusive_unlock, mutex_v, legacy_wait, (VALUE)&args);
- } else {
- Mutex *mutex;
- Data_Get_Struct(mutex_v, Mutex, mutex);
- wait_condvar(condvar, mutex);
- }
+ ConditionVariable *condvar;
+ Data_Get_Struct(self, ConditionVariable, condvar);
+
+ if (CLASS_OF(mutex_v) != rb_cMutex) {
+ /* interoperate with legacy mutex */
+ legacy_wait_args args;
+ args.condvar = condvar;
+ args.mutex = mutex_v;
+ rb_iterate(legacy_exclusive_unlock, mutex_v, legacy_wait, (VALUE)&args);
+ } else {
+ Mutex *mutex;
+ Data_Get_Struct(mutex_v, Mutex, mutex);
+ wait_condvar(condvar, mutex);
+ }
- return self;
+ return self;
}
/*
@@ -763,21 +635,18 @@ rb_condvar_wait(self, mutex_v)
*
*/
-static VALUE rb_condvar_broadcast _((VALUE));
-
static VALUE
-rb_condvar_broadcast(self)
- VALUE self;
+rb_condvar_broadcast(VALUE self)
{
- ConditionVariable *condvar;
+ ConditionVariable *condvar;
- Data_Get_Struct(self, ConditionVariable, condvar);
+ Data_Get_Struct(self, ConditionVariable, condvar);
- rb_thread_critical = 1;
- rb_ensure(wake_all, (VALUE)&condvar->waiting, set_critical, 0);
- rb_thread_schedule();
+ rb_thread_critical = 1;
+ rb_ensure(wake_all, (VALUE)&condvar->waiting, set_critical, 0);
+ rb_thread_schedule();
- return self;
+ return self;
}
/*
@@ -788,30 +657,24 @@ rb_condvar_broadcast(self)
*
*/
-static void signal_condvar _((ConditionVariable *condvar));
-
static void
-signal_condvar(condvar)
- ConditionVariable *condvar;
+signal_condvar(ConditionVariable *condvar)
{
- VALUE waking;
- rb_thread_critical = 1;
- waking = rb_ensure(wake_one, (VALUE)&condvar->waiting, set_critical, 0);
- if (RTEST(waking)) {
- run_thread(waking);
- }
+ VALUE waking;
+ rb_thread_critical = 1;
+ waking = rb_ensure(wake_one, (VALUE)&condvar->waiting, set_critical, 0);
+ if (RTEST(waking)) {
+ run_thread(waking);
+ }
}
-static VALUE rb_condvar_signal _((VALUE));
-
static VALUE
-rb_condvar_signal(self)
- VALUE self;
+rb_condvar_signal(VALUE self)
{
- ConditionVariable *condvar;
- Data_Get_Struct(self, ConditionVariable, condvar);
- signal_condvar(condvar);
- return self;
+ ConditionVariable *condvar;
+ Data_Get_Struct(self, ConditionVariable, condvar);
+ signal_condvar(condvar);
+ return self;
}
/*
@@ -846,61 +709,49 @@ rb_condvar_signal(self)
*/
typedef struct _Queue {
- Mutex mutex;
- ConditionVariable value_available;
- ConditionVariable space_available;
- List values;
- unsigned long capacity;
+ Mutex mutex;
+ ConditionVariable value_available;
+ ConditionVariable space_available;
+ List values;
+ unsigned long capacity;
} Queue;
-static void mark_queue _((Queue *));
-
static void
-mark_queue(queue)
- Queue *queue;
+mark_queue(Queue *queue)
{
- mark_mutex(&queue->mutex);
- mark_condvar(&queue->value_available);
- mark_condvar(&queue->space_available);
- mark_list(&queue->values);
+ mark_mutex(&queue->mutex);
+ mark_condvar(&queue->value_available);
+ mark_condvar(&queue->space_available);
+ mark_list(&queue->values);
}
-static void finalize_queue _((Queue *));
-
static void
-finalize_queue(queue)
- Queue *queue;
+finalize_queue(Queue *queue)
{
- finalize_mutex(&queue->mutex);
- finalize_condvar(&queue->value_available);
- finalize_condvar(&queue->space_available);
- finalize_list(&queue->values);
+ finalize_mutex(&queue->mutex);
+ finalize_condvar(&queue->value_available);
+ finalize_condvar(&queue->space_available);
+ finalize_list(&queue->values);
}
-static void free_queue _((Queue *));
-
static void
-free_queue(queue)
- Queue *queue;
+free_queue(Queue *queue)
{
- assert_no_survivors(&queue->mutex.waiting, "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);
+ assert_no_survivors(&queue->mutex.waiting, "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);
}
-static void init_queue _((Queue *));
-
static void
-init_queue(queue)
- Queue *queue;
+init_queue(Queue *queue)
{
- init_mutex(&queue->mutex);
- init_condvar(&queue->value_available);
- init_condvar(&queue->space_available);
- init_list(&queue->values);
- queue->capacity = 0;
+ init_mutex(&queue->mutex);
+ init_condvar(&queue->value_available);
+ init_condvar(&queue->space_available);
+ init_list(&queue->values);
+ queue->capacity = 0;
}
/*
@@ -911,55 +762,45 @@ init_queue(queue)
*
*/
-static VALUE rb_queue_alloc _((VALUE));
-
static VALUE
-rb_queue_alloc(klass)
- VALUE klass;
+rb_queue_alloc(VALUE klass)
{
- Queue *queue;
- queue = (Queue *)malloc(sizeof(Queue));
- init_queue(queue);
- return Data_Wrap_Struct(klass, mark_queue, free_queue, queue);
+ Queue *queue;
+ queue = (Queue *)malloc(sizeof(Queue));
+ init_queue(queue);
+ return Data_Wrap_Struct(klass, mark_queue, free_queue, queue);
}
-static VALUE rb_queue_marshal_load _((VALUE, VALUE));
-
static VALUE
-rb_queue_marshal_load(self, data)
- VALUE self;
- VALUE data;
+rb_queue_marshal_load(VALUE self, VALUE data)
{
- Queue *queue;
- VALUE array;
- Data_Get_Struct(self, Queue, queue);
-
- array = rb_marshal_load(data);
- if ( TYPE(array) != T_ARRAY ) {
- rb_raise(rb_eRuntimeError, "expected Array of queue data");
- }
- if ( RARRAY(array)->len < 1 ) {
- rb_raise(rb_eRuntimeError, "missing capacity value");
- }
- queue->capacity = NUM2ULONG(rb_ary_shift(array));
- push_multiple_list(&queue->values, RARRAY(array)->ptr, (unsigned)RARRAY(array)->len);
-
- return self;
-}
+ Queue *queue;
+ VALUE array;
+ Data_Get_Struct(self, Queue, queue);
+
+ array = rb_marshal_load(data);
+ if (TYPE(array) != T_ARRAY) {
+ rb_raise(rb_eRuntimeError, "expected Array of queue data");
+ }
+ if (RARRAY(array)->len < 1) {
+ rb_raise(rb_eRuntimeError, "missing capacity value");
+ }
+ queue->capacity = NUM2ULONG(rb_ary_shift(array));
+ push_multiple_list(&queue->values, RARRAY(array)->ptr, (unsigned)RARRAY(array)->len);
-static VALUE rb_queue_marshal_dump _((VALUE));
+ return self;
+}
static VALUE
-rb_queue_marshal_dump(self)
- VALUE self;
+rb_queue_marshal_dump(VALUE self)
{
- Queue *queue;
- VALUE array;
- Data_Get_Struct(self, Queue, queue);
+ Queue *queue;
+ VALUE array;
+ Data_Get_Struct(self, Queue, queue);
- array = array_from_list(&queue->values);
- rb_ary_unshift(array, ULONG2NUM(queue->capacity));
- return rb_marshal_dump(array, Qnil);
+ array = array_from_list(&queue->values);
+ rb_ary_unshift(array, ULONG2NUM(queue->capacity));
+ return rb_marshal_dump(array, Qnil);
}
/*
@@ -970,21 +811,18 @@ rb_queue_marshal_dump(self)
*
*/
-static VALUE rb_queue_clear _((VALUE));
-
static VALUE
-rb_queue_clear(self)
- VALUE self;
+rb_queue_clear(VALUE self)
{
- Queue *queue;
- Data_Get_Struct(self, Queue, queue);
+ Queue *queue;
+ Data_Get_Struct(self, Queue, queue);
- lock_mutex(&queue->mutex);
- clear_list(&queue->values);
- signal_condvar(&queue->space_available);
- unlock_mutex(&queue->mutex);
+ lock_mutex(&queue->mutex);
+ clear_list(&queue->values);
+ signal_condvar(&queue->space_available);
+ unlock_mutex(&queue->mutex);
- return self;
+ return self;
}
/*
@@ -995,21 +833,18 @@ rb_queue_clear(self)
*
*/
-static VALUE rb_queue_empty_p _((VALUE));
-
static VALUE
-rb_queue_empty_p(self)
- VALUE self;
+rb_queue_empty_p(VALUE self)
{
- Queue *queue;
- VALUE result;
- Data_Get_Struct(self, Queue, queue);
+ Queue *queue;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
- lock_mutex(&queue->mutex);
- result = ( ( queue->values.size == 0 ) ? Qtrue : Qfalse );
- unlock_mutex(&queue->mutex);
+ lock_mutex(&queue->mutex);
+ result = queue->values.size == 0 ? Qtrue : Qfalse;
+ unlock_mutex(&queue->mutex);
- return result;
+ return result;
}
/*
@@ -1020,21 +855,18 @@ rb_queue_empty_p(self)
*
*/
-static VALUE rb_queue_length _((VALUE));
-
static VALUE
-rb_queue_length(self)
- VALUE self;
+rb_queue_length(VALUE self)
{
- Queue *queue;
- VALUE result;
- Data_Get_Struct(self, Queue, queue);
+ Queue *queue;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
- lock_mutex(&queue->mutex);
- result = ULONG2NUM(queue->values.size);
- unlock_mutex(&queue->mutex);
+ lock_mutex(&queue->mutex);
+ result = ULONG2NUM(queue->values.size);
+ unlock_mutex(&queue->mutex);
- return result;
+ return result;
}
/*
@@ -1045,22 +877,19 @@ rb_queue_length(self)
*
*/
-static VALUE rb_queue_num_waiting _((VALUE));
-
static VALUE
-rb_queue_num_waiting(self)
- VALUE self;
+rb_queue_num_waiting(VALUE self)
{
- Queue *queue;
- VALUE result;
- Data_Get_Struct(self, Queue, queue);
+ Queue *queue;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
- lock_mutex(&queue->mutex);
- result = ULONG2NUM(queue->value_available.waiting.size +
- queue->space_available.waiting.size);
- unlock_mutex(&queue->mutex);
+ lock_mutex(&queue->mutex);
+ result = ULONG2NUM(queue->value_available.waiting.size +
+ queue->space_available.waiting.size);
+ unlock_mutex(&queue->mutex);
- return result;
+ return result;
}
/*
@@ -1073,44 +902,39 @@ rb_queue_num_waiting(self)
*
*/
-static VALUE rb_queue_pop _((int, VALUE *, VALUE));
-
static VALUE
-rb_queue_pop(argc, argv, self)
- int argc;
- VALUE *argv;
- VALUE self;
+rb_queue_pop(int argc, VALUE *argv, VALUE self)
{
- Queue *queue;
- int should_block;
- VALUE result;
- Data_Get_Struct(self, Queue, queue);
-
- if ( argc == 0 ) {
- should_block = 1;
- } else if ( argc == 1 ) {
- should_block = !RTEST(argv[0]);
- } else {
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
- }
-
- lock_mutex(&queue->mutex);
- if ( !queue->values.entries && !should_block ) {
- unlock_mutex(&queue->mutex);
- rb_raise(rb_eThreadError, "queue empty");
- }
+ Queue *queue;
+ int should_block;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
+
+ if (argc == 0) {
+ should_block = 1;
+ } else if (argc == 1) {
+ should_block = !RTEST(argv[0]);
+ } else {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
+ }
- while (!queue->values.entries) {
- wait_condvar(&queue->value_available, &queue->mutex);
- }
+ lock_mutex(&queue->mutex);
+ if (!queue->values.entries && !should_block) {
+ unlock_mutex(&queue->mutex);
+ rb_raise(rb_eThreadError, "queue empty");
+ }
- result = shift_list(&queue->values);
- if ( queue->capacity && queue->values.size < queue->capacity ) {
- signal_condvar(&queue->space_available);
- }
- unlock_mutex(&queue->mutex);
+ while (!queue->values.entries) {
+ wait_condvar(&queue->value_available, &queue->mutex);
+ }
- return result;
+ result = shift_list(&queue->values);
+ if (queue->capacity && queue->values.size < queue->capacity) {
+ signal_condvar(&queue->space_available);
+ }
+ unlock_mutex(&queue->mutex);
+
+ return result;
}
/*
@@ -1121,25 +945,21 @@ rb_queue_pop(argc, argv, self)
*
*/
-static VALUE rb_queue_push _((VALUE, VALUE));
-
static VALUE
-rb_queue_push(self, value)
- VALUE self;
- VALUE value;
+rb_queue_push(VALUE self, VALUE value)
{
- Queue *queue;
- Data_Get_Struct(self, Queue, queue);
-
- lock_mutex(&queue->mutex);
- while ( queue->capacity && queue->values.size >= queue->capacity ) {
- wait_condvar(&queue->space_available, &queue->mutex);
- }
- push_list(&queue->values, value);
- signal_condvar(&queue->value_available);
- unlock_mutex(&queue->mutex);
-
- return self;
+ Queue *queue;
+ Data_Get_Struct(self, Queue, queue);
+
+ lock_mutex(&queue->mutex);
+ while (queue->capacity && queue->values.size >= queue->capacity) {
+ wait_condvar(&queue->space_available, &queue->mutex);
+ }
+ push_list(&queue->values, value);
+ signal_condvar(&queue->value_available);
+ unlock_mutex(&queue->mutex);
+
+ return self;
}
/*
@@ -1168,21 +988,18 @@ rb_queue_push(self, value)
*
*/
-static VALUE rb_sized_queue_max _((VALUE));
-
static VALUE
-rb_sized_queue_max(self)
- VALUE self;
+rb_sized_queue_max(VALUE self)
{
- Queue *queue;
- VALUE result;
- Data_Get_Struct(self, Queue, queue);
+ Queue *queue;
+ VALUE result;
+ Data_Get_Struct(self, Queue, queue);
- lock_mutex(&queue->mutex);
- result = ULONG2NUM(queue->capacity);
- unlock_mutex(&queue->mutex);
+ lock_mutex(&queue->mutex);
+ result = ULONG2NUM(queue->capacity);
+ unlock_mutex(&queue->mutex);
- return result;
+ return result;
}
/*
@@ -1193,37 +1010,33 @@ rb_sized_queue_max(self)
*
*/
-static VALUE rb_sized_queue_max_set _((VALUE, VALUE));
-
static VALUE
-rb_sized_queue_max_set(self, value)
- VALUE self;
- VALUE value;
+rb_sized_queue_max_set(VALUE self, VALUE value)
{
- Queue *queue;
- unsigned long new_capacity;
- unsigned long difference;
- Data_Get_Struct(self, Queue, queue);
-
- new_capacity = NUM2ULONG(value);
-
- if ( new_capacity < 1 ) {
- rb_raise(rb_eArgError, "value must be positive");
- }
-
- lock_mutex(&queue->mutex);
- if ( queue->capacity && new_capacity > queue->capacity ) {
- difference = new_capacity - queue->capacity;
- } else {
- difference = 0;
- }
- queue->capacity = new_capacity;
- for ( ; difference > 0 ; --difference ) {
- signal_condvar(&queue->space_available);
- }
- unlock_mutex(&queue->mutex);
+ Queue *queue;
+ unsigned long new_capacity;
+ unsigned long difference;
+ Data_Get_Struct(self, Queue, queue);
+
+ new_capacity = NUM2ULONG(value);
+
+ if (new_capacity < 1) {
+ rb_raise(rb_eArgError, "value must be positive");
+ }
+
+ lock_mutex(&queue->mutex);
+ if (queue->capacity && new_capacity > queue->capacity) {
+ difference = new_capacity - queue->capacity;
+ } else {
+ difference = 0;
+ }
+ queue->capacity = new_capacity;
+ for (; difference > 0; --difference) {
+ signal_condvar(&queue->space_available);
+ }
+ unlock_mutex(&queue->mutex);
- return self;
+ return self;
}
/*
@@ -1245,74 +1058,67 @@ rb_sized_queue_max_set(self, value)
/* for marshalling mutexes and condvars */
-static VALUE dummy_load _((VALUE, VALUE));
-
static VALUE
-dummy_load(self, string)
- VALUE self;
- VALUE string;
+dummy_load(VALUE self, VALUE string)
{
- return Qnil;
+ return Qnil;
}
-static VALUE dummy_dump _((VALUE));
-
static VALUE
-dummy_dump(self)
- VALUE self;
+dummy_dump(VALUE self)
{
- return rb_str_new2("");
+ return rb_str_new2("");
}
void
-Init_thread()
+Init_thread(void)
{
- rb_cMutex = rb_define_class("Mutex", rb_cObject);
- rb_define_alloc_func(rb_cMutex, rb_mutex_alloc);
- rb_define_method(rb_cMutex, "marshal_load", dummy_load, 1);
- rb_define_method(rb_cMutex, "marshal_dump", dummy_dump, 0);
- rb_define_method(rb_cMutex, "initialize", return_value, 0);
- rb_define_method(rb_cMutex, "locked?", rb_mutex_locked_p, 0);
- rb_define_method(rb_cMutex, "try_lock", rb_mutex_try_lock, 0);
- rb_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
- rb_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0);
- rb_define_method(rb_cMutex, "exclusive_unlock", rb_mutex_exclusive_unlock, 0);
- rb_define_method(rb_cMutex, "synchronize", rb_mutex_synchronize, 0);
-
- rb_cConditionVariable = rb_define_class("ConditionVariable", rb_cObject);
- rb_define_alloc_func(rb_cConditionVariable, rb_condvar_alloc);
- rb_define_method(rb_cConditionVariable, "marshal_load", dummy_load, 1);
- rb_define_method(rb_cConditionVariable, "marshal_dump", dummy_dump, 0);
- rb_define_method(rb_cConditionVariable, "initialize", return_value, 0);
- rb_define_method(rb_cConditionVariable, "wait", rb_condvar_wait, 1);
- rb_define_method(rb_cConditionVariable, "broadcast", rb_condvar_broadcast, 0);
- rb_define_method(rb_cConditionVariable, "signal", rb_condvar_signal, 0);
-
- rb_cQueue = rb_define_class("Queue", rb_cObject);
- rb_define_alloc_func(rb_cQueue, rb_queue_alloc);
- rb_define_method(rb_cQueue, "marshal_load", rb_queue_marshal_load, 1);
- rb_define_method(rb_cQueue, "marshal_dump", rb_queue_marshal_dump, 0);
- rb_define_method(rb_cQueue, "initialize", return_value, 0);
- rb_define_method(rb_cQueue, "clear", rb_queue_clear, 0);
- rb_define_method(rb_cQueue, "empty?", rb_queue_empty_p, 0);
- rb_define_method(rb_cQueue, "length", rb_queue_length, 0);
- rb_define_method(rb_cQueue, "num_waiting", rb_queue_num_waiting, 0);
- rb_define_method(rb_cQueue, "pop", rb_queue_pop, -1);
- rb_define_method(rb_cQueue, "push", rb_queue_push, 1);
- rb_alias(rb_cQueue, rb_intern("<<"), rb_intern("push"));
- rb_alias(rb_cQueue, rb_intern("deq"), rb_intern("pop"));
- rb_alias(rb_cQueue, rb_intern("shift"), rb_intern("pop"));
- rb_alias(rb_cQueue, rb_intern("size"), rb_intern("length"));
-
- rb_cSizedQueue = rb_define_class("SizedQueue", rb_cQueue);
- rb_define_method(rb_cSizedQueue, "initialize", rb_sized_queue_max_set, 1);
- rb_define_method(rb_cSizedQueue, "num_waiting", rb_queue_num_waiting, 0);
- rb_define_method(rb_cSizedQueue, "pop", rb_queue_pop, -1);
- rb_define_method(rb_cSizedQueue, "push", rb_queue_push, 1);
- rb_define_method(rb_cSizedQueue, "max", rb_sized_queue_max, 0);
- rb_define_method(rb_cSizedQueue, "max=", rb_sized_queue_max_set, 1);
- rb_alias(rb_cSizedQueue, rb_intern("<<"), rb_intern("push"));
- rb_alias(rb_cSizedQueue, rb_intern("deq"), rb_intern("pop"));
- rb_alias(rb_cSizedQueue, rb_intern("shift"), rb_intern("pop"));
+ rb_cMutex = rb_define_class("Mutex", rb_cObject);
+ rb_define_alloc_func(rb_cMutex, rb_mutex_alloc);
+ rb_define_method(rb_cMutex, "marshal_load", dummy_load, 1);
+ rb_define_method(rb_cMutex, "marshal_dump", dummy_dump, 0);
+ rb_define_method(rb_cMutex, "initialize", return_value, 0);
+ rb_define_method(rb_cMutex, "locked?", rb_mutex_locked_p, 0);
+ rb_define_method(rb_cMutex, "try_lock", rb_mutex_try_lock, 0);
+ rb_define_method(rb_cMutex, "lock", rb_mutex_lock, 0);
+ rb_define_method(rb_cMutex, "unlock", rb_mutex_unlock, 0);
+ rb_define_method(rb_cMutex, "exclusive_unlock", rb_mutex_exclusive_unlock, 0);
+ rb_define_method(rb_cMutex, "synchronize", rb_mutex_synchronize, 0);
+
+ rb_cConditionVariable = rb_define_class("ConditionVariable", rb_cObject);
+ rb_define_alloc_func(rb_cConditionVariable, rb_condvar_alloc);
+ rb_define_method(rb_cConditionVariable, "marshal_load", dummy_load, 1);
+ rb_define_method(rb_cConditionVariable, "marshal_dump", dummy_dump, 0);
+ rb_define_method(rb_cConditionVariable, "initialize", return_value, 0);
+ rb_define_method(rb_cConditionVariable, "wait", rb_condvar_wait, 1);
+ rb_define_method(rb_cConditionVariable, "broadcast", rb_condvar_broadcast, 0);
+ rb_define_method(rb_cConditionVariable, "signal", rb_condvar_signal, 0);
+
+ rb_cQueue = rb_define_class("Queue", rb_cObject);
+ rb_define_alloc_func(rb_cQueue, rb_queue_alloc);
+ rb_define_method(rb_cQueue, "marshal_load", rb_queue_marshal_load, 1);
+ rb_define_method(rb_cQueue, "marshal_dump", rb_queue_marshal_dump, 0);
+ rb_define_method(rb_cQueue, "initialize", return_value, 0);
+ rb_define_method(rb_cQueue, "clear", rb_queue_clear, 0);
+ rb_define_method(rb_cQueue, "empty?", rb_queue_empty_p, 0);
+ rb_define_method(rb_cQueue, "length", rb_queue_length, 0);
+ rb_define_method(rb_cQueue, "num_waiting", rb_queue_num_waiting, 0);
+ rb_define_method(rb_cQueue, "pop", rb_queue_pop, -1);
+ rb_define_method(rb_cQueue, "push", rb_queue_push, 1);
+ rb_alias(rb_cQueue, rb_intern("<<"), rb_intern("push"));
+ rb_alias(rb_cQueue, rb_intern("deq"), rb_intern("pop"));
+ rb_alias(rb_cQueue, rb_intern("shift"), rb_intern("pop"));
+ rb_alias(rb_cQueue, rb_intern("size"), rb_intern("length"));
+
+ rb_cSizedQueue = rb_define_class("SizedQueue", rb_cQueue);
+ rb_define_method(rb_cSizedQueue, "initialize", rb_sized_queue_max_set, 1);
+ rb_define_method(rb_cSizedQueue, "num_waiting", rb_queue_num_waiting, 0);
+ rb_define_method(rb_cSizedQueue, "pop", rb_queue_pop, -1);
+ rb_define_method(rb_cSizedQueue, "push", rb_queue_push, 1);
+ rb_define_method(rb_cSizedQueue, "max", rb_sized_queue_max, 0);
+ rb_define_method(rb_cSizedQueue, "max=", rb_sized_queue_max_set, 1);
+ rb_alias(rb_cSizedQueue, rb_intern("<<"), rb_intern("push"));
+ rb_alias(rb_cSizedQueue, rb_intern("deq"), rb_intern("pop"));
+ rb_alias(rb_cSizedQueue, rb_intern("shift"), rb_intern("pop"));
}