r15317@tombo: nickm | 2008-04-24 21:17:49 -0400

Add new functions to be more threadsafe (and structure-ignorant) than event_set.


svn:r726
This commit is contained in:
Nick Mathewson 2008-04-25 01:18:18 +00:00
parent 49868b618a
commit 94fb4d0a1e
3 changed files with 38 additions and 0 deletions

View File

@ -69,6 +69,7 @@ Changes in current version:
o Add new thread-safe interfaces to evdns functions.
o Make all event_tagging interfaces threadsafe.
o Rename internal memory management functions.
o New functions (event_assign, event_new, event_free) for use by apps that want to be safely threadsafe, or want to remain ignorant of the contents of struct event.
Changes in 1.4.0:
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.

30
event.c
View File

@ -664,6 +664,36 @@ event_base_set(struct event_base *base, struct event *ev)
return (0);
}
int
event_assign(struct event *ev, struct event_base *base, evutil_socket_t fd, short events, void (*cb)(evutil_socket_t, short, void *), void *arg)
{
event_set(ev, fd, events, cb, arg);
return event_base_set(base, ev);
}
struct event *
event_new(struct event_base *base, evutil_socket_t fd, short events, void (*cb)(evutil_socket_t, short, void *), void *arg)
{
struct event *ev;
ev = mm_malloc(sizeof(struct event));
if (!ev)
return NULL;
if (event_assign(ev, base, fd, events, cb, arg) < 0) {
mm_free(ev);
return NULL;
}
return ev;
}
void
event_free(struct event *ev)
{
/* make sure that this event won't be coming back to haunt us.
* XXX this is safe, right? */
event_del(ev);
mm_free(ev);
}
/*
* Set's the priority of an event - if an event is already scheduled
* changing the priority is going to fail.

View File

@ -285,6 +285,13 @@ int event_base_loopbreak(struct event_base *);
*/
void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
/*XXX document this function, deprecate previous one. */
int event_assign(struct event *, struct event_base *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
struct event *event_new(struct event_base *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
void event_free(struct event *);
/**
Schedule a one-time event (threadsafe variant)