Module: Pitchfork::SharedMemory

Extended by:
SharedMemory
Included in:
SharedMemory
Defined in:
lib/pitchfork/shared_memory.rb

Defined Under Namespace

Classes: Field

Constant Summary collapse

PER_DROP =
Raindrops::PAGE_SIZE / Raindrops::SIZE
CURRENT_GENERATION_OFFSET =
0
SHUTDOWN_OFFSET =
1
MOLD_TICK_OFFSET =
2
MOLD_PROMOTION_TICK_OFFSET =
3
WORKER_TICK_OFFSET =
4
DROPS =
[Raindrops.new(PER_DROP)]

Instance Method Summary collapse

Instance Method Details

#[](offset) ⇒ Object



61
62
63
# File 'lib/pitchfork/shared_memory.rb', line 61

def [](offset)
  Field.new(offset)
end

#current_generationObject



18
19
20
# File 'lib/pitchfork/shared_memory.rb', line 18

def current_generation
  DROPS[0][CURRENT_GENERATION_OFFSET]
end

#current_generation=(value) ⇒ Object



22
23
24
# File 'lib/pitchfork/shared_memory.rb', line 22

def current_generation=(value)
  DROPS[0][CURRENT_GENERATION_OFFSET] = value
end

#mold_deadlineObject



49
50
51
# File 'lib/pitchfork/shared_memory.rb', line 49

def mold_deadline
  self[MOLD_TICK_OFFSET]
end

#mold_promotion_deadlineObject



53
54
55
# File 'lib/pitchfork/shared_memory.rb', line 53

def mold_promotion_deadline
  self[MOLD_PROMOTION_TICK_OFFSET]
end

#preallocate_drops(workers_count) ⇒ Object

Since workers are created from another process, we have to pre-allocate the drops so they are shared between everyone.

However this doesn’t account for TTIN signals that increase the number of workers, but we should probably remove that feature too.



70
71
72
73
74
# File 'lib/pitchfork/shared_memory.rb', line 70

def preallocate_drops(workers_count)
  0.upto(((WORKER_TICK_OFFSET + workers_count) / PER_DROP.to_f).ceil) do |i|
    DROPS[i] ||= Raindrops.new(PER_DROP)
  end
end

#shutting_down!Object



26
27
28
# File 'lib/pitchfork/shared_memory.rb', line 26

def shutting_down!
  DROPS[0][SHUTDOWN_OFFSET] = 1
end

#shutting_down?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/pitchfork/shared_memory.rb', line 30

def shutting_down?
  DROPS[0][SHUTDOWN_OFFSET] > 0
end

#worker_deadline(worker_nr) ⇒ Object



57
58
59
# File 'lib/pitchfork/shared_memory.rb', line 57

def worker_deadline(worker_nr)
  self[WORKER_TICK_OFFSET + worker_nr]
end