aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/iomgr/closure.c
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2015-10-07 12:34:24 -0700
committerGravatar murgatroid99 <mlumish@google.com>2015-10-07 12:34:24 -0700
commit47f519ece2690352132add8e7973a6f7aa7c10a3 (patch)
treedd010c33df772f64f55fee8cdf5b97c0d2a7322c /src/core/iomgr/closure.c
parent4399679161e9f2ed072120b176f01b30a0ab7042 (diff)
parent0862bcf8d8f7759dfcce1de897d8db81fcd5d296 (diff)
Resolved merge conflicts
Diffstat (limited to 'src/core/iomgr/closure.c')
-rw-r--r--src/core/iomgr/closure.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/core/iomgr/closure.c b/src/core/iomgr/closure.c
index 3265425789..d91681990f 100644
--- a/src/core/iomgr/closure.c
+++ b/src/core/iomgr/closure.c
@@ -33,6 +33,8 @@
#include "src/core/iomgr/closure.h"
+#include <grpc/support/alloc.h>
+
void grpc_closure_init(grpc_closure *closure, grpc_iomgr_cb_func cb,
void *cb_arg) {
closure->cb = cb;
@@ -69,3 +71,25 @@ void grpc_closure_list_move(grpc_closure_list *src, grpc_closure_list *dst) {
}
src->head = src->tail = NULL;
}
+
+typedef struct {
+ grpc_iomgr_cb_func cb;
+ void *cb_arg;
+ grpc_closure wrapper;
+} wrapped_closure;
+
+static void closure_wrapper(grpc_exec_ctx *exec_ctx, void *arg, int success) {
+ wrapped_closure *wc = arg;
+ grpc_iomgr_cb_func cb = wc->cb;
+ void *cb_arg = wc->cb_arg;
+ gpr_free(wc);
+ cb(exec_ctx, cb_arg, success);
+}
+
+grpc_closure *grpc_closure_create(grpc_iomgr_cb_func cb, void *cb_arg) {
+ wrapped_closure *wc = gpr_malloc(sizeof(*wc));
+ wc->cb = cb;
+ wc->cb_arg = cb_arg;
+ grpc_closure_init(&wc->wrapper, closure_wrapper, wc);
+ return &wc->wrapper;
+}