mirror of
https://github.com/cuberite/libevent.git
synced 2025-08-04 09:46:23 -04:00
introduce a way to free the base from Nick Mathewson <nickm@freehaven.net>
svn:r210
This commit is contained in:
parent
571ac95430
commit
2e8051f593
@ -81,6 +81,7 @@ int win32_insert (void *, struct event *);
|
|||||||
int win32_del (void *, struct event *);
|
int win32_del (void *, struct event *);
|
||||||
int win32_recalc (struct event_base *base, void *, int);
|
int win32_recalc (struct event_base *base, void *, int);
|
||||||
int win32_dispatch (struct event_base *base, void *, struct timeval *);
|
int win32_dispatch (struct event_base *base, void *, struct timeval *);
|
||||||
|
void win32_dealloc (void *);
|
||||||
|
|
||||||
struct eventop win32ops = {
|
struct eventop win32ops = {
|
||||||
"win32",
|
"win32",
|
||||||
@ -88,7 +89,8 @@ struct eventop win32ops = {
|
|||||||
win32_insert,
|
win32_insert,
|
||||||
win32_del,
|
win32_del,
|
||||||
win32_recalc,
|
win32_recalc,
|
||||||
win32_dispatch
|
win32_dispatch,
|
||||||
|
win32_dealloc
|
||||||
};
|
};
|
||||||
|
|
||||||
#define FD_SET_ALLOC_SIZE(n) ((sizeof(struct win_fd_set) + ((n)-1)*sizeof(SOCKET)))
|
#define FD_SET_ALLOC_SIZE(n) ((sizeof(struct win_fd_set) + ((n)-1)*sizeof(SOCKET)))
|
||||||
@ -365,6 +367,27 @@ win32_dispatch(struct event_base *base, struct win32op *win32op,
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
win32_dealloc(void *arg)
|
||||||
|
{
|
||||||
|
struct win32op *win32op = arg;
|
||||||
|
|
||||||
|
if (win32op->readset_in)
|
||||||
|
free(win32op->readset_in);
|
||||||
|
if (win32op->writeset_in)
|
||||||
|
free(win32op->writeset_in);
|
||||||
|
if (win32op->readset_out)
|
||||||
|
free(win32op->readset_out);
|
||||||
|
if (win32op->writeset_out)
|
||||||
|
free(win32op->writeset_out);
|
||||||
|
if (win32op->exset_out)
|
||||||
|
free(win32op->exset_out);
|
||||||
|
if (win32op->events)
|
||||||
|
free(win32op->events);
|
||||||
|
|
||||||
|
memset(win32op, 0, sizeof(win32op));
|
||||||
|
free(win32op);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
signal_handler(int sig)
|
signal_handler(int sig)
|
||||||
|
22
devpoll.c
22
devpoll.c
@ -76,6 +76,7 @@ int devpoll_add (void *, struct event *);
|
|||||||
int devpoll_del (void *, struct event *);
|
int devpoll_del (void *, struct event *);
|
||||||
int devpoll_recalc (struct event_base *, void *, int);
|
int devpoll_recalc (struct event_base *, void *, int);
|
||||||
int devpoll_dispatch (struct event_base *, void *, struct timeval *);
|
int devpoll_dispatch (struct event_base *, void *, struct timeval *);
|
||||||
|
void devpoll_dealloc (void *);
|
||||||
|
|
||||||
struct eventop devpollops = {
|
struct eventop devpollops = {
|
||||||
"devpoll",
|
"devpoll",
|
||||||
@ -83,7 +84,8 @@ struct eventop devpollops = {
|
|||||||
devpoll_add,
|
devpoll_add,
|
||||||
devpoll_del,
|
devpoll_del,
|
||||||
devpoll_recalc,
|
devpoll_recalc,
|
||||||
devpoll_dispatch
|
devpoll_dispatch,
|
||||||
|
devpoll_dealloc
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NEVENT 32000
|
#define NEVENT 32000
|
||||||
@ -401,3 +403,21 @@ devpoll_del(void *arg, struct event *ev)
|
|||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
devpoll_dealloc(void *arg)
|
||||||
|
{
|
||||||
|
struct devpollop *devpollop = arg;
|
||||||
|
|
||||||
|
if (devpollop->fds)
|
||||||
|
free(devpollop->fds);
|
||||||
|
if (devpollop->events)
|
||||||
|
free(devpollop->events);
|
||||||
|
if (devpollop->changes)
|
||||||
|
free(devpollop->changes);
|
||||||
|
if (devpollop->dpfd >= 0)
|
||||||
|
close(devpollop->dpfd);
|
||||||
|
|
||||||
|
memset(devpollop, 0, sizeof(struct devpollop));
|
||||||
|
free(devpollop);
|
||||||
|
}
|
||||||
|
20
epoll.c
20
epoll.c
@ -76,6 +76,7 @@ int epoll_add (void *, struct event *);
|
|||||||
int epoll_del (void *, struct event *);
|
int epoll_del (void *, struct event *);
|
||||||
int epoll_recalc (struct event_base *, void *, int);
|
int epoll_recalc (struct event_base *, void *, int);
|
||||||
int epoll_dispatch (struct event_base *, void *, struct timeval *);
|
int epoll_dispatch (struct event_base *, void *, struct timeval *);
|
||||||
|
void epoll_dealloc (void *);
|
||||||
|
|
||||||
struct eventop epollops = {
|
struct eventop epollops = {
|
||||||
"epoll",
|
"epoll",
|
||||||
@ -83,7 +84,8 @@ struct eventop epollops = {
|
|||||||
epoll_add,
|
epoll_add,
|
||||||
epoll_del,
|
epoll_del,
|
||||||
epoll_recalc,
|
epoll_recalc,
|
||||||
epoll_dispatch
|
epoll_dispatch,
|
||||||
|
epoll_dealloc
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_SETFD
|
#ifdef HAVE_SETFD
|
||||||
@ -349,3 +351,19 @@ epoll_del(void *arg, struct event *ev)
|
|||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
epoll_dealloc(void *arg)
|
||||||
|
{
|
||||||
|
struct epollop *epollop = arg;
|
||||||
|
|
||||||
|
if (epollop->fds)
|
||||||
|
free(epollop->fds);
|
||||||
|
if (epollop->events)
|
||||||
|
free(epollop->events);
|
||||||
|
if (epollop->epfd >= 0)
|
||||||
|
close(epollop->epfd);
|
||||||
|
|
||||||
|
memset(epollop, 0, sizeof(struct epollop));
|
||||||
|
free(epollop);
|
||||||
|
}
|
||||||
|
27
event.c
27
event.c
@ -196,6 +196,33 @@ event_init(void)
|
|||||||
return (current_base);
|
return (current_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
event_base_free(struct event_base *base)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (base == NULL && current_base)
|
||||||
|
base = current_base;
|
||||||
|
if (base == current_base)
|
||||||
|
current_base = NULL;
|
||||||
|
|
||||||
|
assert(base);
|
||||||
|
assert(TAILQ_EMPTY(&base->eventqueue));
|
||||||
|
for (i=0; i < base->nactivequeues; ++i)
|
||||||
|
assert(TAILQ_EMPTY(base->activequeues[i]));
|
||||||
|
|
||||||
|
assert(RB_EMPTY(&base->timetree));
|
||||||
|
|
||||||
|
for (i = 0; i < base->nactivequeues; ++i)
|
||||||
|
free(base->activequeues[i]);
|
||||||
|
free(base->activequeues);
|
||||||
|
|
||||||
|
if (base->evsel->dealloc != NULL)
|
||||||
|
base->evsel->dealloc(base->evbase);
|
||||||
|
|
||||||
|
free(base);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
event_priority_init(int npriorities)
|
event_priority_init(int npriorities)
|
||||||
{
|
{
|
||||||
|
2
event.h
2
event.h
@ -135,6 +135,7 @@ struct eventop {
|
|||||||
int (*del)(void *, struct event *);
|
int (*del)(void *, struct event *);
|
||||||
int (*recalc)(struct event_base *, void *, int);
|
int (*recalc)(struct event_base *, void *, int);
|
||||||
int (*dispatch)(struct event_base *, void *, struct timeval *);
|
int (*dispatch)(struct event_base *, void *, struct timeval *);
|
||||||
|
void (*dealloc)(void *);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TIMEOUT_DEFAULT {5, 0}
|
#define TIMEOUT_DEFAULT {5, 0}
|
||||||
@ -142,6 +143,7 @@ struct eventop {
|
|||||||
void *event_init(void);
|
void *event_init(void);
|
||||||
int event_dispatch(void);
|
int event_dispatch(void);
|
||||||
int event_base_dispatch(struct event_base *);
|
int event_base_dispatch(struct event_base *);
|
||||||
|
void event_base_free(struct event_base *);
|
||||||
|
|
||||||
#define _EVENT_LOG_DEBUG 0
|
#define _EVENT_LOG_DEBUG 0
|
||||||
#define _EVENT_LOG_MSG 1
|
#define _EVENT_LOG_MSG 1
|
||||||
|
19
kqueue.c
19
kqueue.c
@ -75,6 +75,7 @@ int kq_del (void *, struct event *);
|
|||||||
int kq_recalc (struct event_base *, void *, int);
|
int kq_recalc (struct event_base *, void *, int);
|
||||||
int kq_dispatch (struct event_base *, void *, struct timeval *);
|
int kq_dispatch (struct event_base *, void *, struct timeval *);
|
||||||
int kq_insert (struct kqop *, struct kevent *);
|
int kq_insert (struct kqop *, struct kevent *);
|
||||||
|
void kq_dealloc (void *);
|
||||||
|
|
||||||
const struct eventop kqops = {
|
const struct eventop kqops = {
|
||||||
"kqueue",
|
"kqueue",
|
||||||
@ -82,7 +83,8 @@ const struct eventop kqops = {
|
|||||||
kq_add,
|
kq_add,
|
||||||
kq_del,
|
kq_del,
|
||||||
kq_recalc,
|
kq_recalc,
|
||||||
kq_dispatch
|
kq_dispatch,
|
||||||
|
kq_dealloc
|
||||||
};
|
};
|
||||||
|
|
||||||
void *
|
void *
|
||||||
@ -394,3 +396,18 @@ kq_del(void *arg, struct event *ev)
|
|||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
kq_dealloc(void *arg)
|
||||||
|
{
|
||||||
|
struct kqop *kqop = arg;
|
||||||
|
|
||||||
|
if (kqop->changes)
|
||||||
|
free(kqop->changes);
|
||||||
|
if (kqop->events)
|
||||||
|
free(kqop->events);
|
||||||
|
if (kqop->kq)
|
||||||
|
close(kqop->kq);
|
||||||
|
memset(kqop, 0, sizeof(struct kqop));
|
||||||
|
free(kqop);
|
||||||
|
}
|
||||||
|
22
poll.c
22
poll.c
@ -74,6 +74,7 @@ int poll_add (void *, struct event *);
|
|||||||
int poll_del (void *, struct event *);
|
int poll_del (void *, struct event *);
|
||||||
int poll_recalc (struct event_base *, void *, int);
|
int poll_recalc (struct event_base *, void *, int);
|
||||||
int poll_dispatch (struct event_base *, void *, struct timeval *);
|
int poll_dispatch (struct event_base *, void *, struct timeval *);
|
||||||
|
void poll_dealloc (void *);
|
||||||
|
|
||||||
const struct eventop pollops = {
|
const struct eventop pollops = {
|
||||||
"poll",
|
"poll",
|
||||||
@ -81,7 +82,8 @@ const struct eventop pollops = {
|
|||||||
poll_add,
|
poll_add,
|
||||||
poll_del,
|
poll_del,
|
||||||
poll_recalc,
|
poll_recalc,
|
||||||
poll_dispatch
|
poll_dispatch,
|
||||||
|
poll_dealloc
|
||||||
};
|
};
|
||||||
|
|
||||||
void *
|
void *
|
||||||
@ -355,3 +357,21 @@ poll_del(void *arg, struct event *ev)
|
|||||||
poll_check_ok(pop);
|
poll_check_ok(pop);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
poll_dealloc(void *arg)
|
||||||
|
{
|
||||||
|
struct pollop *pop = arg;
|
||||||
|
|
||||||
|
if (pop->event_set)
|
||||||
|
free(pop->event_set);
|
||||||
|
if (pop->event_r_back)
|
||||||
|
free(pop->event_r_back);
|
||||||
|
if (pop->event_w_back)
|
||||||
|
free(pop->event_w_back);
|
||||||
|
if (pop->idxplus1_by_fd)
|
||||||
|
free(pop->idxplus1_by_fd);
|
||||||
|
|
||||||
|
memset(pop, 0, sizeof(struct pollop));
|
||||||
|
free(pop);
|
||||||
|
}
|
||||||
|
26
select.c
26
select.c
@ -76,6 +76,7 @@ int select_add (void *, struct event *);
|
|||||||
int select_del (void *, struct event *);
|
int select_del (void *, struct event *);
|
||||||
int select_recalc (struct event_base *, void *, int);
|
int select_recalc (struct event_base *, void *, int);
|
||||||
int select_dispatch (struct event_base *, void *, struct timeval *);
|
int select_dispatch (struct event_base *, void *, struct timeval *);
|
||||||
|
void select_dealloc (void *);
|
||||||
|
|
||||||
const struct eventop selectops = {
|
const struct eventop selectops = {
|
||||||
"select",
|
"select",
|
||||||
@ -83,7 +84,8 @@ const struct eventop selectops = {
|
|||||||
select_add,
|
select_add,
|
||||||
select_del,
|
select_del,
|
||||||
select_recalc,
|
select_recalc,
|
||||||
select_dispatch
|
select_dispatch,
|
||||||
|
select_dealloc
|
||||||
};
|
};
|
||||||
|
|
||||||
static int select_resize(struct selectop *sop, int fdsz);
|
static int select_resize(struct selectop *sop, int fdsz);
|
||||||
@ -350,3 +352,25 @@ select_del(void *arg, struct event *ev)
|
|||||||
check_selectop(sop);
|
check_selectop(sop);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
select_dealloc(void *arg)
|
||||||
|
{
|
||||||
|
struct selectop *sop = arg;
|
||||||
|
|
||||||
|
if (sop->event_readset_in)
|
||||||
|
free(sop->event_readset_in);
|
||||||
|
if (sop->event_writeset_in)
|
||||||
|
free(sop->event_writeset_in);
|
||||||
|
if (sop->event_readset_out)
|
||||||
|
free(sop->event_readset_out);
|
||||||
|
if (sop->event_writeset_out)
|
||||||
|
free(sop->event_writeset_out);
|
||||||
|
if (sop->event_r_by_fd)
|
||||||
|
free(sop->event_r_by_fd);
|
||||||
|
if (sop->event_w_by_fd)
|
||||||
|
free(sop->event_w_by_fd);
|
||||||
|
|
||||||
|
memset(sop, 0, sizeof(struct selectop));
|
||||||
|
free(sop);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user