Ticket #21 (new enhancement)

Opened 1 year ago

Last modified 3 months ago

Add EM.get_quantum to get the current timer granularity

Reported by: tmm1 Assigned to:
Priority: minor Milestone: EventMachine "Framework"
Keywords: Cc: raggi

Attachments

textmate stdin NVV2l9.txt (3.8 kB) - added by tmm1 on 06/17/08 14:19:05.

Change History

06/17/08 14:19:05 changed by tmm1

  • attachment textmate stdin NVV2l9.txt added.

06/17/08 14:36:00 changed by tmm1

  • cc set to raggi.
  • priority changed from major to minor.
  • type changed from defect to enhancement.
  • milestone set to EventMachine "Framework".

02/11/09 01:04:32 changed by tmm1

updated patch against latest git master, although I have no idea why this function would be useful.. Quantum looks like its only used in the select reactor as the timeout value for the select() call.

diff --git a/ext/cmain.cpp b/ext/cmain.cpp
index e69ba39..0365c28 100644
--- a/ext/cmain.cpp
+++ b/ext/cmain.cpp
@@ -403,6 +403,16 @@ extern "C" int evma_set_comm_inactivity_timeout (const char *binding, int *value
 
 
 /**********************
+evma_get_timer_quantum
+**********************/
+
+extern "C" int evma_get_timer_quantum ()
+{
+	ensure_eventmachine("evma_get_timer_quantum");
+	return EventMachine->GetTimerQuantum ();
+}
+
+/**********************
 evma_set_timer_quantum
 **********************/
 
diff --git a/ext/em.cpp b/ext/em.cpp
index 6af0a8d..9a1c92c 100644
--- a/ext/em.cpp
+++ b/ext/em.cpp
@@ -182,6 +182,14 @@ void EventMachine_t::ScheduleHalt()
 	gTerminateSignalReceived = true;
 }
 
+/*******************************
+EventMachine_t::GetTimerQuantum
+*******************************/
+
+int EventMachine_t::GetTimerQuantum()
+{
+	return Quantum.tv_sec * 1000 + Quantum.tv_usec / 1000;
+}
 
 
 /*******************************
diff --git a/ext/em.h b/ext/em.h
index a586786..a06546c 100644
--- a/ext/em.h
+++ b/ext/em.h
@@ -97,6 +97,7 @@ class EventMachine_t
 		void ArmKqueueWriter (EventableDescriptor*);
 		void ArmKqueueReader (EventableDescriptor*);
 
+		int GetTimerQuantum();
 		void SetTimerQuantum (int);
 		static void SetuidString (const char*);
 		static int SetRlimitNofile (int);
diff --git a/ext/eventmachine.h b/ext/eventmachine.h
index 6d17c70..fef4136 100644
--- a/ext/eventmachine.h
+++ b/ext/eventmachine.h
@@ -74,6 +74,7 @@ extern "C" {
 	int evma_report_connection_error_status (const char *binding);
 	void evma_signal_loopbreak();
 	void evma_set_timer_quantum (int);
+	int evma_get_timer_quantum();
 	void evma_set_max_timer_count (int);
 	void evma_setuid_string (const char *username);
 	void evma_stop_machine();
diff --git a/ext/rubymain.cpp b/ext/rubymain.cpp
index f7b9415..8e1b5f4 100644
--- a/ext/rubymain.cpp
+++ b/ext/rubymain.cpp
@@ -447,6 +447,14 @@ static VALUE t_library_type (VALUE self)
 }
 
 
+/*******************
+t_get_timer_quantum
+*******************/
+static VALUE t_get_timer_quantum (VALUE self)
+{
+	return INT2NUM (evma_get_timer_quantum());
+}
+
 
 /*******************
 t_set_timer_quantum
@@ -728,6 +736,7 @@ extern "C" void Init_rubyeventmachine()
 	rb_define_module_function (EmModule, "stop", (VALUE(*)(...))t_stop, 0);
 	rb_define_module_function (EmModule, "signal_loopbreak", (VALUE(*)(...))t_signal_loopbreak, 0);
 	rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0);
+	rb_define_module_function (EmModule, "get_timer_quantum", (VALUE(*)(...))t_get_timer_quantum, 0);
 	rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1);
 	rb_define_module_function (EmModule, "set_max_timer_count", (VALUE(*)(...))t_set_max_timer_count, 1);
 	rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1);
diff --git a/lib/eventmachine.rb b/lib/eventmachine.rb
index 56d4f43..b80ae21 100644
--- a/lib/eventmachine.rb
+++ b/lib/eventmachine.rb
@@ -915,6 +915,12 @@ module EventMachine
 		set_timer_quantum mills.to_i
 	end
 
+	# Get the current timer granularity.
+	#
+	def self::get_quantum
+		get_timer_quantum
+	end
+
 	# Sets the maximum number of timers and periodic timers that may be outstanding at any
 	# given time. You only need to call #set_max_timers if you need more than the default
 	# number of timers, which on most platforms is 1000.