blob: 371b0f55dcae0e941a90e1bff562cfafa5831ade [file] [log] [blame]
Craig Tiller73b66062015-09-09 09:34:46 -07001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tiller73b66062015-09-09 09:34:46 -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 Tiller9a4dddd2016-03-25 17:08:13 -070034#ifndef GRPC_CORE_LIB_IOMGR_WORKQUEUE_H
35#define GRPC_CORE_LIB_IOMGR_WORKQUEUE_H
Craig Tiller73b66062015-09-09 09:34:46 -070036
Craig Tiller9533d042016-03-25 17:11:06 -070037#include "src/core/lib/iomgr/closure.h"
38#include "src/core/lib/iomgr/exec_ctx.h"
39#include "src/core/lib/iomgr/iomgr.h"
40#include "src/core/lib/iomgr/pollset.h"
Craig Tiller13d455e2016-05-27 12:06:34 -070041#include "src/core/lib/iomgr/pollset_set.h"
murgatroid9954070892016-08-08 17:01:18 -070042#include "src/core/lib/iomgr/port.h"
Craig Tiller73b66062015-09-09 09:34:46 -070043
Yuchen Zeng12dfdc32016-04-26 22:05:41 -070044#ifdef GPR_WINDOWS
Craig Tiller9533d042016-03-25 17:11:06 -070045#include "src/core/lib/iomgr/workqueue_windows.h"
Craig Tiller73b66062015-09-09 09:34:46 -070046#endif
47
Craig Tiller6c396862016-01-28 13:53:40 -080048/* grpc_workqueue is forward declared in exec_ctx.h */
Craig Tiller73b66062015-09-09 09:34:46 -070049
Craig Tiller706f5bb2016-07-13 20:32:23 -070050/* Reference counting functions. Use the macro's always
51 (GRPC_WORKQUEUE_{REF,UNREF}).
52
53 Pass in a descriptive reason string for reffing/unreffing as the last
54 argument to each macro. When GRPC_WORKQUEUE_REFCOUNT_DEBUG is defined, that
55 string will be printed alongside the refcount. When it is not defined, the
56 string will be discarded at compilation time. */
57
Craig Tiller39cfffa2016-09-10 10:00:17 -070058/*#define GRPC_WORKQUEUE_REFCOUNT_DEBUG*/
Craig Tiller3cd6a512015-09-16 16:15:47 -070059#ifdef GRPC_WORKQUEUE_REFCOUNT_DEBUG
60#define GRPC_WORKQUEUE_REF(p, r) \
Craig Tiller0b834b32016-09-07 14:03:29 -070061 grpc_workqueue_ref((p), __FILE__, __LINE__, (r))
Craig Tiller706f5bb2016-07-13 20:32:23 -070062#define GRPC_WORKQUEUE_UNREF(exec_ctx, p, r) \
63 grpc_workqueue_unref((exec_ctx), (p), __FILE__, __LINE__, (r))
Craig Tiller0b834b32016-09-07 14:03:29 -070064grpc_workqueue *grpc_workqueue_ref(grpc_workqueue *workqueue, const char *file,
65 int line, const char *reason);
Craig Tillera82950e2015-09-22 12:33:20 -070066void grpc_workqueue_unref(grpc_exec_ctx *exec_ctx, grpc_workqueue *workqueue,
67 const char *file, int line, const char *reason);
Craig Tiller3cd6a512015-09-16 16:15:47 -070068#else
Craig Tiller0b834b32016-09-07 14:03:29 -070069#define GRPC_WORKQUEUE_REF(p, r) grpc_workqueue_ref((p))
Craig Tiller8af4c332015-09-22 12:32:31 -070070#define GRPC_WORKQUEUE_UNREF(cl, p, r) grpc_workqueue_unref((cl), (p))
Craig Tiller0b834b32016-09-07 14:03:29 -070071grpc_workqueue *grpc_workqueue_ref(grpc_workqueue *workqueue);
Craig Tillera82950e2015-09-22 12:33:20 -070072void grpc_workqueue_unref(grpc_exec_ctx *exec_ctx, grpc_workqueue *workqueue);
Craig Tiller3cd6a512015-09-16 16:15:47 -070073#endif
Craig Tiller73b66062015-09-09 09:34:46 -070074
Craig Tiller91031da2016-12-28 15:44:25 -080075/** Fetch the workqueue closure scheduler. Items added to a work queue will be
76 started in approximately the order they were enqueued, on some thread that
77 may or may not be the current thread. Successive closures enqueued onto a
78 workqueue MAY be executed concurrently.
Craig Tiller5d0c1f02016-07-13 20:13:19 -070079
80 It is generally more expensive to add a closure to a workqueue than to the
81 execution context, both in terms of CPU work and in execution latency.
82
83 Use work queues when it's important that other threads be given a chance to
84 tackle some workload. */
Craig Tiller91031da2016-12-28 15:44:25 -080085grpc_closure_scheduler *grpc_workqueue_scheduler(grpc_workqueue *workqueue);
Craig Tiller73b66062015-09-09 09:34:46 -070086
Craig Tiller9a4dddd2016-03-25 17:08:13 -070087#endif /* GRPC_CORE_LIB_IOMGR_WORKQUEUE_H */