Class: AtomicRuby::ThreadPoolMonitor

Inherits:
Object
  • Object
show all
Defined in:
ext/atomic_ruby/atomic_ruby.c

Instance Method Summary collapse

Instance Method Details

#register_workerObject



661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'ext/atomic_ruby/atomic_ruby.c', line 661

static VALUE rb_cThreadPoolMonitor_register_worker(VALUE self) {
  atomic_ruby_thread_pool_monitor_t *monitor;
  TypedData_Get_Struct(self, atomic_ruby_thread_pool_monitor_t, &atomic_ruby_thread_pool_monitor_type, monitor);

  VALUE thread = rb_thread_current();
  atomic_ruby_thread_pool_worker_state_t *state = ALLOC(atomic_ruby_thread_pool_worker_state_t);
  state->monitor = monitor;
  state->phase = ATOMIC_RUBY_THREAD_POOL_WORKER_INACTIVE;
  state->phase_started_at = 0;
  state->running_cpu_started_at = 0;
  rb_internal_thread_specific_set(thread, atomic_ruby_thread_pool_worker_key, state);
  return Qnil;
}

#snapshotObject



699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
# File 'ext/atomic_ruby/atomic_ruby.c', line 699

static VALUE rb_cThreadPoolMonitor_snapshot(VALUE self) {
  atomic_ruby_thread_pool_monitor_t *monitor;
  TypedData_Get_Struct(self, atomic_ruby_thread_pool_monitor_t, &atomic_ruby_thread_pool_monitor_type, monitor);

  return rb_ary_new_from_args(
    7,
    UINT2NUM(atomic_load_explicit(&monitor->running_count, memory_order_relaxed)),
    UINT2NUM(atomic_load_explicit(&monitor->waiting_count, memory_order_relaxed)),
    UINT2NUM(atomic_load_explicit(&monitor->blocked_count, memory_order_relaxed)),
    ULL2NUM(atomic_load_explicit(&monitor->running_time, memory_order_relaxed)),
    ULL2NUM(atomic_load_explicit(&monitor->waiting_time, memory_order_relaxed)),
    ULL2NUM(atomic_load_explicit(&monitor->blocked_time, memory_order_relaxed)),
    ULL2NUM(atomic_load_explicit(&monitor->running_cpu_time, memory_order_relaxed))
  );
}

#start_workObject



686
687
688
689
690
# File 'ext/atomic_ruby/atomic_ruby.c', line 686

static VALUE rb_cThreadPoolMonitor_start_work(VALUE self) {
  atomic_ruby_thread_pool_worker_state_t *state = rb_internal_thread_specific_get(rb_thread_current(), atomic_ruby_thread_pool_worker_key);
  atomic_ruby_thread_pool_worker_enter_phase(state, ATOMIC_RUBY_THREAD_POOL_WORKER_RUNNING, atomic_ruby_monotonic_time());
  return Qnil;
}

#stop_workObject



692
693
694
695
696
697
# File 'ext/atomic_ruby/atomic_ruby.c', line 692

static VALUE rb_cThreadPoolMonitor_stop_work(VALUE self) {
  atomic_ruby_thread_pool_worker_state_t *state = rb_internal_thread_specific_get(rb_thread_current(), atomic_ruby_thread_pool_worker_key);
  atomic_ruby_thread_pool_worker_leave_phase(state, atomic_ruby_monotonic_time());
  state->phase = ATOMIC_RUBY_THREAD_POOL_WORKER_INACTIVE;
  return Qnil;
}

#unregister_workerObject



675
676
677
678
679
680
681
682
683
684
# File 'ext/atomic_ruby/atomic_ruby.c', line 675

static VALUE rb_cThreadPoolMonitor_unregister_worker(VALUE self) {
  VALUE thread = rb_thread_current();
  atomic_ruby_thread_pool_worker_state_t *state = rb_internal_thread_specific_get(thread, atomic_ruby_thread_pool_worker_key);
  if (state == NULL) return Qnil;

  atomic_ruby_thread_pool_worker_leave_phase(state, atomic_ruby_monotonic_time());
  rb_internal_thread_specific_set(thread, atomic_ruby_thread_pool_worker_key, NULL);
  xfree(state);
  return Qnil;
}