[ekg2-commit] ekg2: ekg.c (HEAD) [darkjames]

CVS commit cvs w amba.bydg.pdi.net
Nie, 18 Lut 2007, 14:24:24 CET


Module name:	ekg2
Changes by:	darkjames	07/02/18 14:24:20

Modified files:
	ekg.c

Log message:
OPTIMIZE_EKG_LOOP stuff.
orginal code from: ekg2-newautoaway-part3+ekgloop-currtime.diff (c peres)
	(there was one call of time(NULL) + several gettimeofday(),
	here we call only once gettimeofday() and none time(NULL))
	if OPTIMIZE_EKG_LOOP is defined to 1.

Index: ekg.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/ekg.c,v
diff -d -u -r1.138 -r1.139
--- ekg.c	18 Feb 2007 13:06:35 -0000	1.138
+++ ekg.c	18 Feb 2007 13:24:19 -0000	1.139
@@ -135,6 +135,12 @@
  * główna pętla ekg. obsługuje przeglądanie deskryptorów, timery i wszystko,
  * co ma się dziać w tle.
  */
+
+#define OPTIMIZE_EKG_LOOP 0	/* define to 1, if you want to call gettimeofday() only once... disable also time(NULL) calls
+				 *	it's quite ok, although we're less accurate. But feel free to change it to 1.
+				 *	It'll be someday default value in ekg2-cvs too.. but not now.
+				 */
+
 void ekg_loop() {
 	struct timeval tv;
         struct timeval stv;
@@ -142,19 +148,27 @@
         fd_set rd, wd;
         int ret, maxfd, pid, status;
 
+#if OPTIMIZE_EKG_LOOP
+	gettimeofday(&tv, NULL);
+#define time(x) tv.tv_sec
+#endif
+
 	{
                 /* przejrzyj timery użytkownika, ui, skryptów */
                 for (l = timers; l; ) {
                         struct timer *t = l->data;
                         l = l->next;
-
+#if !OPTIMIZE_EKG_LOOP
                         gettimeofday(&tv, NULL);
+#endif
 
                         if (tv.tv_sec > t->ends.tv_sec || (tv.tv_sec == t->ends.tv_sec && tv.tv_usec >= t->ends.tv_usec)) {
 				int ispersist = t->persist;
 				
                                 if (ispersist) {
+#if !OPTIMIZE_EKG_LOOP
                                         gettimeofday(&tv, NULL);
+#endif
                                         tv.tv_sec += t->period;
                                         memcpy(&t->ends, &tv, sizeof(tv));
                                 }
@@ -297,8 +311,9 @@
 		for (l = timers; l; l = l->next) {
 			struct timer *t = l->data;
 			int usec = 0;
-
+#if !OPTIMIZE_EKG_LOOP
 			gettimeofday(&tv, NULL);
+#endif
 
 			/* zeby uniknac przekrecenia licznika mikrosekund przy
 			 * wiekszych czasach, pomijamy dlugie timery */
@@ -325,7 +340,9 @@
 			stv.tv_sec = 0;
 		if (stv.tv_usec < 0)
 			stv.tv_usec = 1;
-
+#if OPTIMIZE_EKG_LOOP
+#undef time
+#endif
                 /* sprawdź, co się dzieje */
 /* XXX, on win32 we must do select() on only SOCKETS.
  *    , on files we must do "WaitForSingleObjectEx() 


Więcej informacji o liście dyskusyjnej ekg2-commit