More documentation for finalization feature

This commit is contained in:
Nick Mathewson 2013-04-26 11:36:43 -04:00
parent 4ea4c6a93e
commit a800b913ac
6 changed files with 45 additions and 10 deletions

View File

@ -252,11 +252,13 @@ struct bufferevent_ops {
*/ */
int (*disable)(struct bufferevent *, short); int (*disable)(struct bufferevent *, short);
/** DOCUMENT */ /** Detatches the bufferevent from related data structures. Called as
* soon as its reference count reaches 0. */
void (*unlink)(struct bufferevent *); void (*unlink)(struct bufferevent *);
/** Free any storage and deallocate any extra data or structures used /** Free any storage and deallocate any extra data or structures used
in this implementation. DOCUMENT in this implementation. Called when the bufferevent is
finalized.
*/ */
void (*destruct)(struct bufferevent *); void (*destruct)(struct bufferevent *);

View File

@ -1193,8 +1193,8 @@ be_openssl_unlink(struct bufferevent *bev)
"bufferevent with too few references"); "bufferevent with too few references");
} else { } else {
bufferevent_free(bev_ssl->underlying); bufferevent_free(bev_ssl->underlying);
/* We still have a reference to it, since DOCUMENT. So we don't /* We still have a reference to it, via our
* drop this. */ * BIO. So we don't drop this. */
// bev_ssl->underlying = NULL; // bev_ssl->underlying = NULL;
} }
} }

View File

@ -59,15 +59,28 @@ extern "C" {
#define ev_callback ev_evcallback.evcb_cb_union.evcb_callback #define ev_callback ev_evcallback.evcb_cb_union.evcb_callback
#define ev_arg ev_evcallback.evcb_arg #define ev_arg ev_evcallback.evcb_arg
/* Possible values for evcb_closure in struct event_callback */ /** @name Event closure codes
/* DOCUMENT these. */
Possible values for evcb_closure in struct event_callback
@{
*/
/** A regular event. Uses the evcb_callback callback */
#define EV_CLOSURE_EVENT 0 #define EV_CLOSURE_EVENT 0
/** A signal event. Uses the evcb_callback callback */
#define EV_CLOSURE_EVENT_SIGNAL 1 #define EV_CLOSURE_EVENT_SIGNAL 1
/** A persistent non-signal event. Uses the evcb_callback callback */
#define EV_CLOSURE_EVENT_PERSIST 2 #define EV_CLOSURE_EVENT_PERSIST 2
/** A simple callback. Uses the evcb_selfcb callback. */
#define EV_CLOSURE_CB_SELF 3 #define EV_CLOSURE_CB_SELF 3
/** A finalizing callback. Uses the evcb_cbfinalize callback. */
#define EV_CLOSURE_CB_FINALIZE 4 #define EV_CLOSURE_CB_FINALIZE 4
/** A finalizing event. Uses the evcb_evfinalize callback. */
#define EV_CLOSURE_EVENT_FINALIZE 5 #define EV_CLOSURE_EVENT_FINALIZE 5
/** A finalizing event that should get freed after. Uses the evcb_evfinalize
* callback. */
#define EV_CLOSURE_EVENT_FINALIZE_FREE 6 #define EV_CLOSURE_EVENT_FINALIZE_FREE 6
/** @} */
/** Structure to define the backend of a given event_base. */ /** Structure to define the backend of a given event_base. */
struct eventop { struct eventop {
@ -386,9 +399,19 @@ int evsig_restore_handler_(struct event_base *base, int evsignal);
int event_add_nolock_(struct event *ev, int event_add_nolock_(struct event *ev,
const struct timeval *tv, int tv_is_absolute); const struct timeval *tv, int tv_is_absolute);
/** Argument for event_del_nolock_. Tells event_del not to block on the event
* if it's running in another thread. */
#define EVENT_DEL_NOBLOCK 0 #define EVENT_DEL_NOBLOCK 0
/** Argument for event_del_nolock_. Tells event_del to block on the event
* if it's running in another thread, regardless of its value for EV_FINALIZE
*/
#define EVENT_DEL_BLOCK 1 #define EVENT_DEL_BLOCK 1
/** Argument for event_del_nolock_. Tells event_del to block on the event
* if it is running in another thread and it doesn't have EV_FINALIZE set.
*/
#define EVENT_DEL_AUTOBLOCK 2 #define EVENT_DEL_AUTOBLOCK 2
/** Argument for event_del_nolock_. Tells event_del to procede even if the
* event is set up for finalization rather for regular use.*/
#define EVENT_DEL_EVEN_IF_FINALIZING 3 #define EVENT_DEL_EVEN_IF_FINALIZING 3
int event_del_nolock_(struct event *ev, int blocking); int event_del_nolock_(struct event *ev, int blocking);
int event_remove_timer_nolock_(struct event *ev); int event_remove_timer_nolock_(struct event *ev);

View File

@ -2599,8 +2599,11 @@ event_del_noblock(struct event *ev)
return event_del_(ev, EVENT_DEL_NOBLOCK); return event_del_(ev, EVENT_DEL_NOBLOCK);
} }
/* Helper for event_del: always called with th_base_lock held. /** Helper for event_del: always called with th_base_lock held.
* DOCUMENT blocking */ *
* "blocking" must be one of the EVENT_DEL_{BLOCK, NOBLOCK, AUTOBLOCK,
* EVEN_IF_FINALIZING} values. See those for more information.
*/
int int
event_del_nolock_(struct event *ev, int blocking) event_del_nolock_(struct event *ev, int blocking)
{ {

View File

@ -599,12 +599,16 @@ struct event_base *event_base_new_with_config(const struct event_config *);
Note that this function will not close any fds or free any memory passed Note that this function will not close any fds or free any memory passed
to event_new as the argument to callback. to event_new as the argument to callback.
If there are any pending finalizer callbacks, this function will invoke
them.
@param eb an event_base to be freed @param eb an event_base to be freed
*/ */
void event_base_free(struct event_base *); void event_base_free(struct event_base *);
/** DOCUMENT */ /**
As event_free, but do not run finalizers.
*/
void event_base_free_nofinalize(struct event_base *); void event_base_free_nofinalize(struct event_base *);
/** @name Log severities /** @name Log severities
@ -1038,6 +1042,10 @@ typedef void (*event_finalize_callback_fn)(struct event *, void *);
The event_free_finalize() function frees the event after it's finalized; The event_free_finalize() function frees the event after it's finalized;
event_finalize() does not. event_finalize() does not.
A finalizer callback must not make events pending or active. It must not
add events, activate events, or attempt to "resucitate" the event being
finalized in any way.
*/ */
/**@{*/ /**@{*/
void event_finalize(unsigned, struct event *, event_finalize_callback_fn); void event_finalize(unsigned, struct event *, event_finalize_callback_fn);

View File

@ -105,7 +105,6 @@ struct name { \
struct event; struct event;
struct event_callback { struct event_callback {
/* DOCUMENT all these fields */
TAILQ_ENTRY(event_callback) evcb_active_next; TAILQ_ENTRY(event_callback) evcb_active_next;
short evcb_flags; short evcb_flags;
ev_uint8_t evcb_pri; /* smaller numbers are higher priority */ ev_uint8_t evcb_pri; /* smaller numbers are higher priority */