Craig Tiller | 73b6606 | 2015-09-09 09:34:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 73b6606 | 2015-09-09 09:34:46 -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 | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_LIB_IOMGR_WORKQUEUE_H |
| 35 | #define GRPC_CORE_LIB_IOMGR_WORKQUEUE_H |
Craig Tiller | 73b6606 | 2015-09-09 09:34:46 -0700 | [diff] [blame] | 36 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 37 | #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 Tiller | 13d455e | 2016-05-27 12:06:34 -0700 | [diff] [blame] | 41 | #include "src/core/lib/iomgr/pollset_set.h" |
murgatroid99 | 5407089 | 2016-08-08 17:01:18 -0700 | [diff] [blame] | 42 | #include "src/core/lib/iomgr/port.h" |
Craig Tiller | 73b6606 | 2015-09-09 09:34:46 -0700 | [diff] [blame] | 43 | |
Yuchen Zeng | 12dfdc3 | 2016-04-26 22:05:41 -0700 | [diff] [blame] | 44 | #ifdef GPR_WINDOWS |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 45 | #include "src/core/lib/iomgr/workqueue_windows.h" |
Craig Tiller | 73b6606 | 2015-09-09 09:34:46 -0700 | [diff] [blame] | 46 | #endif |
| 47 | |
Craig Tiller | 6c39686 | 2016-01-28 13:53:40 -0800 | [diff] [blame] | 48 | /* grpc_workqueue is forward declared in exec_ctx.h */ |
Craig Tiller | 73b6606 | 2015-09-09 09:34:46 -0700 | [diff] [blame] | 49 | |
Craig Tiller | 706f5bb | 2016-07-13 20:32:23 -0700 | [diff] [blame] | 50 | /* 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 Tiller | 39cfffa | 2016-09-10 10:00:17 -0700 | [diff] [blame] | 58 | /*#define GRPC_WORKQUEUE_REFCOUNT_DEBUG*/ |
Craig Tiller | 3cd6a51 | 2015-09-16 16:15:47 -0700 | [diff] [blame] | 59 | #ifdef GRPC_WORKQUEUE_REFCOUNT_DEBUG |
| 60 | #define GRPC_WORKQUEUE_REF(p, r) \ |
Craig Tiller | 0b834b3 | 2016-09-07 14:03:29 -0700 | [diff] [blame] | 61 | grpc_workqueue_ref((p), __FILE__, __LINE__, (r)) |
Craig Tiller | 706f5bb | 2016-07-13 20:32:23 -0700 | [diff] [blame] | 62 | #define GRPC_WORKQUEUE_UNREF(exec_ctx, p, r) \ |
| 63 | grpc_workqueue_unref((exec_ctx), (p), __FILE__, __LINE__, (r)) |
Craig Tiller | 0b834b3 | 2016-09-07 14:03:29 -0700 | [diff] [blame] | 64 | grpc_workqueue *grpc_workqueue_ref(grpc_workqueue *workqueue, const char *file, |
| 65 | int line, const char *reason); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 66 | void grpc_workqueue_unref(grpc_exec_ctx *exec_ctx, grpc_workqueue *workqueue, |
| 67 | const char *file, int line, const char *reason); |
Craig Tiller | 3cd6a51 | 2015-09-16 16:15:47 -0700 | [diff] [blame] | 68 | #else |
Craig Tiller | 0b834b3 | 2016-09-07 14:03:29 -0700 | [diff] [blame] | 69 | #define GRPC_WORKQUEUE_REF(p, r) grpc_workqueue_ref((p)) |
Craig Tiller | 8af4c33 | 2015-09-22 12:32:31 -0700 | [diff] [blame] | 70 | #define GRPC_WORKQUEUE_UNREF(cl, p, r) grpc_workqueue_unref((cl), (p)) |
Craig Tiller | 0b834b3 | 2016-09-07 14:03:29 -0700 | [diff] [blame] | 71 | grpc_workqueue *grpc_workqueue_ref(grpc_workqueue *workqueue); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 72 | void grpc_workqueue_unref(grpc_exec_ctx *exec_ctx, grpc_workqueue *workqueue); |
Craig Tiller | 3cd6a51 | 2015-09-16 16:15:47 -0700 | [diff] [blame] | 73 | #endif |
Craig Tiller | 73b6606 | 2015-09-09 09:34:46 -0700 | [diff] [blame] | 74 | |
Craig Tiller | 91031da | 2016-12-28 15:44:25 -0800 | [diff] [blame] | 75 | /** 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 Tiller | 5d0c1f0 | 2016-07-13 20:13:19 -0700 | [diff] [blame] | 79 | |
| 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 Tiller | 91031da | 2016-12-28 15:44:25 -0800 | [diff] [blame] | 85 | grpc_closure_scheduler *grpc_workqueue_scheduler(grpc_workqueue *workqueue); |
Craig Tiller | 73b6606 | 2015-09-09 09:34:46 -0700 | [diff] [blame] | 86 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 87 | #endif /* GRPC_CORE_LIB_IOMGR_WORKQUEUE_H */ |