Class: ProcessShared::AbstractSemaphore
- Inherits:
-
Object
- Object
- ProcessShared::AbstractSemaphore
- Includes:
- PSem, WithSelf
- Defined in:
- lib/process_shared/abstract_semaphore.rb
Class Method Summary collapse
-
.gen_name(middle, name = nil) ⇒ String
Generate a name for a semaphore.
-
.make_finalizer(name) ⇒ Proc
Make a Proc suitable for use as a finalizer that will call
psem_unlink
onname
and ignore system errors.
Instance Method Summary collapse
-
#synchronize ⇒ Object
private_class_method :new.
Class Method Details
.gen_name(middle, name = nil) ⇒ String
Generate a name for a semaphore. If name
is given, it is used as the name (and so a semaphore could be shared by arbitrary processes not forked from one another). Otherwise, a name is generated containing middle
and the process id.
19 20 21 22 23 24 25 26 27 |
# File 'lib/process_shared/abstract_semaphore.rb', line 19 def self.gen_name(middle, name = nil) if name name else @count ||= 0 @count += 1 "ps-#{middle}-#{::Process.pid}-#{@count}" end end |
.make_finalizer(name) ⇒ Proc
Make a Proc suitable for use as a finalizer that will call psem_unlink
on name
and ignore system errors.
33 34 35 |
# File 'lib/process_shared/abstract_semaphore.rb', line 33 def self.make_finalizer(name) proc { ProcessShared::PSem.psem_unlink(name, nil) } end |
Instance Method Details
#synchronize ⇒ Object
private_class_method :new
39 40 41 42 43 44 45 46 |
# File 'lib/process_shared/abstract_semaphore.rb', line 39 def synchronize wait begin yield ensure post end end |