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 ⇒ Object
- #start_work ⇒ Object
- #stop ⇒ Object
- #stop_work ⇒ Object
- #unregister_worker ⇒ Object
Instance Method Details
#register_worker ⇒ Object
719 720 721 722 723 724 725 726 727 728 729 730 731 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 719 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; } |
#snapshot ⇒ Object
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 757 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 ⇒ Object
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 692 static VALUE rb_cThreadPoolMonitor_start(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); rb_nativethread_lock_lock(&atomic_ruby_thread_pool_monitor_lock); if (!monitor->active) { monitor->active = true; if (atomic_ruby_thread_pool_monitor_count++ == 0) { atomic_ruby_thread_pool_event_hook = rb_internal_thread_add_event_hook( atomic_ruby_thread_pool_event_callback, RUBY_INTERNAL_THREAD_EVENT_READY | RUBY_INTERNAL_THREAD_EVENT_RESUMED | RUBY_INTERNAL_THREAD_EVENT_SUSPENDED, NULL ); } } rb_nativethread_lock_unlock(&atomic_ruby_thread_pool_monitor_lock); return Qnil; } |
#start_work ⇒ Object
744 745 746 747 748 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 744 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 ⇒ Object
712 713 714 715 716 717 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 712 static VALUE rb_cThreadPoolMonitor_stop(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); atomic_ruby_thread_pool_monitor_stop(monitor); return Qnil; } |
#stop_work ⇒ Object
750 751 752 753 754 755 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 750 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
733 734 735 736 737 738 739 740 741 742 |
# File 'ext/atomic_ruby/atomic_ruby.c', line 733 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; } |