Class: POSIX::Semaphore
- Inherits:
-
Object
- Object
- POSIX::Semaphore
- Defined in:
- lib/posix/semaphore.rb,
lib/posix/semaphore/mutex.rb
Defined Under Namespace
Classes: Mutex
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(name, mode = File::CREAT, perms = 0611, value = 1) ⇒ Semaphore
constructor
A new instance of Semaphore.
- #inspect ⇒ Object
- #post ⇒ Object
- #unlink ⇒ Object
- #wait(timeout = nil) ⇒ Object
- #wait_nonblock ⇒ Object
- #zero? ⇒ Boolean (also: #locked?)
Constructor Details
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/posix/semaphore.rb', line 7 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/posix/semaphore.rb', line 7 def name @name end |
Class Method Details
.unlink(name) ⇒ Object
47 48 49 |
# File 'lib/posix/semaphore.rb', line 47 def self.unlink name POSIX.sem_unlink name end |
Instance Method Details
#inspect ⇒ Object
62 63 64 |
# File 'lib/posix/semaphore.rb', line 62 def inspect "#<#{self.class.name}:#@id name:#{@name.inspect}>" end |
#unlink ⇒ Object
43 44 45 |
# File 'lib/posix/semaphore.rb', line 43 def unlink self.class.unlink @name end |
#wait(timeout = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/posix/semaphore.rb', line 14 def wait timeout=nil if timeout.nil? POSIX.sem_wait @id true else begin if timeout.is_a? Numeric timeout = Time.now + timeout elsif defined? DateTime and timeout.is_a? DateTime timeout = timeout.to_time end POSIX.sem_timedwait @id, timeout rescue Errno::ETIMEDOUT return false rescue end end end |
#wait_nonblock ⇒ Object
32 33 34 |
# File 'lib/posix/semaphore.rb', line 32 def wait_nonblock POSIX.sem_trywait @id end |
#zero? ⇒ Boolean Also known as: locked?
51 52 53 54 55 56 57 58 59 |
# File 'lib/posix/semaphore.rb', line 51 def zero? begin wait_nonblock rescue Errno::EAGAIN return true end post return false end |