Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
David Garcia Quintas | 3598d44 | 2016-03-15 14:53:05 -0700 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [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_SURFACE_COMPLETION_QUEUE_H |
| 35 | #define GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
Craig Tiller | d6599a3 | 2015-09-03 09:37:02 -0700 | [diff] [blame] | 37 | /* Internal API for completion queues */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 38 | |
| 39 | #include <grpc/grpc.h> |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 40 | #include "src/core/lib/iomgr/pollset.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 41 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 42 | typedef struct grpc_cq_completion { |
Craig Tiller | 12cf537 | 2015-07-09 13:48:11 -0700 | [diff] [blame] | 43 | /** user supplied tag */ |
Craig Tiller | 97fc6a3 | 2015-07-08 15:31:35 -0700 | [diff] [blame] | 44 | void *tag; |
| 45 | /** done callback - called when this queue element is no longer |
| 46 | needed by the completion queue */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 47 | void (*done)(grpc_exec_ctx *exec_ctx, void *done_arg, |
| 48 | struct grpc_cq_completion *c); |
Craig Tiller | 97fc6a3 | 2015-07-08 15:31:35 -0700 | [diff] [blame] | 49 | void *done_arg; |
| 50 | /** next pointer; low bit is used to indicate success or not */ |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 51 | uintptr_t next; |
Craig Tiller | 97fc6a3 | 2015-07-08 15:31:35 -0700 | [diff] [blame] | 52 | } grpc_cq_completion; |
| 53 | |
Craig Tiller | 463f237 | 2015-05-28 16:16:15 -0700 | [diff] [blame] | 54 | #ifdef GRPC_CQ_REF_COUNT_DEBUG |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 55 | void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason, |
| 56 | const char *file, int line); |
| 57 | void grpc_cq_internal_unref(grpc_completion_queue *cc, const char *reason, |
| 58 | const char *file, int line); |
Nicolas "Pixel" Noble | aaf39ab | 2015-06-24 23:22:53 +0200 | [diff] [blame] | 59 | #define GRPC_CQ_INTERNAL_REF(cc, reason) \ |
| 60 | grpc_cq_internal_ref(cc, reason, __FILE__, __LINE__) |
| 61 | #define GRPC_CQ_INTERNAL_UNREF(cc, reason) \ |
| 62 | grpc_cq_internal_unref(cc, reason, __FILE__, __LINE__) |
Craig Tiller | 463f237 | 2015-05-28 16:16:15 -0700 | [diff] [blame] | 63 | #else |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 64 | void grpc_cq_internal_ref(grpc_completion_queue *cc); |
| 65 | void grpc_cq_internal_unref(grpc_completion_queue *cc); |
Craig Tiller | 463f237 | 2015-05-28 16:16:15 -0700 | [diff] [blame] | 66 | #define GRPC_CQ_INTERNAL_REF(cc, reason) grpc_cq_internal_ref(cc) |
| 67 | #define GRPC_CQ_INTERNAL_UNREF(cc, reason) grpc_cq_internal_unref(cc) |
| 68 | #endif |
Craig Tiller | 8950461 | 2015-04-27 11:48:46 -0700 | [diff] [blame] | 69 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 70 | /* Flag that an operation is beginning: the completion channel will not finish |
Craig Tiller | 076f978 | 2015-12-14 15:14:16 -0800 | [diff] [blame] | 71 | shutdown until a corrensponding grpc_cq_end_* call is made. |
| 72 | \a tag is currently used only in debug builds. */ |
Craig Tiller | 4bf2928 | 2015-12-14 11:25:48 -0800 | [diff] [blame] | 73 | void grpc_cq_begin_op(grpc_completion_queue *cc, void *tag); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 74 | |
Craig Tiller | 4bf2928 | 2015-12-14 11:25:48 -0800 | [diff] [blame] | 75 | /* Queue a GRPC_OP_COMPLETED operation; tag must correspond to the tag passed to |
| 76 | grpc_cq_begin_op */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 77 | void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, |
| 78 | void *tag, int success, |
| 79 | void (*done)(grpc_exec_ctx *exec_ctx, void *done_arg, |
| 80 | grpc_cq_completion *storage), |
| 81 | void *done_arg, grpc_cq_completion *storage); |
Craig Tiller | 4ffdcd5 | 2015-01-16 11:34:55 -0800 | [diff] [blame] | 82 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 83 | grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc); |
ctiller | d79b486 | 2014-12-17 16:36:59 -0800 | [diff] [blame] | 84 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 85 | void grpc_cq_mark_server_cq(grpc_completion_queue *cc); |
| 86 | int grpc_cq_is_server_cq(grpc_completion_queue *cc); |
Craig Tiller | b56975c | 2015-06-15 10:11:16 -0700 | [diff] [blame] | 87 | |
Craig Tiller | c7e1a2a | 2015-11-02 14:17:32 -0800 | [diff] [blame] | 88 | void grpc_cq_global_init(void); |
| 89 | void grpc_cq_global_shutdown(void); |
| 90 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 91 | #endif /* GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H */ |