]> rtime.felk.cvut.cz Git - sojka/libev.git/commitdiff
*** empty log message ***
authorMarc Alexander Lehmann <libev@schmorp.de>
Fri, 10 Jul 2009 00:36:21 +0000 (00:36 +0000)
committerMarc Alexander Lehmann <libev@schmorp.de>
Fri, 10 Jul 2009 00:36:21 +0000 (00:36 +0000)
Changes
ev++.h
ev.c
ev.h
ev.pod
ev_epoll.c
ev_kqueue.c
ev_poll.c
ev_port.c
ev_select.c
ev_vars.h

diff --git a/Changes b/Changes
index 721c5a64c4511d3239d013f36258e7db68eaa1c3..354a2d4e21a0b43a4a6e13efea2c6090d9fb3b2b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -16,6 +16,7 @@ TODO: on_call_pending, on_suspend_resume ev_invoke_pending (EV_P)
           !EV_MULTIPLICITY.
         - implement ev_loop_depth.
         - do not compile in any priority code when EV_MAXPRI == EV_MINPRI.
+        - support EV_MINIMAL==2 for a reduced API.
 
 3.6  Tue Apr 28 02:49:30 CEST 2009
        - multiple timers becoming ready within an event loop iteration
diff --git a/ev++.h b/ev++.h
index f1b4c6ffd2923f592367a85ad5bfa57a92bcdbd4..4cec6993ecf34e7e421f8a115377635653f436e9 100644 (file)
--- a/ev++.h
+++ b/ev++.h
@@ -207,11 +207,6 @@ namespace ev {
 #endif
     }
 
-    unsigned int count () const throw ()
-    {
-      return ev_loop_count (EV_AX);
-    }
-
     unsigned int backend () const throw ()
     {
       return ev_backend (EV_AX);
@@ -232,6 +227,17 @@ namespace ev {
       ev_unref (EV_AX);
     }
 
+#if EV_MINIMAL < 2
+    unsigned int count () const throw ()
+    {
+      return ev_loop_count (EV_AX);
+    }
+
+    unsigned int depth () const throw ()
+    {
+      return ev_loop_depth (EV_AX);
+    }
+
     void set_io_collect_interval (tstamp interval) throw ()
     {
       ev_set_io_collect_interval (EV_AX_ interval);
@@ -241,6 +247,7 @@ namespace ev {
     {
       ev_set_timeout_collect_interval (EV_AX_ interval);
     }
+#endif
 
     // function callback
     void once (int fd, int events, tstamp timeout, void (*cb)(int, void *), void *arg = 0) throw ()
diff --git a/ev.c b/ev.c
index 595d1eff2415dc317d4c53efeb97cdc444894d9a..bfa87818106adec40ff2f729321bb8ad93f2e260 100644 (file)
--- a/ev.c
+++ b/ev.c
@@ -569,6 +569,16 @@ typedef struct
 
 #endif
 
+#if EV_MINIMAL < 2
+# define EV_SUSPEND_CB if (expect_false (suspend_cb)) suspend_cb (EV_A)
+# define EV_RESUME_CB  if (expect_false (resume_cb )) resume_cb  (EV_A)
+# define EV_INVOKE_PENDING invoke_cb (EV_A)
+#else
+# define EV_SUSPEND_CB (void)0
+# define EV_RESUME_CB  (void)0
+# define EV_INVOKE_PENDING ev_invoke_pending (EV_A)
+#endif
+
 /*****************************************************************************/
 
 #ifndef EV_HAVE_EV_TIME
@@ -1359,6 +1369,7 @@ ev_backend (EV_P)
   return backend;
 }
 
+#if EV_MINIMAL < 2
 unsigned int
 ev_loop_count (EV_P)
 {
@@ -1383,6 +1394,30 @@ ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval)
   timeout_blocktime = interval;
 }
 
+void
+ev_set_userdata (EV_P_ void *data)
+{
+  userdata = data;
+}
+
+void *
+ev_userdata (EV_P)
+{
+  return userdata;
+}
+
+void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P))
+{
+  invoke_cb = invoke_pending_cb;
+}
+
+void ev_set_blocking_cb (EV_P_ void (*suspend_cb_)(EV_P), void (*resume_cb_)(EV_P))
+{
+  suspend_cb = suspend_cb_;
+  resume_cb  = resume_cb_;
+}
+#endif
+
 /* initialise a loop structure, must be zero-initialised */
 static void noinline
 loop_init (EV_P_ unsigned int flags)
