ipc/chromium/src/third_party/libevent/defer-internal.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
michael@0 3 *
michael@0 4 * Redistribution and use in source and binary forms, with or without
michael@0 5 * modification, are permitted provided that the following conditions
michael@0 6 * are met:
michael@0 7 * 1. Redistributions of source code must retain the above copyright
michael@0 8 * notice, this list of conditions and the following disclaimer.
michael@0 9 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 10 * notice, this list of conditions and the following disclaimer in the
michael@0 11 * documentation and/or other materials provided with the distribution.
michael@0 12 * 3. The name of the author may not be used to endorse or promote products
michael@0 13 * derived from this software without specific prior written permission.
michael@0 14 *
michael@0 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
michael@0 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
michael@0 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@0 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
michael@0 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
michael@0 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
michael@0 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 25 */
michael@0 26 #ifndef _DEFER_INTERNAL_H_
michael@0 27 #define _DEFER_INTERNAL_H_
michael@0 28
michael@0 29 #ifdef __cplusplus
michael@0 30 extern "C" {
michael@0 31 #endif
michael@0 32
michael@0 33 #include "event2/event-config.h"
michael@0 34 #include <sys/queue.h>
michael@0 35
michael@0 36 struct deferred_cb;
michael@0 37
michael@0 38 typedef void (*deferred_cb_fn)(struct deferred_cb *, void *);
michael@0 39
michael@0 40 /** A deferred_cb is a callback that can be scheduled to run as part of
michael@0 41 * an event_base's event_loop, rather than running immediately. */
michael@0 42 struct deferred_cb {
michael@0 43 /** Links to the adjacent active (pending) deferred_cb objects. */
michael@0 44 TAILQ_ENTRY (deferred_cb) cb_next;
michael@0 45 /** True iff this deferred_cb is pending in an event_base. */
michael@0 46 unsigned queued : 1;
michael@0 47 /** The function to execute when the callback runs. */
michael@0 48 deferred_cb_fn cb;
michael@0 49 /** The function's second argument. */
michael@0 50 void *arg;
michael@0 51 };
michael@0 52
michael@0 53 /** A deferred_cb_queue is a list of deferred_cb that we can add to and run. */
michael@0 54 struct deferred_cb_queue {
michael@0 55 /** Lock used to protect the queue. */
michael@0 56 void *lock;
michael@0 57
michael@0 58 /** How many entries are in the queue? */
michael@0 59 int active_count;
michael@0 60
michael@0 61 /** Function called when adding to the queue from another thread. */
michael@0 62 void (*notify_fn)(struct deferred_cb_queue *, void *);
michael@0 63 void *notify_arg;
michael@0 64
michael@0 65 /** Deferred callback management: a list of deferred callbacks to
michael@0 66 * run active the active events. */
michael@0 67 TAILQ_HEAD (deferred_cb_list, deferred_cb) deferred_cb_list;
michael@0 68 };
michael@0 69
michael@0 70 /**
michael@0 71 Initialize an empty, non-pending deferred_cb.
michael@0 72
michael@0 73 @param deferred The deferred_cb structure to initialize.
michael@0 74 @param cb The function to run when the deferred_cb executes.
michael@0 75 @param arg The function's second argument.
michael@0 76 */
michael@0 77 void event_deferred_cb_init(struct deferred_cb *, deferred_cb_fn, void *);
michael@0 78 /**
michael@0 79 Cancel a deferred_cb if it is currently scheduled in an event_base.
michael@0 80 */
michael@0 81 void event_deferred_cb_cancel(struct deferred_cb_queue *, struct deferred_cb *);
michael@0 82 /**
michael@0 83 Activate a deferred_cb if it is not currently scheduled in an event_base.
michael@0 84 */
michael@0 85 void event_deferred_cb_schedule(struct deferred_cb_queue *, struct deferred_cb *);
michael@0 86
michael@0 87 #define LOCK_DEFERRED_QUEUE(q) \
michael@0 88 EVLOCK_LOCK((q)->lock, 0)
michael@0 89 #define UNLOCK_DEFERRED_QUEUE(q) \
michael@0 90 EVLOCK_UNLOCK((q)->lock, 0)
michael@0 91
michael@0 92 #ifdef __cplusplus
michael@0 93 }
michael@0 94 #endif
michael@0 95
michael@0 96 void event_deferred_cb_queue_init(struct deferred_cb_queue *);
michael@0 97 struct deferred_cb_queue *event_base_get_deferred_cb_queue(struct event_base *);
michael@0 98
michael@0 99 #endif /* _EVENT_INTERNAL_H_ */
michael@0 100

mercurial