Class: Mach::Semaphore
- Includes:
- Functions
- Defined in:
- lib/mach/semaphore.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Port
Instance Method Summary collapse
-
#destroy(opts = {}) ⇒ Object
Destroy a Semaphore.
-
#initialize(opts = {}) ⇒ Integer
constructor
Create a new Semaphore.
- #signal ⇒ Object
- #signal_all ⇒ Object
- #timedwait(secs) ⇒ Object
- #wait ⇒ Object
Methods included from Functions
attach_mach_function, error_check, error_check_bootstrap, new_memory_pointer, #new_memory_pointer
Methods included from Types
Methods inherited from Port
#==, #copy_send, #deallocate, #insert_right, #receive_right, #send_right, #to_s
Constructor Details
#initialize(opts = {}) ⇒ Integer
Create a new Semaphore.
semaphore; defaults to 1
semaphore (defaults to Mach.task_self)
semaphore (defaults to SyncPolicy::FIFO)
Semaphore object; otherwise a new semaphore is created
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mach/semaphore.rb', line 27 def initialize(opts = {}) value = opts[:value] || 1 task = (opts[:task] && opts[:task].to_i) || ipc_space || mach_task_self sync_policy = opts[:sync_policy] || :fifo port = if opts[:port] opts[:port].to_i else mem = new_memory_pointer(:semaphore_t) semaphore_create(task, mem, sync_policy, value) mem.get_uint(0) end super(:port => port, :ipc_space => task) end |
Instance Method Details
#destroy(opts = {}) ⇒ Object
Destroy a Semaphore.
semaphore (defaults to the owning task)
49 50 51 52 |
# File 'lib/mach/semaphore.rb', line 49 def destroy(opts = {}) task = opts[:task] || ipc_space || mach_task_self semaphore_destroy(task.to_i, port) end |
#signal ⇒ Object
54 55 56 |
# File 'lib/mach/semaphore.rb', line 54 def signal semaphore_signal(port) end |
#signal_all ⇒ Object
58 59 60 |
# File 'lib/mach/semaphore.rb', line 58 def signal_all semaphore_signal_all(port) end |
#timedwait(secs) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/mach/semaphore.rb', line 67 def timedwait(secs) timespec = TimeSpec.new timespec.add_seconds!(secs) semaphore_timedwait(port, timespec) end |
#wait ⇒ Object
62 63 64 |
# File 'lib/mach/semaphore.rb', line 62 def wait semaphore_wait(port) end |