@@ -1413,7 +1448,9 @@ loop_init (EV_P_ unsigned int flags)
       mn_now            = get_clock ();
       now_floor         = mn_now;
       rtmn_diff         = ev_rt_now - mn_now;
+#if EV_MINIMAL < 2
       invoke_cb         = ev_invoke_pending;
+#endif
 
       io_blocktime      = 0.;
       timeout_blocktime = 0.;
@@ -1617,6 +1654,7 @@ ev_loop_fork (EV_P)
 {
   postfork = 1; /* must be in line with ev_default_fork */
 }
+#endif /* multiplicity */
 
 #if EV_VERIFY
 static void noinline
@@ -1654,6 +1692,7 @@ array_verify (EV_P_ W *ws, int cnt)
 }
 #endif
 
+#if EV_MINIMAL < 2
 void
 ev_loop_verify (EV_P)
 {
@@ -1716,8 +1755,7 @@ ev_loop_verify (EV_P)
 # endif
 #endif
 }
-
-#endif /* multiplicity */
+#endif
 
 #if EV_MULTIPLICITY
 struct ev_loop *
@@ -1788,7 +1826,7 @@ ev_invoke (EV_P_ void *w, int revents)
   EV_CB_INVOKE ((W)w, revents);
 }
 
-void
+void noinline
 ev_invoke_pending (EV_P)
 {
   int pri;
@@ -2037,11 +2075,13 @@ time_update (EV_P_ ev_tstamp max_block)
 void
 ev_loop (EV_P_ int flags)
 {
+#if EV_MINIMAL < 2
   ++loop_depth;
+#endif
 
   loop_done = EVUNLOOP_CANCEL;
 
-  invoke_cb (EV_A); /* in case we recurse, ensure ordering stays nice and clean */
+  EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */
 
   do
     {
@@ -2064,7 +2104,7 @@ ev_loop (EV_P_ int flags)
         if (forkcnt)
           {
             queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
-            invoke_cb (EV_A);
+            EV_INVOKE_PENDING;
           }
 #endif
 
@@ -2072,7 +2112,7 @@ ev_loop (EV_P_ int flags)
       if (expect_false (preparecnt))
         {
           queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
-          invoke_cb (EV_A);
+          EV_INVOKE_PENDING;
         }
 
       /* we might have forked, so reify kernel state if necessary */
@@ -2131,7 +2171,9 @@ ev_loop (EV_P_ int flags)
               }
           }
 
+#if EV_MINIMAL < 2
         ++loop_count;
+#endif
         backend_poll (EV_A_ waittime);
 
         /* update ev_rt_now, do magic */
@@ -2153,7 +2195,7 @@ ev_loop (EV_P_ int flags)
       if (expect_false (checkcnt))
         queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
 
-      invoke_cb (EV_A);
+      EV_INVOKE_PENDING;
     }
   while (expect_true (
     activecnt
@@ -2164,7 +2206,9 @@ ev_loop (EV_P_ int flags)
   if (loop_done == EVUNLOOP_ONE)
     loop_done = EVUNLOOP_CANCEL;
 
+#if EV_MINIMAL < 2
   --loop_depth;
+#endif
 }
 
 void
diff --git a/ev.h b/ev.h
index 16e6a94c5da1468311620ac233452addbde9ffd9..104a3c940b9c314e1e5ed7be004c44a07087d204 100644 (file)
--- a/ev.h
+++ b/ev.h
@@ -502,13 +502,9 @@ void ev_default_destroy (void); /* destroy the default loop */
 /* you can actually call it at any time, anywhere :) */
 void ev_default_fork (void);
 
-unsigned int ev_backend     (EV_P); /* backend in use by loop */
-unsigned int ev_loop_count  (EV_P); /* number of loop iterations */
-unsigned int ev_loop_depth  (EV_P); /* #ev_loop enters - #ev_loop leaves */
-void         ev_loop_verify (EV_P); /* abort if loop data corrupted */
+unsigned int ev_backend (EV_P); /* backend in use by loop */
 
-void ev_now_update     (EV_P); /* update event loop time */
-void ev_invoke_pending (EV_P); /* invoke all pending watchers */
+void ev_now_update (EV_P); /* update event loop time */
 
 #if EV_WALK_ENABLE
 /* walk (almost) all watchers in the loop of a given type, invoking the */
@@ -529,28 +525,51 @@ void ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w));
 void ev_loop (EV_P_ int flags);
 void ev_unloop (EV_P_ int how); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */
 
