]> git.llucax.com Git - software/libev.git/commitdiff
better resize
authorroot <root>
Wed, 31 Oct 2007 20:10:17 +0000 (20:10 +0000)
committerroot <root>
Wed, 31 Oct 2007 20:10:17 +0000 (20:10 +0000)
ev.c
ev.h

diff --git a/ev.c b/ev.c
index b2e48f8228eb2972ea8693ba966eb62830679078..f48b007be08524888782737a2531bca41666ea95 100644 (file)
--- a/ev.c
+++ b/ev.c
@@ -115,7 +115,13 @@ get_clock (void)
 #define array_needsize(base,cur,cnt,init)              \
   if ((cnt) > cur)                                     \
     {                                                  \
-      int newcnt = cur ? cur << 1 : 16;                        \
+      int newcnt = cur;                                        \
+      do                                               \
+        {                                              \
+          newcnt = (newcnt << 1) | 4 & ~3;             \
+        }                                              \
+      while ((cnt) > newcnt);                          \
+                                                       \
       base = realloc (base, sizeof (*base) * (newcnt));        \
       init (base + cur, newcnt - cur);                 \
       cur = newcnt;                                    \
@@ -370,36 +376,39 @@ childcb (struct ev_signal *sw, int revents)
 
 int ev_init (int flags)
 {
+  if (!ev_method)
+    {
 #if HAVE_MONOTONIC
-  {
-    struct timespec ts;
-    if (!clock_gettime (CLOCK_MONOTONIC, &ts))
-      have_monotonic = 1;
-  }
+      {
+        struct timespec ts;
+        if (!clock_gettime (CLOCK_MONOTONIC, &ts))
+          have_monotonic = 1;
+      }
 #endif
 
-  ev_now = ev_time ();
-  now    = get_clock ();
-  diff   = ev_now - now;
+      ev_now = ev_time ();
+      now    = get_clock ();
+      diff   = ev_now - now;
 
-  if (pipe (sigpipe))
-    return 0;
+      if (pipe (sigpipe))
+        return 0;
 
-  ev_method = EVMETHOD_NONE;
+      ev_method = EVMETHOD_NONE;
 #if HAVE_EPOLL
-  if (ev_method == EVMETHOD_NONE) epoll_init (flags);
+      if (ev_method == EVMETHOD_NONE) epoll_init (flags);
 #endif
 #if HAVE_SELECT
-  if (ev_method == EVMETHOD_NONE) select_init (flags);
+      if (ev_method == EVMETHOD_NONE) select_init (flags);
 #endif
 
-  if (ev_method)
-    {
-      evw_init (&sigev, sigcb);
-      siginit ();
+      if (ev_method)
+        {
+          evw_init (&sigev, sigcb);
+          siginit ();
 
-      evsignal_init (&childev, childcb, SIGCHLD);
-      evsignal_start (&childev);
+          evsignal_init (&childev, childcb, SIGCHLD);
+          evsignal_start (&childev);
+        }
     }
 
   return ev_method;
diff --git a/ev.h b/ev.h
index ff7acaae40780116c833bfefc58bf7107c4a33ff..6a326066d0cf8c7ce68b37cb022451c8cc4f5472 100644 (file)
--- a/ev.h
+++ b/ev.h
@@ -148,7 +148,7 @@ struct ev_child
   EV_WATCHER_LIST (ev_child);
 
   int pid;    /* ro */
-  int status; /* holds the exit status, use the macros from sys/wait.h */
+  int status; /* rw, holds the exit status, use the macros from sys/wait.h */
 };
 
 #define EVMETHOD_NONE   0