blob: 08c07f3baac54d2aca234cf838d1c3bf7ecbd16c [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
David Garcia Quintas3598d442016-03-15 14:53:05 -07003 * Copyright 2015-2016, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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_SURFACE_COMPLETION_QUEUE_H
35#define GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
Craig Tillerd6599a32015-09-03 09:37:02 -070037/* Internal API for completion queues */
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038
39#include <grpc/grpc.h>
Craig Tillerf40df232016-03-25 13:38:14 -070040#include "src/core/iomgr/pollset.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080041
Craig Tillera82950e2015-09-22 12:33:20 -070042typedef struct grpc_cq_completion {
Craig Tiller12cf5372015-07-09 13:48:11 -070043 /** user supplied tag */
Craig Tiller97fc6a32015-07-08 15:31:35 -070044 void *tag;
45 /** done callback - called when this queue element is no longer
46 needed by the completion queue */
Craig Tillera82950e2015-09-22 12:33:20 -070047 void (*done)(grpc_exec_ctx *exec_ctx, void *done_arg,
48 struct grpc_cq_completion *c);
Craig Tiller97fc6a32015-07-08 15:31:35 -070049 void *done_arg;
50 /** next pointer; low bit is used to indicate success or not */
Craig Tiller7536af02015-12-22 13:49:30 -080051 uintptr_t next;
Craig Tiller97fc6a32015-07-08 15:31:35 -070052} grpc_cq_completion;
53
Craig Tiller463f2372015-05-28 16:16:15 -070054#ifdef GRPC_CQ_REF_COUNT_DEBUG
Craig Tillera82950e2015-09-22 12:33:20 -070055void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason,
56 const char *file, int line);
57void grpc_cq_internal_unref(grpc_completion_queue *cc, const char *reason,
58 const char *file, int line);
Nicolas "Pixel" Nobleaaf39ab2015-06-24 23:22:53 +020059#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 Tiller463f2372015-05-28 16:16:15 -070063#else
Craig Tillera82950e2015-09-22 12:33:20 -070064void grpc_cq_internal_ref(grpc_completion_queue *cc);
65void grpc_cq_internal_unref(grpc_completion_queue *cc);
Craig Tiller463f2372015-05-28 16:16:15 -070066#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 Tiller89504612015-04-27 11:48:46 -070069
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080070/* Flag that an operation is beginning: the completion channel will not finish
Craig Tiller076f9782015-12-14 15:14:16 -080071 shutdown until a corrensponding grpc_cq_end_* call is made.
72 \a tag is currently used only in debug builds. */
Craig Tiller4bf29282015-12-14 11:25:48 -080073void grpc_cq_begin_op(grpc_completion_queue *cc, void *tag);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080074
Craig Tiller4bf29282015-12-14 11:25:48 -080075/* Queue a GRPC_OP_COMPLETED operation; tag must correspond to the tag passed to
76 grpc_cq_begin_op */
Craig Tillera82950e2015-09-22 12:33:20 -070077void 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 Tiller4ffdcd52015-01-16 11:34:55 -080082
Craig Tillera82950e2015-09-22 12:33:20 -070083grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc);
ctillerd79b4862014-12-17 16:36:59 -080084
Craig Tillera82950e2015-09-22 12:33:20 -070085void grpc_cq_mark_server_cq(grpc_completion_queue *cc);
86int grpc_cq_is_server_cq(grpc_completion_queue *cc);
Craig Tillerb56975c2015-06-15 10:11:16 -070087
Craig Tillerc7e1a2a2015-11-02 14:17:32 -080088void grpc_cq_global_init(void);
89void grpc_cq_global_shutdown(void);
90
Craig Tiller9a4dddd2016-03-25 17:08:13 -070091#endif /* GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H */