-void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */
-void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */
-
 /*
  * ref/unref can be used to add or remove a refcount on the mainloop. every watcher
- * keeps one reference. if you have a long-runing watcher you never unregister that
+ * keeps one reference. if you have a long-running watcher you never unregister that
  * should not keep ev_loop from running, unref() after starting, and ref() before stopping.
  */
 void ev_ref   (EV_P);
 void ev_unref (EV_P);
 
+/*
+ * convenience function, wait for a single event, without registering an event watcher
+ * if timeout is < 0, do wait indefinitely
+ */
+void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg);
+
+# if EV_MINIMAL < 2
+unsigned int ev_loop_count  (EV_P); /* number of loop iterations */
+unsigned int ev_loop_depth  (EV_P); /* #ev_loop enters - #ev_loop leaves */
+void         ev_loop_verify (EV_P); /* abort if loop data corrupted */
+
+void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */
+void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */
+
+/*
+ * a single void * can be attached to each loop. this is intended
+ * to aid the invoke_pending/blocking callbacks.
+ */
+void ev_set_userdata (EV_P_ void *data);
+void *ev_userdata (EV_P);
+
+/*
+ * hooks to overide how and when libev invokes callbacks,
+ * and hooks that wrap the actual eventloop blocking call.
+ */
+void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P));
+void ev_set_blocking_cb (EV_P_ void (*suspend_cb_)(EV_P), void (*resume_cb_)(EV_P));
+
+void ev_invoke_pending (EV_P); /* invoke all pending watchers */
+
 /*
  * stop/start the timer handling.
  */
 void ev_suspend (EV_P);
 void ev_resume  (EV_P);
+#endif
 
-/*
- * convenience function, wait for a single event, without registering an event watcher
- * if timeout is < 0, do wait indefinitely
- */
-void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg);
 #endif
 
 /* these may evaluate ev multiple times, and the other arguments at most once */
diff --git a/ev.pod b/ev.pod
index 27d3f3592c16f82fbd30c22a9a8397e250e41e27..29ee970a2fe8f2ea47013b85b455f7b2c2744f21 100644 (file)
--- a/ev.pod
+++ b/ev.pod
@@ -3681,6 +3681,11 @@ the default 4-heap.
 You can save even more by disabling watcher types you do not need and
 setting C<EV_MAXPRI> == C<EV_MINPRI>.
 
+Defining C<EV_MINIMAL> to C<2> will additionally reduce the core API to
+provide a bare-bones event library. See C<ev.h> for details on what parts
+of the API are still available, and do not complain if this subset changes
+over time.
+
 =item EV_PID_HASHSIZE
 
 C<ev_child> watchers use a small hash table to distribute workload by
index ca78ca68bc88ec8d02ccba9ef3fee51176cb3a14..4b7d2555e78cb867a9c51fb735b31faa4e480898 100644 (file)
@@ -121,9 +121,9 @@ epoll_poll (EV_P_ ev_tstamp timeout)
   int i;
   int eventcnt;
   
-  if (expect_false (suspend_cb)) suspend_cb (EV_A);
+  EV_SUSPEND_CB;
   eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.));
-  if (expect_false (resume_cb))  resume_cb  (EV_A);
+  EV_RESUME_CB;
 
   if (expect_false (eventcnt < 0))
     {
index 3a4824f522c0b365619f1dceca46d93dca325060..2a9832fc8b8b8d7117717e6f57a47f65b41f2062 100644 (file)
@@ -85,6 +85,8 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
   int res, i;
   struct timespec ts;
 
+  EV_SUSPEND_CB;
+
   /* need to resize so there is enough space for errors */
   if (kqueue_changecnt > kqueue_eventmax)
     {
@@ -93,13 +95,13 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
       kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
     }
 
-  if (expect_false (suspend_cb)) suspend_cb (EV_A);
   ts.tv_sec  = (time_t)timeout;
   ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9);
   res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts);
