summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2016-05-08 09:35:29 +0200
committerPatrick Griffis <tingping@tingping.se>2016-06-29 15:24:03 -0400
commit7dca22048633479e28fec8e311ae80c9f55d46b6 (patch)
treef6f53c0b017683edb56af852acf46af2e3e38c2f /src
parent111ba3750fd16c81100de6b759103e527c2c22f7 (diff)
Refactor timer handling
This allows us to omit the lagometer timer in the event that it is not
enabled, bringing the baseline wake-up rate down to 1Hz from 2Hz, which
could bring considerable power savings on mobile devices.
Diffstat (limited to 'src')
-rw-r--r--src/common/dcc.c2
-rw-r--r--src/common/hexchat.c41
2 files changed, 24 insertions, 19 deletions
diff --git a/src/common/dcc.c b/src/common/dcc.c
index 6c5b117e..cf909a14 100644
--- a/src/common/dcc.c
+++ b/src/common/dcc.c
@@ -233,7 +233,7 @@ is_dcc_completed (struct DCC *dcc)
 	return FALSE;
 }
 
-/* this is called from hexchat.c:hexchat_misc_checks() every 1 second. */
+/* this is called from hexchat.c:hexchat_check_dcc() every 1 second. */
 
 void
 dcc_check_timeouts (void)
diff --git a/src/common/hexchat.c b/src/common/hexchat.c
index 499df8b0..8da63aef 100644
--- a/src/common/hexchat.c
+++ b/src/common/hexchat.c
@@ -355,24 +355,24 @@ doover:
 }
 
 static int
-hexchat_misc_checks (void)		/* this gets called every 1/2 second */
+hexchat_check_dcc (void)	/* this gets called every 1 second */
 {
-	static int count = 0;
-
-	count++;
-
-	lagcheck_update ();			/* every 500ms */
-
-	if (count % 2)
-		dcc_check_timeouts ();	/* every 1 second */
+	dcc_check_timeouts ();
+	return 1;
+}
 
-	if (count >= 60)				/* every 30 seconds */
-	{
-		if (prefs.hex_gui_lagometer)
-			lag_check ();
-		count = 0;
-	}
+/* these are only run if the lagometer is enabled */
+static int
+hexchat_lag_check (void)   /* this gets called every 30 seconds */
+{
+	lag_check ();
+	return 1;
+}
 
+static int
+hexchat_lag_check_update (void)   /* this gets called every 0.5 seconds */
+{
+	lagcheck_update ();
 	return 1;
 }
 
@@ -403,10 +403,15 @@ irc_init (session *sess)
 
 	if (prefs.hex_notify_timeout)
 		notify_tag = fe_timeout_add (prefs.hex_notify_timeout * 1000,
-											  notify_checklist, 0);
+					     notify_checklist, NULL);
 
-	fe_timeout_add (prefs.hex_away_timeout * 1000, away_check, 0);
-	fe_timeout_add (500, hexchat_misc_checks, 0);
+	fe_timeout_add (prefs.hex_away_timeout * 1000, away_check, NULL);
+	fe_timeout_add (1000, hexchat_check_dcc, NULL);
+	if (prefs.hex_gui_lagometer)
+	{
+		fe_timeout_add (500, hexchat_lag_check_update, NULL);
+		fe_timeout_add (30000, hexchat_lag_check, NULL);
+	}
 
 	if (arg_url != NULL)
 	{