blob: 81dff85d40268a1080cbd4446954f67e0df57970 [file] [log] [blame]
Craig Tiller5842a5b2016-05-02 12:38:57 -07001/*
2 *
Craig Tillerad3c8c12016-05-02 21:47:30 -07003 * Copyright 2016, Google Inc.
Craig Tiller5842a5b2016-05-02 12:38:57 -07004 * 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 Tillerece4aaf2016-07-07 22:35:23 -070034#ifndef GRPC_CORE_LIB_IOMGR_COMBINER_H
35#define GRPC_CORE_LIB_IOMGR_COMBINER_H
Craig Tiller5842a5b2016-05-02 12:38:57 -070036
Craig Tillera26637f2016-05-02 13:36:36 -070037#include <stddef.h>
38
39#include <grpc/support/atm.h>
40#include "src/core/lib/iomgr/exec_ctx.h"
Craig Tillere4942952016-05-02 21:50:44 -070041#include "src/core/lib/support/mpscq.h"
Craig Tillera26637f2016-05-02 13:36:36 -070042
Craig Tillera729f602016-05-02 22:24:32 -070043// Provides serialized access to some resource.
Craig Tillerf6b6d292016-09-02 09:27:26 -070044// Each action queued on a combiner is executed serially in a borrowed thread.
Craig Tillera729f602016-05-02 22:24:32 -070045// The actual thread executing actions may change over time (but there will only
46// every be one at a time).
47
Craig Tillera729f602016-05-02 22:24:32 -070048// Initialize the lock, with an optional workqueue to shift load to when
49// necessary
Craig Tillerf7cade12016-07-07 21:41:10 -070050grpc_combiner *grpc_combiner_create(grpc_workqueue *optional_workqueue);
Craig Tillera729f602016-05-02 22:24:32 -070051// Destroy the lock
Craig Tillere0221ff2016-07-11 15:56:08 -070052void grpc_combiner_destroy(grpc_exec_ctx *exec_ctx, grpc_combiner *lock);
Craig Tiller91031da2016-12-28 15:44:25 -080053// Fetch a scheduler to schedule closures against
54grpc_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.
57grpc_closure_scheduler *grpc_combiner_finally_scheduler(grpc_combiner *lock,
58 bool covered_by_poller);
Craig Tiller5842a5b2016-05-02 12:38:57 -070059
Craig Tillerdfd3a8f2016-08-24 09:43:45 -070060bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx *exec_ctx);
61
Craig Tillerc3df7b42016-07-18 15:51:26 -070062extern int grpc_combiner_trace;
63
Craig Tillerece4aaf2016-07-07 22:35:23 -070064#endif /* GRPC_CORE_LIB_IOMGR_COMBINER_H */