OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * |
| 3 * Copyright 2015-2016, 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 |
| 39 /** 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 */ |
| 56 struct grpc_exec_ctx { |
| 57 grpc_closure_list closure_list; |
| 58 }; |
| 59 |
| 60 /** A workqueue represents a list of work to be executed asynchronously. |
| 61 Forward declared here to avoid a circular dependency with workqueue.h. */ |
| 62 struct grpc_workqueue; |
| 63 typedef struct grpc_workqueue grpc_workqueue; |
| 64 |
| 65 #define GRPC_EXEC_CTX_INIT \ |
| 66 { GRPC_CLOSURE_LIST_INIT } |
| 67 |
| 68 /** Flush any work that has been enqueued onto this grpc_exec_ctx. |
| 69 * Caller must guarantee that no interfering locks are held. |
| 70 * Returns true if work was performed, false otherwise. */ |
| 71 bool grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx); |
| 72 /** Finish any pending work for a grpc_exec_ctx. Must be called before |
| 73 * the instance is destroyed, or work may be lost. */ |
| 74 void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx); |
| 75 /** Add a closure to be executed at the next flush/finish point */ |
| 76 void grpc_exec_ctx_enqueue(grpc_exec_ctx *exec_ctx, grpc_closure *closure, |
| 77 bool success, |
| 78 grpc_workqueue *offload_target_or_null); |
| 79 /** Add a list of closures to be executed at the next flush/finish point. |
| 80 * Leaves \a list empty. */ |
| 81 void grpc_exec_ctx_enqueue_list(grpc_exec_ctx *exec_ctx, |
| 82 grpc_closure_list *list, |
| 83 grpc_workqueue *offload_target_or_null); |
| 84 |
| 85 #endif |
OLD | NEW |