-  if (expect_false (resume_cb))  resume_cb  (EV_A);
   kqueue_changecnt = 0;
 
+  EV_RESUME_CB;
+
   if (expect_false (res < 0))
     { 
       if (errno != EINTR)
index f43e7809a0748d50e5c44ea80d548e418001d490..8702acac830bd8a9aa9379f9198d153a7892433e 100644 (file)
--- a/ev_poll.c
+++ b/ev_poll.c
@@ -91,9 +91,9 @@ poll_poll (EV_P_ ev_tstamp timeout)
   struct pollfd *p;
   int res;
   
-  if (expect_false (suspend_cb)) suspend_cb (EV_A);
+  EV_SUSPEND_CB;
   res = poll (polls, pollcnt, (int)ceil (timeout * 1000.));
-  if (expect_false (resume_cb))  resume_cb  (EV_A);
+  EV_RESUME_CB;
 
   if (expect_false (res < 0))
     {
index 14580432193aef6202de86a0c3ea667698876656..ff745daa8b8f8c09fb660f26e45e12effd370a21 100644 (file)
--- a/ev_port.c
+++ b/ev_port.c
@@ -85,11 +85,11 @@ port_poll (EV_P_ ev_tstamp timeout)
   struct timespec ts;
   uint_t nget = 1;
 
-  if (expect_false (suspend_cb)) suspend_cb (EV_A);
+  EV_SUSPEND_CB;
   ts.tv_sec  = (time_t)timeout;
   ts.tv_nsec = (long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9;
   res = port_getn (backend_fd, port_events, port_eventmax, &nget, &ts);
-  if (expect_false (resume_cb))  resume_cb  (EV_A);
+  EV_RESUME_CB;
 
   if (res == -1)
     { 
index ffb4d3027d59335d6fcaf4859fd89f74cd0151d0..b7bb69d4dafb20671e6ddb5972fed73ab427ed4d 100644 (file)
@@ -140,7 +140,7 @@ select_poll (EV_P_ ev_tstamp timeout)
   int res;
   int fd_setsize;
 
-  if (expect_false (suspend_cb)) suspend_cb (EV_A);
+  EV_SUSPEND_CB;
   tv.tv_sec  = (long)timeout;
   tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6);
 
@@ -167,7 +167,7 @@ select_poll (EV_P_ ev_tstamp timeout)
 #else
   res = select (vec_max * NFDBITS, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv);
 #endif
-  if (expect_false (resume_cb))  resume_cb  (EV_A);
+  EV_RESUME_CB;
 
   if (expect_false (res < 0))
     {
index 9279004eec0e2a3e844d87ba2f36799220a76747..8c6bbab42779fc93d818af4445374cc93572b376 100644 (file)
--- a/ev_vars.h
+++ b/ev_vars.h
@@ -48,8 +48,6 @@ VARx(ev_tstamp, timeout_blocktime)
 
 VARx(int, backend)
 VARx(int, activecnt) /* total number of active events ("refcount") */
-VARx(unsigned int, loop_count) /* total number of loop iterations/blocks */
-VARx(unsigned int, loop_depth) /* #ev_loop enters - #ev_loop leaves */
 VARx(char, loop_done)  /* signal by ev_unloop */
 
 VARx(int, backend_fd)
@@ -168,10 +166,18 @@ VARx(char, fs_2625) /* whether we are running in linux 2.6.25 or newer */
 VAR (fs_hash, ANFS fs_hash [EV_INOTIFY_HASHSIZE])
 #endif
 
+#if EV_MINIMAL < 2
+VARx(unsigned int, loop_count) /* total number of loop iterations/blocks */
+VARx(unsigned int, loop_depth) /* #ev_loop enters - #ev_loop leaves */
+
 VARx(void *, userdata)
+#endif
+
+#if EV_MINIMAL < 2
 VAR (suspend_cb, void (*suspend_cb)(EV_P))
 VAR (resume_cb , void (*resume_cb) (EV_P))
 VAR (invoke_cb , void (*invoke_cb) (EV_P))
+#endif
 
 #undef VARx