*** empty log message ***

This commit is contained in:
Marc Alexander Lehmann 2007-12-05 13:54:36 +00:00
parent 4989fff209
commit 67ffe0b273
4 changed files with 40 additions and 18 deletions

50
ev.c
View File

@ -398,23 +398,44 @@ ev_now (EV_P)
}
#endif
#define array_roundsize(type,n) (((n) | 4) & ~3)
int inline_size
array_nextsize (int elem, int cur, int cnt)
{
int ncur = cur + 1;
#define array_needsize(type,base,cur,cnt,init) \
if (expect_false ((cnt) > cur)) \
{ \
int newcnt = cur; \
do \
{ \
newcnt = array_roundsize (type, newcnt << 1); \
} \
while ((cnt) > newcnt); \
\
base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\
init (base + cur, newcnt - cur); \
cur = newcnt; \
do
ncur <<= 1;
while (cnt > ncur);
/* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */
if (elem * ncur > 4096)
{
ncur *= elem;
ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095;
ncur = ncur - sizeof (void *) * 4;
ncur /= elem;
}
return ncur;
}
inline_speed void *
array_realloc (int elem, void *base, int *cur, int cnt)
{
*cur = array_nextsize (elem, *cur, cnt);
return ev_realloc (base, elem * *cur);
}
#define array_needsize(type,base,cur,cnt,init) \
if (expect_false ((cnt) > (cur))) \
{ \
int ocur_ = (cur); \
(base) = (type *)array_realloc \
(sizeof (type), (base), &(cur), (cnt)); \
init ((base) + (ocur_), (cur) - ocur_); \
}
#if 0
#define array_slim(type,stem) \
if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
{ \
@ -422,6 +443,7 @@ ev_now (EV_P)
base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
}
#endif
#define array_free(stem, idx) \
ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;

View File

@ -74,7 +74,7 @@ epoll_poll (EV_P_ ev_tstamp timeout)
if (expect_false (eventcnt == epoll_eventmax))
{
ev_free (epoll_events);
epoll_eventmax = array_roundsize (epoll_events, epoll_eventmax << 1);
epoll_eventmax = array_nextsize (sizeof (struct epoll_event), epoll_eventmax, epoll_eventmax + 1);
epoll_events = (struct epoll_event *)ev_malloc (sizeof (struct epoll_event) * epoll_eventmax);
}
}

View File

@ -83,7 +83,7 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
if (kqueue_changecnt > kqueue_eventmax)
{
ev_free (kqueue_events);
kqueue_eventmax = array_roundsize (struct kevent, kqueue_changecnt);
kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt);
kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
}
@ -137,7 +137,7 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
if (expect_false (res == kqueue_eventmax))
{
ev_free (kqueue_events);
kqueue_eventmax = array_roundsize (struct kevent, kqueue_eventmax << 1);
kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_eventmax + 1);
kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
}
}

View File

@ -103,7 +103,7 @@ port_poll (EV_P_ ev_tstamp timeout)
if (expect_false (nget == port_eventmax))
{
ev_free (port_events);
port_eventmax = array_roundsize (port_event_t, port_eventmax << 1);
port_eventmax = array_nextsize (sizeof (port_event_t), port_eventmax, port_eventmax + 1);
port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax);
}
}