In Files
- thread_sync.c
Files
- grammar.en.rdoc
- test.ja.rdoc
- contributing.rdoc
- contributors.rdoc
- dtrace_probes.rdoc
- extension.ja.rdoc
- extension.rdoc
- globals.rdoc
- keywords.rdoc
- maintainers.rdoc
- marshal.rdoc
- regexp.rdoc
- security.rdoc
- standard_library.rdoc
- syntax.rdoc
- assignment.rdoc
- calling_methods.rdoc
- control_expressions.rdoc
- exceptions.rdoc
- literals.rdoc
- methods.rdoc
- miscellaneous.rdoc
- modules_and_classes.rdoc
- precedence.rdoc
- refinements.rdoc
- README.ja.rdoc
- README.rdoc
Class/Module Index
![show/hide quicksearch [+]](./images/find.png)
- ArgumentError
- Array
- BasicObject
- Bignum
- Binding
- Class
- ClosedQueueError
- Comparable
- Complex
- Complex::compatible
- ConditionVariable
- Continuation
- Data
- Dir
- ENV
- EOFError
- Encoding
- Encoding::CompatibilityError
- Encoding::Converter
- Encoding::ConverterNotFoundError
- Encoding::InvalidByteSequenceError
- Encoding::UndefinedConversionError
- EncodingError
- Enumerable
- Enumerator
- Enumerator::Generator
- Enumerator::Lazy
- Enumerator::Yielder
- Errno
- Exception
- FalseClass
- Fiber
- FiberError
- File
- File::Constants
- File::Stat
- FileTest
- Fixnum
- Float
- FloatDomainError
- GC
- GC::Profiler
- Hash
- IO
- IO::EAGAINWaitReadable
- IO::EAGAINWaitWritable
- IO::EINPROGRESSWaitReadable
- IO::EINPROGRESSWaitWritable
- IO::EWOULDBLOCKWaitReadable
- IO::EWOULDBLOCKWaitWritable
- IO::WaitReadable
- IO::WaitWritable
- IOError
- IndexError
- Integer
- Interrupt
- Kernel
- KeyError
- LoadError
- LocalJumpError
- Marshal
- MatchData
- Math
- Math::DomainError
- Method
- Module
- NameError
- NilClass
- NoMemoryError
- NoMethodError
- NotImplementedError
- Numeric
- Object
- ObjectSpace
- ObjectSpace::WeakMap
- Proc
- Process
- Process::GID
- Process::Status
- Process::Sys
- Process::UID
- Process::Waiter
- Queue
- Random
- Random::Formatter
- Range
- RangeError
- Rational
- Rational::compatible
- Regexp
- RegexpError
- RubyVM
- RubyVM::Env
- RubyVM::InstructionSequence
- RuntimeError
- ScriptError
- SecurityError
- Signal
- SignalException
- SizedQueue
- StandardError
- StopIteration
- String
- Struct
- Symbol
- SyntaxError
- SystemCallError
- SystemExit
- SystemStackError
- Thread
- Thread::Backtrace::Location
- Thread::Mutex
- ThreadError
- ThreadGroup
- Time
- TracePoint
- TrueClass
- TypeError
- UnboundMethod
- UncaughtThrowError
- ZeroDivisionError
- fatal
- unknown
SizedQueue
This class represents queues of specified size capacity. The push operation may be blocked if the capacity is full.
See Queue for an example of how a SizedQueue works.
Public Class Methods
Creates a fixed-length queue with a maximum size of max.
static VALUE
rb_szqueue_initialize(VALUE self, VALUE vmax)
{
long max;
max = NUM2LONG(vmax);
if (max <= 0) {
rb_raise(rb_eArgError, "queue size must be positive");
}
RSTRUCT_SET(self, QUEUE_QUE, ary_buf_new());
RSTRUCT_SET(self, QUEUE_WAITERS, ary_buf_new());
RSTRUCT_SET(self, SZQUEUE_WAITERS, ary_buf_new());
RSTRUCT_SET(self, SZQUEUE_MAX, vmax);
return self;
}
Public Instance Methods
Removes all objects from the queue.
static VALUE
rb_szqueue_clear(VALUE self)
{
rb_ary_clear(GET_QUEUE_QUE(self));
wakeup_all_threads(GET_SZQUEUE_WAITERS(self));
return self;
}
Similar to Queue#close.
The difference is behavior with waiting enqueuing threads.
If there are waiting enqueuing threads, they are interrupted by raising ClosedQueueError('queue closed').
static VALUE
rb_szqueue_close(VALUE self)
{
return queue_do_close(self, TRUE);
}
Returns the maximum size of the queue.
static VALUE
rb_szqueue_max_get(VALUE self)
{
return GET_SZQUEUE_MAX(self);
}
Sets the maximum size of the queue to the given number.
static VALUE
rb_szqueue_max_set(VALUE self, VALUE vmax)
{
long max = NUM2LONG(vmax), diff = 0;
VALUE t;
if (max <= 0) {
rb_raise(rb_eArgError, "queue size must be positive");
}
if ((unsigned long)max > GET_SZQUEUE_ULONGMAX(self)) {
diff = max - GET_SZQUEUE_ULONGMAX(self);
}
RSTRUCT_SET(self, SZQUEUE_MAX, vmax);
while (diff-- > 0 && !NIL_P(t = rb_ary_shift(GET_SZQUEUE_WAITERS(self)))) {
rb_thread_wakeup_alive(t);
}
return vmax;
}
Returns the number of threads waiting on the queue.
static VALUE
rb_szqueue_num_waiting(VALUE self)
{
long len = queue_num_waiting(self) + szqueue_num_waiting_producer(self);
return ULONG2NUM(len);
}
Retrieves data from the queue.
If the queue is empty, the calling thread is suspended until data is pushed
onto the queue. If non_block is true, the thread isn't
suspended, and an exception is raised.
static VALUE
rb_szqueue_pop(int argc, VALUE *argv, VALUE self)
{
int should_block = queue_pop_should_block(argc, argv);
return szqueue_do_pop(self, should_block);
}
Pushes object to the queue.
If there is no space left in the queue, waits until space becomes
available, unless non_block is true. If
non_block is true, the thread isn't suspended, and an
exception is raised.
static VALUE
rb_szqueue_push(int argc, VALUE *argv, VALUE self)
{
struct waiting_delete args;
int should_block = szqueue_push_should_block(argc, argv);
args.waiting = GET_SZQUEUE_WAITERS(self);
args.th = rb_thread_current();
while (queue_length(self) >= GET_SZQUEUE_ULONGMAX(self)) {
if (!should_block) {
rb_raise(rb_eThreadError, "queue full");
}
else if (queue_closed_p(self)) {
goto closed;
}
else {
rb_ary_push(args.waiting, args.th);
rb_ensure((VALUE (*)())rb_thread_sleep_deadly, (VALUE)0, queue_delete_from_waiting, (VALUE)&args);
}
}
if (queue_closed_p(self)) {
closed:
raise_closed_queue_error(self);
}
return queue_do_push(self, argv[0]);
}