blob: bfa08c41dd774e85862030a627dfd81f49be7bf2 [file] [log] [blame]
Craig Tiller298751c2015-09-22 09:41:05 -07001/*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#ifndef GRPC_INTERNAL_CORE_IOMGR_EXEC_CTX_H
35#define GRPC_INTERNAL_CORE_IOMGR_EXEC_CTX_H
36
37#include "src/core/iomgr/closure.h"
38
Craig Tiller8b52f852015-09-22 16:38:57 -070039/** Execution context.
40 * A bag of data that collects information along a callstack.
41 * Generally created at public API entry points, and passed down as
42 * pointer to child functions that manipulate it.
43 *
44 * Specific responsibilities (this may grow in the future):
45 * - track a list of work that needs to be delayed until the top of the
46 * call stack (this provides a convenient mechanism to run callbacks
47 * without worrying about locking issues)
48 *
49 * CONVENTIONS:
50 * Instance of this must ALWAYS be constructed on the stack, never
51 * heap allocated. Instances and pointers to them must always be called
52 * exec_ctx. Instances are always passed as the first argument
53 * to a function that takes it, and always as a pointer (grpc_exec_ctx
54 * is never copied).
55 */
Craig Tiller8af4c332015-09-22 12:32:31 -070056struct grpc_exec_ctx {
57 grpc_closure_list closure_list;
58};
59
Craig Tillera82950e2015-09-22 12:33:20 -070060#define GRPC_EXEC_CTX_INIT \
61 { GRPC_CLOSURE_LIST_INIT }
Craig Tiller8af4c332015-09-22 12:32:31 -070062
Craig Tiller8b52f852015-09-22 16:38:57 -070063/** Flush any work that has been enqueued onto this grpc_exec_ctx.
64 * Caller must guarantee that no interfering locks are held. */
Craig Tiller8af4c332015-09-22 12:32:31 -070065void grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx);
Craig Tiller8b52f852015-09-22 16:38:57 -070066/** Finish any pending work for a grpc_exec_ctx. Must be called before
67 * the instance is destroyed, or work may be lost. */
68void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx);
69/** Add a closure to be executed at the next flush/finish point */
Craig Tillera82950e2015-09-22 12:33:20 -070070void grpc_exec_ctx_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
71 int success);
Craig Tiller8b52f852015-09-22 16:38:57 -070072/** Add a list of closures to be executed at the next flush/finish point.
73 * Leaves \a list empty. */
Craig Tillera82950e2015-09-22 12:33:20 -070074void grpc_exec_ctx_enqueue_list(grpc_exec_ctx *exec_ctx,
75 grpc_closure_list *list);
Craig Tiller8af4c332015-09-22 12:32:31 -070076
Craig Tiller298751c2015-09-22 09:41:05 -070077#endif