Class: ProcessShared::Mach::Semaphore

Inherits:
Mach::Semaphore show all
Extended by:
OpenWithSelf
Includes:
SynchronizableSemaphore
Defined in:
lib/process_shared/mach/semaphore.rb

Overview

Extends ::Mach::Semaphore to be compatible with ProcessShared::Semaphore

Instance Attribute Summary

Attributes inherited from Mach::Port

#ipc_space, #port

Instance Method Summary collapse

Methods included from OpenWithSelf

open

Methods included from SynchronizableSemaphore

#synchronize, #to_mtx

Methods inherited from Mach::Semaphore

#destroy, #signal, #signal_all, #timedwait, #wait

Methods included from Mach::Functions

attach_mach_function, error_check, error_check_bootstrap, new_memory_pointer, #new_memory_pointer

Methods included from Mach::Types

#enum, #find_type, typedefs

Methods inherited from Mach::Port

#==, #copy_send, #deallocate, #destroy, #insert_right, #receive_right, #send_right, #to_s

Constructor Details

#initialize(value = 1) ⇒ Semaphore

Returns a new instance of Semaphore.


15
16
17
18
# File 'lib/process_shared/mach/semaphore.rb', line 15

def initialize(value = 1)
  super(:value => value)
  ProcessShared::Mach.shared_ports.add self
end

Instance Method Details

#closeObject


37
38
39
# File 'lib/process_shared/mach/semaphore.rb', line 37

def close
  # TODO
end

#try_wait(timeout = nil) ⇒ Object


20
21
22
23
24
25
26
27
28
29
# File 'lib/process_shared/mach/semaphore.rb', line 20

def try_wait(timeout = nil)
  secs = timeout ? timeout : 0
  begin
    # TODO catch and convert exceptions...
    timedwait(secs)
  rescue Mach::Error::OPERATION_TIMED_OUT => e
    klass = secs == 0 ? Errno::EAGAIN : Errno::ETIMEDOUT
    raise klass, e.message
  end
end

#valueObject

Raises:

  • (Errno::ENOTSUP)

33
34
35
# File 'lib/process_shared/mach/semaphore.rb', line 33

def value
  raise Errno::ENOTSUP
end