monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[monit-dev] [monit] r375 committed - Sleep less when waiting on process


From: monit
Subject: [monit-dev] [monit] r375 committed - Sleep less when waiting on process to start or stop. Thanks to Michael...
Date: Wed, 08 Jun 2011 13:22:43 +0000

Revision: 375
Author:   address@hidden
Date:     Wed Jun  8 06:21:51 2011
Log: Sleep less when waiting on process to start or stop. Thanks to Michael Renner for suggestion

http://code.google.com/p/monit/source/detail?r=375

Modified:
 /trunk/control.c
 /trunk/monitor.h
 /trunk/util.c
 /trunk/util.h

=======================================
--- /trunk/control.c    Mon Mar 21 08:32:15 2011
+++ /trunk/control.c    Wed Jun  8 06:21:51 2011
@@ -467,7 +467,7 @@
   while ((time(NULL) < timeout) && !Run.stopped) {
     if ((isrunning = Util_isProcessRunning(s, TRUE)))
       break;
-    sleep(1);
+      Util_usleep(5000);
   }

   if (! isrunning)
@@ -495,7 +495,7 @@
   while ((time(NULL) < timeout) && !Run.stopped) {
     if (! (isrunning = Util_isProcessRunning(s, TRUE)))
       break;
-    sleep(1);
+    Util_usleep(5000);
   }

   if (isrunning) {
=======================================
--- /trunk/monitor.h    Thu Mar 24 01:16:05 2011
+++ /trunk/monitor.h    Wed Jun  8 06:21:51 2011
@@ -91,6 +91,11 @@
 #define TIMEFORMAT         "%Z %b %e %T"
 #define STRERROR            strerror(errno)
 #define STRLEN             256
+#ifndef USEC_PER_SEC
+#define USEC_PER_SEC       1000000L
+#endif
+#define USEC_PER_MSEC      1000L
+
 #define ARGMAX             64
 #define HTTP_CONTENT_MAX   (1024*1000)
 /* Set event queue directory mode: "drwx------" */
=======================================
--- /trunk/util.c       Wed Mar 23 14:34:11 2011
+++ /trunk/util.c       Wed Jun  8 06:21:51 2011
@@ -2032,6 +2032,15 @@
     freeaddrinfo(info);
   return 0;
 }
+
+
+long Util_usleep(long u) {
+        struct timeval tv;
+        tv.tv_sec = u / USEC_PER_SEC;
+        tv.tv_usec = u % USEC_PER_SEC;
+        select(0, 0, 0, 0, &tv);
+        return u;
+}


/* ----------------------------------------------------------------- Private */
=======================================
--- /trunk/util.h       Wed Mar 23 03:15:53 2011
+++ /trunk/util.h       Wed Jun  8 06:21:51 2011
@@ -525,4 +525,13 @@
 int Util_getfqdnhostname(char *buf, unsigned len);


+/**
+ * This method suspend the calling process or Thread for
+ * <code>u</code> micro seconds.
+ * @param u Micro seconds to sleep
+ * @return The number of micro seconds slept
+ */
+long Util_usleep(long u);
+
+
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]