From: root
Date: Tue, 27 Nov 2007 19:23:31 +0000 (+0000)
Subject: *** empty log message ***
X-Git-Tag: rel-1_5~16
X-Git-Url: https://git.llucax.com/software/libev.git/commitdiff_plain/6800c1e86d28e4bc573747e6d327c770b2e00df4
*** empty log message ***
---
diff --git a/ev.3 b/ev.3
index 01e5c65..d718a09 100644
--- a/ev.3
+++ b/ev.3
@@ -2120,6 +2120,12 @@ defined to be \f(CW0\fR, then they are not.
If you need to shave off some kilobytes of code at the expense of some
speed, define this symbol to \f(CW1\fR. Currently only used for gcc to override
some inlining decisions, saves roughly 30% codesize of amd64.
+.IP "\s-1EV_PID_HASHSIZE\s0" 4
+.IX Item "EV_PID_HASHSIZE"
+\&\f(CW\*(C`ev_child\*(C'\fR watchers use a small hash table to distribute workload by
+pid. The default size is \f(CW16\fR (or \f(CW1\fR with \f(CW\*(C`EV_MINIMAL\*(C'\fR), usually more
+than enough. If you need to manage thousands of children you might want to
+increase this value.
.IP "\s-1EV_COMMON\s0" 4
.IX Item "EV_COMMON"
By default, all watchers have a \f(CW\*(C`void *data\*(C'\fR member. By redefining
diff --git a/ev.c b/ev.c
index f868d7e..8911cb8 100644
--- a/ev.c
+++ b/ev.c
@@ -158,6 +158,14 @@ extern "C" {
# define EV_USE_PORT 0
#endif
+#ifndef EV_PID_HASHSIZE
+# if EV_MINIMAL
+# define EV_PID_HASHSIZE 1
+# else
+# define EV_PID_HASHSIZE 16
+# endif
+#endif
+
/**/
#ifndef CLOCK_MONOTONIC
@@ -178,7 +186,6 @@ extern "C" {
#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
-#define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */
/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
#ifdef EV_H
@@ -711,7 +718,7 @@ siginit (EV_P)
/*****************************************************************************/
-static ev_child *childs [PID_HASHSIZE];
+static ev_child *childs [EV_PID_HASHSIZE];
#ifndef _WIN32
@@ -722,7 +729,7 @@ child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status)
{
ev_child *w;
- for (w = (ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
+ for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
if (w->pid == pid || !w->pid)
{
ev_priority (w) = ev_priority (sw); /* need to do it *now* */
@@ -753,7 +760,8 @@ childcb (EV_P_ ev_signal *sw, int revents)
ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
child_reap (EV_A_ sw, pid, pid, status);
- child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
+ if (EV_PID_HASHSIZE > 1)
+ child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
}
#endif
@@ -1627,7 +1635,7 @@ ev_child_start (EV_P_ ev_child *w)
return;
ev_start (EV_A_ (W)w, 1);
- wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
+ wlist_add ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
}
void
@@ -1637,7 +1645,7 @@ ev_child_stop (EV_P_ ev_child *w)
if (expect_false (!ev_is_active (w)))
return;
- wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
+ wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
ev_stop (EV_A_ (W)w);
}
diff --git a/ev.html b/ev.html
index c5df51e..5bcffd0 100644
--- a/ev.html
+++ b/ev.html
@@ -6,7 +6,7 @@
-
+
@@ -1997,6 +1997,13 @@ defined to be 0, then they are not.
If you need to shave off some kilobytes of code at the expense of some
speed, define this symbol to 1. Currently only used for gcc to override
some inlining decisions, saves roughly 30% codesize of amd64.
+
+
EV_PID_HASHSIZE
+
+
ev_child watchers use a small hash table to distribute workload by
+pid. The default size is 16 (or 1 with EV_MINIMAL), usually more
+than enough. If you need to manage thousands of children you might want to
+increase this value.
EV_COMMON
diff --git a/ev.pod b/ev.pod
index 17484ff..5b0835d 100644
--- a/ev.pod
+++ b/ev.pod
@@ -1999,6 +1999,13 @@ If you need to shave off some kilobytes of code at the expense of some
speed, define this symbol to C<1>. Currently only used for gcc to override
some inlining decisions, saves roughly 30% codesize of amd64.
+=item EV_PID_HASHSIZE
+
+C watchers use a small hash table to distribute workload by
+pid. The default size is C<16> (or C<1> with C), usually more
+than enough. If you need to manage thousands of children you might want to
+increase this value.
+
=item EV_COMMON
By default, all watchers have a C member. By redefining