LCOV - code coverage report
Current view: top level - src/core/iomgr - closure.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 34 36 94.4 %
Date: 2015-10-10 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, Google Inc.
       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             : 
      34             : #include "src/core/iomgr/closure.h"
      35             : 
      36             : #include <grpc/support/alloc.h>
      37             : 
      38    15520376 : void grpc_closure_init(grpc_closure *closure, grpc_iomgr_cb_func cb,
      39             :                        void *cb_arg) {
      40    15520376 :   closure->cb = cb;
      41    15520376 :   closure->cb_arg = cb_arg;
      42    15520376 :   closure->next = NULL;
      43    15520376 : }
      44             : 
      45    31869812 : void grpc_closure_list_add(grpc_closure_list *closure_list,
      46             :                            grpc_closure *closure, int success) {
      47    63739624 :   if (closure == NULL) return;
      48    25271766 :   closure->next = NULL;
      49    25271766 :   closure->success = success;
      50    25271766 :   if (closure_list->head == NULL) {
      51    16524428 :     closure_list->head = closure;
      52             :   } else {
      53     8747338 :     closure_list->tail->next = closure;
      54             :   }
      55    25271766 :   closure_list->tail = closure;
      56             : }
      57             : 
      58    49553959 : int grpc_closure_list_empty(grpc_closure_list closure_list) {
      59    49553959 :   return closure_list.head == NULL;
      60             : }
      61             : 
      62      323142 : void grpc_closure_list_move(grpc_closure_list *src, grpc_closure_list *dst) {
      63      323142 :   if (src->head == NULL) {
      64      640600 :     return;
      65             :   }
      66        5684 :   if (dst->head == NULL) {
      67        5684 :     *dst = *src;
      68             :   } else {
      69           0 :     dst->tail->next = src->head;
      70           0 :     dst->tail = src->tail;
      71             :   }
      72        5684 :   src->head = src->tail = NULL;
      73             : }
      74             : 
      75             : typedef struct {
      76             :   grpc_iomgr_cb_func cb;
      77             :   void *cb_arg;
      78             :   grpc_closure wrapper;
      79             : } wrapped_closure;
      80             : 
      81        1354 : static void closure_wrapper(grpc_exec_ctx *exec_ctx, void *arg, int success) {
      82        1354 :   wrapped_closure *wc = arg;
      83        1354 :   grpc_iomgr_cb_func cb = wc->cb;
      84        1354 :   void *cb_arg = wc->cb_arg;
      85        1354 :   gpr_free(wc);
      86        1354 :   cb(exec_ctx, cb_arg, success);
      87        1354 : }
      88             : 
      89        1354 : grpc_closure *grpc_closure_create(grpc_iomgr_cb_func cb, void *cb_arg) {
      90        1354 :   wrapped_closure *wc = gpr_malloc(sizeof(*wc));
      91        1354 :   wc->cb = cb;
      92        1354 :   wc->cb_arg = cb_arg;
      93        1354 :   grpc_closure_init(&wc->wrapper, closure_wrapper, wc);
      94        1354 :   return &wc->wrapper;
      95             : }

Generated by: LCOV version 1.10