1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/third_party/libevent/defer-internal.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* 1.5 + * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 1.6 + * 1.7 + * Redistribution and use in source and binary forms, with or without 1.8 + * modification, are permitted provided that the following conditions 1.9 + * are met: 1.10 + * 1. Redistributions of source code must retain the above copyright 1.11 + * notice, this list of conditions and the following disclaimer. 1.12 + * 2. Redistributions in binary form must reproduce the above copyright 1.13 + * notice, this list of conditions and the following disclaimer in the 1.14 + * documentation and/or other materials provided with the distribution. 1.15 + * 3. The name of the author may not be used to endorse or promote products 1.16 + * derived from this software without specific prior written permission. 1.17 + * 1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1.20 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1.21 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1.22 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1.23 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.24 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.25 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.26 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 1.27 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.28 + */ 1.29 +#ifndef _DEFER_INTERNAL_H_ 1.30 +#define _DEFER_INTERNAL_H_ 1.31 + 1.32 +#ifdef __cplusplus 1.33 +extern "C" { 1.34 +#endif 1.35 + 1.36 +#include "event2/event-config.h" 1.37 +#include <sys/queue.h> 1.38 + 1.39 +struct deferred_cb; 1.40 + 1.41 +typedef void (*deferred_cb_fn)(struct deferred_cb *, void *); 1.42 + 1.43 +/** A deferred_cb is a callback that can be scheduled to run as part of 1.44 + * an event_base's event_loop, rather than running immediately. */ 1.45 +struct deferred_cb { 1.46 + /** Links to the adjacent active (pending) deferred_cb objects. */ 1.47 + TAILQ_ENTRY (deferred_cb) cb_next; 1.48 + /** True iff this deferred_cb is pending in an event_base. */ 1.49 + unsigned queued : 1; 1.50 + /** The function to execute when the callback runs. */ 1.51 + deferred_cb_fn cb; 1.52 + /** The function's second argument. */ 1.53 + void *arg; 1.54 +}; 1.55 + 1.56 +/** A deferred_cb_queue is a list of deferred_cb that we can add to and run. */ 1.57 +struct deferred_cb_queue { 1.58 + /** Lock used to protect the queue. */ 1.59 + void *lock; 1.60 + 1.61 + /** How many entries are in the queue? */ 1.62 + int active_count; 1.63 + 1.64 + /** Function called when adding to the queue from another thread. */ 1.65 + void (*notify_fn)(struct deferred_cb_queue *, void *); 1.66 + void *notify_arg; 1.67 + 1.68 + /** Deferred callback management: a list of deferred callbacks to 1.69 + * run active the active events. */ 1.70 + TAILQ_HEAD (deferred_cb_list, deferred_cb) deferred_cb_list; 1.71 +}; 1.72 + 1.73 +/** 1.74 + Initialize an empty, non-pending deferred_cb. 1.75 + 1.76 + @param deferred The deferred_cb structure to initialize. 1.77 + @param cb The function to run when the deferred_cb executes. 1.78 + @param arg The function's second argument. 1.79 + */ 1.80 +void event_deferred_cb_init(struct deferred_cb *, deferred_cb_fn, void *); 1.81 +/** 1.82 + Cancel a deferred_cb if it is currently scheduled in an event_base. 1.83 + */ 1.84 +void event_deferred_cb_cancel(struct deferred_cb_queue *, struct deferred_cb *); 1.85 +/** 1.86 + Activate a deferred_cb if it is not currently scheduled in an event_base. 1.87 + */ 1.88 +void event_deferred_cb_schedule(struct deferred_cb_queue *, struct deferred_cb *); 1.89 + 1.90 +#define LOCK_DEFERRED_QUEUE(q) \ 1.91 + EVLOCK_LOCK((q)->lock, 0) 1.92 +#define UNLOCK_DEFERRED_QUEUE(q) \ 1.93 + EVLOCK_UNLOCK((q)->lock, 0) 1.94 + 1.95 +#ifdef __cplusplus 1.96 +} 1.97 +#endif 1.98 + 1.99 +void event_deferred_cb_queue_init(struct deferred_cb_queue *); 1.100 +struct deferred_cb_queue *event_base_get_deferred_cb_queue(struct event_base *); 1.101 + 1.102 +#endif /* _EVENT_INTERNAL_H_ */ 1.103 +