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: Semian.default_permissions, timeout: 0) ⇒ Resource

Returns a new instance of Resource.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/semian/resource.rb', line 12

def initialize(name, tickets: nil, quota: nil, permissions: Semian.default_permissions, timeout: 0)
  unless name.is_a?(String) || name.is_a?(Symbol)
    raise TypeError, "name must be a string or symbol, got: #{name.class}"
  end

  if Semian.semaphores_enabled?
    if respond_to?(:initialize_semaphore)
      initialize_semaphore("#{Semian.namespace}#{name}", tickets, quota, permissions, timeout)
    end
  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)


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

def acquire(*)
  wait_time = 0
  yield wait_time
end

#countObject



41
42
43
# File 'lib/semian/resource.rb', line 41

def count
  0
end

#destroyObject



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

def destroy
end

#in_use?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/semian/resource.rb', line 61

def in_use?
  false
end

#keyObject



57
58
59
# File 'lib/semian/resource.rb', line 57

def key
  '0x00000000'
end

#registered_workersObject



49
50
51
# File 'lib/semian/resource.rb', line 49

def registered_workers
  0
end

#reset_registered_workers!Object



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

def reset_registered_workers!
end

#semidObject



53
54
55
# File 'lib/semian/resource.rb', line 53

def semid
  0
end

#unregister_workerObject



33
34
# File 'lib/semian/resource.rb', line 33

def unregister_worker
end