summaryrefslogtreecommitdiff
path: root/thread_sync.rb
diff options
context:
space:
mode:
Diffstat (limited to 'thread_sync.rb')
-rw-r--r--thread_sync.rb27
1 files changed, 25 insertions, 2 deletions
diff --git a/thread_sync.rb b/thread_sync.rb
index d567ca51af..f8fa69900b 100644
--- a/thread_sync.rb
+++ b/thread_sync.rb
@@ -10,7 +10,7 @@ class Thread
# +ThreadError+ is raised.
#
# If +timeout+ seconds have passed and no data is available +nil+ is
- # returned.
+ # returned. If +timeout+ is +0+ it returns immediately.
def pop(non_block = false, timeout: nil)
if non_block && timeout
raise ArgumentError, "can't set a timeout if non_block is enabled"
@@ -32,7 +32,7 @@ class Thread
# suspended, and +ThreadError+ is raised.
#
# If +timeout+ seconds have passed and no data is available +nil+ is
- # returned.
+ # returned. If +timeout+ is +0+ it returns immediately.
def pop(non_block = false, timeout: nil)
if non_block && timeout
raise ArgumentError, "can't set a timeout if non_block is enabled"
@@ -41,5 +41,28 @@ class Thread
end
alias_method :deq, :pop
alias_method :shift, :pop
+
+ # call-seq:
+ # push(object, non_block=false, timeout: nil)
+ # enq(object, non_block=false, timeout: nil)
+ # <<(object)
+ #
+ # 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 +ThreadError+ is raised.
+ #
+ # If +timeout+ seconds have passed and no space is available +nil+ is
+ # returned. If +timeout+ is +0+ it returns immediately.
+ # Otherwise it returns +self+.
+ def push(object, non_block = false, timeout: nil)
+ if non_block && timeout
+ raise ArgumentError, "can't set a timeout if non_block is enabled"
+ end
+ Primitive.rb_szqueue_push(object, non_block, timeout)
+ end
+ alias_method :enq, :push
+ alias_method :<<, :push
end
end