Class: Semian::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/semian/resource.rb,
ext/semian/semian.c

Overview

Resource is the fundamental class of Semian. It is essentially a wrapper around a

SystemV semaphore.

You should not create this class directly, it will be created indirectly via Semian.register.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, tickets: nil, quota: nil, permissions: 0660, timeout: 0) ⇒ Resource

Returns a new instance of Resource.



12
13
14
15
16
17
18
19
# File 'lib/semian/resource.rb', line 12

def initialize(name, tickets: nil, quota: nil, permissions: 0660, timeout: 0)
  if Semian.semaphores_enabled?
    initialize_semaphore(name, tickets, quota, permissions, timeout) if respond_to?(:initialize_semaphore)
  else
    Semian.issue_disabled_semaphores_warning
  end
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/semian/resource.rb', line 3

def name
  @name
end

#ticketsObject (readonly)

Returns the value of attribute tickets.



3
4
5
# File 'lib/semian/resource.rb', line 3

def tickets
  @tickets
end

Class Method Details

.instance(name, **kwargs) ⇒ Object

Ensure that there can only be one resource of a given type



7
8
9
# File 'lib/semian/resource.rb', line 7

def instance(name, **kwargs)
  Semian.resources[name] ||= ProtectedResource.new(name, new(name, **kwargs), nil)
end

Instance Method Details

#acquire {|wait_time| ... } ⇒ Object

Yields:

  • (wait_time)


30
31
32
33
# File 'lib/semian/resource.rb', line 30

def acquire(*)
  wait_time = 0
  yield wait_time
end

#countObject



35
36
37
# File 'lib/semian/resource.rb', line 35

def count
  0
end

#destroyObject



24
25
# File 'lib/semian/resource.rb', line 24

def destroy
end

#in_use?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/semian/resource.rb', line 55

def in_use?
  false
end

#keyObject



51
52
53
# File 'lib/semian/resource.rb', line 51

def key
  '0x00000000'
end

#registered_workersObject



43
44
45
# File 'lib/semian/resource.rb', line 43

def registered_workers
  0
end

#reset_registered_workers!Object



21
22
# File 'lib/semian/resource.rb', line 21

def reset_registered_workers!
end

#semidObject



47
48
49
# File 'lib/semian/resource.rb', line 47

def semid
  0
end

#unregister_workerObject



27
28
# File 'lib/semian/resource.rb', line 27

def unregister_worker
end