Class: AtomicRuby::ThreadPoolMonitor
- Inherits:
-
Object
- Object
- AtomicRuby::ThreadPoolMonitor
- Defined in:
- ext/atomic_ruby/atomic_ruby.c
Instance Method Summary collapse
- #register_worker ⇒ Object
- #snapshot ⇒ Object
- #start_work ⇒ Object
- #stop_work ⇒ Object
- #unregister_worker ⇒ Object
Instance Method Details
#register_worker ⇒ Object
644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 644
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;
rb_internal_thread_specific_set(thread, atomic_ruby_thread_pool_worker_key, state);
return Qnil;
}
|
#snapshot ⇒ Object
681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 681
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(
6,
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))
);
}
|
#start_work ⇒ Object
668 669 670 671 672 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 668 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_work ⇒ Object
674 675 676 677 678 679 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 674
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_worker ⇒ Object
657 658 659 660 661 662 663 664 665 666 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 657
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;
}
|