Module: Pitchfork::SharedMemory
Defined Under Namespace
Classes: Field, WorkerState
Constant Summary collapse
- CURRENT_GENERATION_OFFSET =
0- SHUTDOWN_OFFSET =
1- MOLD_TICK_OFFSET =
2- MOLD_PROMOTION_TICK_OFFSET =
3- SERVICE_TICK_OFFSET =
4- WORKER_TICK_OFFSET =
5- PAGES =
[MemoryPage.new(MemoryPage::SLOTS)]
Instance Method Summary collapse
- #[](offset) ⇒ Object
- #current_generation ⇒ Object
- #current_generation=(value) ⇒ Object
- #mold_promotion_state ⇒ Object
- #mold_state ⇒ Object
-
#preallocate_pages(workers_count) ⇒ Object
Since workers are created from another process, we have to pre-allocate the drops so they are shared between everyone.
- #service_state ⇒ Object
- #shutting_down! ⇒ Object
- #shutting_down? ⇒ Boolean
- #worker_state(worker_nr) ⇒ Object
Instance Method Details
#[](offset) ⇒ Object
90 91 92 |
# File 'lib/pitchfork/shared_memory.rb', line 90 def [](offset) Field.new(offset) end |
#current_generation ⇒ Object
16 17 18 |
# File 'lib/pitchfork/shared_memory.rb', line 16 def current_generation PAGES[0][CURRENT_GENERATION_OFFSET] end |
#current_generation=(value) ⇒ Object
20 21 22 |
# File 'lib/pitchfork/shared_memory.rb', line 20 def current_generation=(value) PAGES[0][CURRENT_GENERATION_OFFSET] = value end |
#mold_promotion_state ⇒ Object
78 79 80 |
# File 'lib/pitchfork/shared_memory.rb', line 78 def mold_promotion_state WorkerState.new(self[MOLD_PROMOTION_TICK_OFFSET]) end |
#mold_state ⇒ Object
74 75 76 |
# File 'lib/pitchfork/shared_memory.rb', line 74 def mold_state WorkerState.new(self[MOLD_TICK_OFFSET]) end |
#preallocate_pages(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.
99 100 101 102 103 |
# File 'lib/pitchfork/shared_memory.rb', line 99 def preallocate_pages(workers_count) 0.upto(((WORKER_TICK_OFFSET + workers_count) / MemoryPage::SLOTS.to_f).ceil) do |i| PAGES[i] ||= MemoryPage.new(MemoryPage::SLOTS) end end |
#service_state ⇒ Object
82 83 84 |
# File 'lib/pitchfork/shared_memory.rb', line 82 def service_state WorkerState.new(self[SERVICE_TICK_OFFSET]) end |
#shutting_down! ⇒ Object
24 25 26 |
# File 'lib/pitchfork/shared_memory.rb', line 24 def shutting_down! PAGES[0][SHUTDOWN_OFFSET] = 1 end |
#shutting_down? ⇒ Boolean
28 29 30 |
# File 'lib/pitchfork/shared_memory.rb', line 28 def shutting_down? PAGES[0][SHUTDOWN_OFFSET] > 0 end |
#worker_state(worker_nr) ⇒ Object
86 87 88 |
# File 'lib/pitchfork/shared_memory.rb', line 86 def worker_state(worker_nr) WorkerState.new(self[WORKER_TICK_OFFSET + worker_nr]) end |