Craig Tiller | 5842a5b | 2016-05-02 12:38:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | ad3c8c1 | 2016-05-02 21:47:30 -0700 | [diff] [blame] | 3 | * Copyright 2016, Google Inc. |
Craig Tiller | 5842a5b | 2016-05-02 12:38:57 -0700 | [diff] [blame] | 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 | |
Craig Tiller | ece4aaf | 2016-07-07 22:35:23 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_IOMGR_COMBINER_H |
| 35 | #define GRPC_CORE_LIB_IOMGR_COMBINER_H |
Craig Tiller | 5842a5b | 2016-05-02 12:38:57 -0700 | [diff] [blame] | 36 | |
Craig Tiller | a26637f | 2016-05-02 13:36:36 -0700 | [diff] [blame] | 37 | #include <stddef.h> |
| 38 | |
| 39 | #include <grpc/support/atm.h> |
| 40 | #include "src/core/lib/iomgr/exec_ctx.h" |
Craig Tiller | e494295 | 2016-05-02 21:50:44 -0700 | [diff] [blame] | 41 | #include "src/core/lib/support/mpscq.h" |
Craig Tiller | a26637f | 2016-05-02 13:36:36 -0700 | [diff] [blame] | 42 | |
Craig Tiller | a729f60 | 2016-05-02 22:24:32 -0700 | [diff] [blame] | 43 | // Provides serialized access to some resource. |
Craig Tiller | f6b6d29 | 2016-09-02 09:27:26 -0700 | [diff] [blame] | 44 | // Each action queued on a combiner is executed serially in a borrowed thread. |
Craig Tiller | a729f60 | 2016-05-02 22:24:32 -0700 | [diff] [blame] | 45 | // The actual thread executing actions may change over time (but there will only |
| 46 | // every be one at a time). |
| 47 | |
Craig Tiller | a729f60 | 2016-05-02 22:24:32 -0700 | [diff] [blame] | 48 | // Initialize the lock, with an optional workqueue to shift load to when |
| 49 | // necessary |
Craig Tiller | f7cade1 | 2016-07-07 21:41:10 -0700 | [diff] [blame] | 50 | grpc_combiner *grpc_combiner_create(grpc_workqueue *optional_workqueue); |
Craig Tiller | a729f60 | 2016-05-02 22:24:32 -0700 | [diff] [blame] | 51 | // Destroy the lock |
Craig Tiller | e0221ff | 2016-07-11 15:56:08 -0700 | [diff] [blame] | 52 | void grpc_combiner_destroy(grpc_exec_ctx *exec_ctx, grpc_combiner *lock); |
Craig Tiller | 91031da | 2016-12-28 15:44:25 -0800 | [diff] [blame] | 53 | // Fetch a scheduler to schedule closures against |
| 54 | grpc_closure_scheduler *grpc_combiner_scheduler(grpc_combiner *lock, |
| 55 | bool covered_by_poller); |
| 56 | // Scheduler to execute \a action within the lock just prior to unlocking. |
| 57 | grpc_closure_scheduler *grpc_combiner_finally_scheduler(grpc_combiner *lock, |
| 58 | bool covered_by_poller); |
Craig Tiller | 5842a5b | 2016-05-02 12:38:57 -0700 | [diff] [blame] | 59 | |
Craig Tiller | dfd3a8f | 2016-08-24 09:43:45 -0700 | [diff] [blame] | 60 | bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx *exec_ctx); |
| 61 | |
Craig Tiller | c3df7b4 | 2016-07-18 15:51:26 -0700 | [diff] [blame] | 62 | extern int grpc_combiner_trace; |
| 63 | |
Craig Tiller | ece4aaf | 2016-07-07 22:35:23 -0700 | [diff] [blame] | 64 | #endif /* GRPC_CORE_LIB_IOMGR_COMBINER_H */ |