当前位置: 首页>>代码示例>>C++>>正文


C++ GPR_MAX函数代码示例

本文整理汇总了C++中GPR_MAX函数的典型用法代码示例。如果您正苦于以下问题:C++ GPR_MAX函数的具体用法?C++ GPR_MAX怎么用?C++ GPR_MAX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GPR_MAX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: grpc_chttp2_hptbl_set_current_table_size

int grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
                                             uint32_t bytes) {
  if (tbl->current_table_bytes == bytes) {
    return 1;
  }
  if (bytes > tbl->max_bytes) {
    if (grpc_http_trace) {
      gpr_log(GPR_ERROR,
              "Attempt to make hpack table %d bytes when max is %d bytes",
              bytes, tbl->max_bytes);
    }
    return 0;
  }
  if (grpc_http_trace) {
    gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes);
  }
  while (tbl->mem_used > bytes) {
    evict1(tbl);
  }
  tbl->current_table_bytes = bytes;
  tbl->max_entries = entries_for_bytes(bytes);
  if (tbl->max_entries > tbl->cap_entries) {
    rebuild_ents(tbl, GPR_MAX(tbl->max_entries, 2 * tbl->cap_entries));
  } else if (tbl->max_entries < tbl->cap_entries / 3) {
    uint32_t new_cap = GPR_MAX(tbl->max_entries, 16u);
    if (new_cap != tbl->cap_entries) {
      rebuild_ents(tbl, new_cap);
    }
  }
  return 1;
}
开发者ID:github188,项目名称:grpc,代码行数:31,代码来源:hpack_table.c

示例2: main

int main(int argc, char **argv) {
    int four[4];
    int five[5];
    uint32_t bitset = 0;
    grpc_test_init(argc, argv);

    GPR_ASSERT(GPR_MIN(1, 2) == 1);
    GPR_ASSERT(GPR_MAX(1, 2) == 2);
    GPR_ASSERT(GPR_MIN(2, 1) == 1);
    GPR_ASSERT(GPR_MAX(2, 1) == 2);
    GPR_ASSERT(GPR_CLAMP(1, 0, 2) == 1);
    GPR_ASSERT(GPR_CLAMP(0, 0, 2) == 0);
    GPR_ASSERT(GPR_CLAMP(2, 0, 2) == 2);
    GPR_ASSERT(GPR_CLAMP(-1, 0, 2) == 0);
    GPR_ASSERT(GPR_CLAMP(3, 0, 2) == 2);
    GPR_ASSERT(GPR_ROTL((uint32_t)0x80000001, 1) == 3);
    GPR_ASSERT(GPR_ROTR((uint32_t)0x80000001, 1) == 0xc0000000);
    GPR_ASSERT(GPR_ARRAY_SIZE(four) == 4);
    GPR_ASSERT(GPR_ARRAY_SIZE(five) == 5);

    GPR_ASSERT(GPR_BITCOUNT((1u << 31) - 1) == 31);
    GPR_ASSERT(GPR_BITCOUNT(1u << 3) == 1);
    GPR_ASSERT(GPR_BITCOUNT(0) == 0);

    GPR_ASSERT(GPR_BITSET(&bitset, 3) == 8);
    GPR_ASSERT(GPR_BITCOUNT(bitset) == 1);
    GPR_ASSERT(GPR_BITGET(bitset, 3) == 1);
    GPR_ASSERT(GPR_BITSET(&bitset, 1) == 10);
    GPR_ASSERT(GPR_BITCOUNT(bitset) == 2);
    GPR_ASSERT(GPR_BITCLEAR(&bitset, 3) == 2);
    GPR_ASSERT(GPR_BITCOUNT(bitset) == 1);
    GPR_ASSERT(GPR_BITGET(bitset, 3) == 0);

    return 0;
}
开发者ID:ConfusedReality,项目名称:pkg_network_grpc,代码行数:35,代码来源:useful_test.c

示例3: recv_metadata

static void recv_metadata(grpc_call *call, grpc_metadata_batch *md) {
  grpc_linked_mdelem *l;
  grpc_metadata_array *dest;
  grpc_metadata *mdusr;
  int is_trailing;
  grpc_mdctx *mdctx = call->metadata_context;

  is_trailing = call->read_state >= READ_STATE_GOT_INITIAL_METADATA;
  for (l = md->list.head; l != NULL; l = l->next) {
    grpc_mdelem *md = l->md;
    grpc_mdstr *key = md->key;
    if (key == grpc_channel_get_status_string(call->channel)) {
      set_status_code(call, STATUS_FROM_WIRE, decode_status(md));
    } else if (key == grpc_channel_get_message_string(call->channel)) {
      set_status_details(call, STATUS_FROM_WIRE, grpc_mdstr_ref(md->value));
    } else {
      dest = &call->buffered_metadata[is_trailing];
      if (dest->count == dest->capacity) {
        dest->capacity = GPR_MAX(dest->capacity + 8, dest->capacity * 2);
        dest->metadata =
            gpr_realloc(dest->metadata, sizeof(grpc_metadata) * dest->capacity);
      }
      mdusr = &dest->metadata[dest->count++];
      mdusr->key = grpc_mdstr_as_c_string(md->key);
      mdusr->value = grpc_mdstr_as_c_string(md->value);
      mdusr->value_length = GPR_SLICE_LENGTH(md->value->slice);
      if (call->owned_metadata_count == call->owned_metadata_capacity) {
        call->owned_metadata_capacity =
            GPR_MAX(call->owned_metadata_capacity + 8,
                    call->owned_metadata_capacity * 2);
        call->owned_metadata =
            gpr_realloc(call->owned_metadata,
                        sizeof(grpc_mdelem *) * call->owned_metadata_capacity);
      }
      call->owned_metadata[call->owned_metadata_count++] = md;
      l->md = 0;
    }
  }
  if (gpr_time_cmp(md->deadline, gpr_inf_future) != 0) {
    set_deadline_alarm(call, md->deadline);
  }
  if (!is_trailing) {
    call->read_state = READ_STATE_GOT_INITIAL_METADATA;
  }

  grpc_mdctx_lock(mdctx);
  for (l = md->list.head; l; l = l->next) {
    if (l->md) grpc_mdctx_locked_mdelem_unref(mdctx, l->md);
  }
  for (l = md->garbage.head; l; l = l->next) {
    grpc_mdctx_locked_mdelem_unref(mdctx, l->md);
  }
  grpc_mdctx_unlock(mdctx);
}
开发者ID:caojiguang,项目名称:grpc,代码行数:54,代码来源:call.c

示例4: grpc_call_add_metadata_old

grpc_call_error grpc_call_add_metadata_old(grpc_call *call,
                                           grpc_metadata *metadata,
                                           gpr_uint32 flags) {
  legacy_state *ls;
  grpc_metadata *mdout;

  lock(call);
  ls = get_legacy_state(call);

  if (ls->md_out_count[ls->md_out_buffer] ==
      ls->md_out_capacity[ls->md_out_buffer]) {
    ls->md_out_capacity[ls->md_out_buffer] =
        GPR_MAX(ls->md_out_capacity[ls->md_out_buffer] * 3 / 2,
                ls->md_out_capacity[ls->md_out_buffer] + 8);
    ls->md_out[ls->md_out_buffer] = gpr_realloc(
        ls->md_out[ls->md_out_buffer],
        sizeof(grpc_metadata) * ls->md_out_capacity[ls->md_out_buffer]);
  }
  mdout = &ls->md_out[ls->md_out_buffer][ls->md_out_count[ls->md_out_buffer]++];
  mdout->key = gpr_strdup(metadata->key);
  mdout->value = gpr_malloc(metadata->value_length);
  mdout->value_length = metadata->value_length;
  memcpy((char *)mdout->value, metadata->value, metadata->value_length);

  unlock(call);

  return GRPC_CALL_OK;
}
开发者ID:qioixiy,项目名称:grpc,代码行数:28,代码来源:call.c

示例5: grpc_cq_internal_unref

void grpc_cq_internal_unref(grpc_completion_queue *cc, const char *reason,
                            const char *file, int line) {
  gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "CQ:%p unref %d -> %d %s", cc,
          (int)cc->owning_refs.count, (int)cc->owning_refs.count - 1, reason);
#else
void grpc_cq_internal_unref(grpc_completion_queue *cc) {
#endif
  if (gpr_unref(&cc->owning_refs)) {
    GPR_ASSERT(cc->completed_head.next == (uintptr_t)&cc->completed_head);
    grpc_pollset_destroy(POLLSET_FROM_CQ(cc));
#ifndef NDEBUG
    gpr_free(cc->outstanding_tags);
#endif
    gpr_free(cc);
  }
}

void grpc_cq_begin_op(grpc_completion_queue *cc, void *tag) {
#ifndef NDEBUG
  gpr_mu_lock(cc->mu);
  GPR_ASSERT(!cc->shutdown_called);
  if (cc->outstanding_tag_count == cc->outstanding_tag_capacity) {
    cc->outstanding_tag_capacity = GPR_MAX(4, 2 * cc->outstanding_tag_capacity);
    cc->outstanding_tags =
        gpr_realloc(cc->outstanding_tags, sizeof(*cc->outstanding_tags) *
                                              cc->outstanding_tag_capacity);
  }
  cc->outstanding_tags[cc->outstanding_tag_count++] = tag;
  gpr_mu_unlock(cc->mu);
#endif
  gpr_ref(&cc->pending_events);
}
开发者ID:juanmancb90,项目名称:hotdog-functions,代码行数:32,代码来源:completion_queue.c

示例6: get_final_details

static void get_final_details(grpc_call *call, grpc_ioreq_data out) {
  int i;
  for (i = 0; i < STATUS_SOURCE_COUNT; i++) {
    if (call->status[i].is_set) {
      if (call->status[i].details) {
        gpr_slice details = call->status[i].details->slice;
        size_t len = GPR_SLICE_LENGTH(details);
        if (len + 1 > *out.recv_status_details.details_capacity) {
          *out.recv_status_details.details_capacity = GPR_MAX(
              len + 1, *out.recv_status_details.details_capacity * 3 / 2);
          *out.recv_status_details.details =
              gpr_realloc(*out.recv_status_details.details,
                          *out.recv_status_details.details_capacity);
        }
        memcpy(*out.recv_status_details.details, GPR_SLICE_START_PTR(details),
               len);
        (*out.recv_status_details.details)[len] = 0;
      } else {
        goto no_details;
      }
      return;
    }
  }

no_details:
  if (0 == *out.recv_status_details.details_capacity) {
    *out.recv_status_details.details_capacity = 8;
    *out.recv_status_details.details =
        gpr_malloc(*out.recv_status_details.details_capacity);
  }
  **out.recv_status_details.details = 0;
}
开发者ID:qioixiy,项目名称:grpc,代码行数:32,代码来源:call.c

示例7: grpc_incoming_metadata_buffer_move_to_referencing_sopb

void grpc_incoming_metadata_buffer_move_to_referencing_sopb(
    grpc_chttp2_incoming_metadata_buffer *src,
    grpc_chttp2_incoming_metadata_buffer *dst, grpc_stream_op_buffer *sopb) {
  size_t delta;
  size_t i;
  dst->deadline = gpr_time_min(src->deadline, dst->deadline);

  if (src->count == 0) {
    return;
  }
  if (dst->count == 0) {
    grpc_chttp2_incoming_metadata_buffer_swap(src, dst);
    return;
  }
  delta = dst->count;
  if (dst->capacity < src->count + dst->count) {
    dst->capacity = GPR_MAX(dst->capacity * 2, src->count + dst->count);
    dst->elems = gpr_realloc(dst->elems, dst->capacity * sizeof(*dst->elems));
  }
  memcpy(dst->elems + dst->count, src->elems, src->count * sizeof(*src->elems));
  dst->count += src->count;
  for (i = 0; i < sopb->nops; i++) {
    if (sopb->ops[i].type != GRPC_OP_METADATA) continue;
    sopb->ops[i].data.metadata.list.tail =
        (void *)(delta + (gpr_intptr)sopb->ops[i].data.metadata.list.tail);
  }
  src->count = 0;
}
开发者ID:luoweisong,项目名称:grpc,代码行数:28,代码来源:incoming_metadata.c

示例8: add_sopb_headers

static void add_sopb_headers(int n, ...) {
  int i;
  grpc_metadata_batch b;
  va_list l;
  grpc_linked_mdelem *e = gpr_malloc(sizeof(*e) * n);

  grpc_metadata_batch_init(&b);

  va_start(l, n);
  for (i = 0; i < n; i++) {
    char *key = va_arg(l, char *);
    char *value = va_arg(l, char *);
    if (i) {
      e[i - 1].next = &e[i];
      e[i].prev = &e[i - 1];
    }
    e[i].md = grpc_mdelem_from_strings(g_mdctx, key, value);
  }
  e[0].prev = NULL;
  e[n - 1].next = NULL;
  va_end(l);

  b.list.head = &e[0];
  b.list.tail = &e[n - 1];

  if (cap_to_delete == num_to_delete) {
    cap_to_delete = GPR_MAX(2 * cap_to_delete, 1000);
    to_delete = gpr_realloc(to_delete, sizeof(*to_delete) * cap_to_delete);
  }
  to_delete[num_to_delete++] = e;

  grpc_sopb_add_metadata(&g_sopb, b);
}
开发者ID:alindeman,项目名称:grpc,代码行数:33,代码来源:stream_encoder_test.c

示例9: grpc_chttp2_stream_map_move_into

void grpc_chttp2_stream_map_move_into(grpc_chttp2_stream_map *src,
                                      grpc_chttp2_stream_map *dst) {
  /* if src is empty we dont need to do anything */
  if (src->count == src->free) {
    return;
  }
  /* if dst is empty we simply need to swap */
  if (dst->count == dst->free) {
    GPR_SWAP(grpc_chttp2_stream_map, *src, *dst);
    return;
  }
  /* the first element of src must be greater than the last of dst...
   * however the maps may need compacting for this property to hold */
  if (src->keys[0] <= dst->keys[dst->count - 1]) {
    src->count = compact(src->keys, src->values, src->count);
    src->free = 0;
    dst->count = compact(dst->keys, dst->values, dst->count);
    dst->free = 0;
  }
  GPR_ASSERT(src->keys[0] > dst->keys[dst->count - 1]);
  /* if dst doesn't have capacity, resize */
  if (dst->count + src->count > dst->capacity) {
    dst->capacity = GPR_MAX(dst->capacity * 3 / 2, dst->count + src->count);
    dst->keys = gpr_realloc(dst->keys, dst->capacity * sizeof(uint32_t));
    dst->values = gpr_realloc(dst->values, dst->capacity * sizeof(void *));
  }
  memcpy(dst->keys + dst->count, src->keys, src->count * sizeof(uint32_t));
  memcpy(dst->values + dst->count, src->values, src->count * sizeof(void *));
  dst->count += src->count;
  dst->free += src->free;
  src->count = 0;
  src->free = 0;
}
开发者ID:AlexTalks,项目名称:bazel,代码行数:33,代码来源:stream_map.c

示例10: verify

/* verify that the output generated by encoding the stream matches the
   hexstring passed in */
static void verify(size_t window_available, int eof, size_t expect_window_used,
                   const char *expected, size_t nheaders, ...) {
  grpc_slice_buffer output;
  grpc_slice merged;
  grpc_slice expect = parse_hexstring(expected);
  size_t i;
  va_list l;
  grpc_linked_mdelem *e = gpr_malloc(sizeof(*e) * nheaders);
  grpc_metadata_batch b;

  grpc_metadata_batch_init(&b);

  va_start(l, nheaders);
  for (i = 0; i < nheaders; i++) {
    char *key = va_arg(l, char *);
    char *value = va_arg(l, char *);
    if (i) {
      e[i - 1].next = &e[i];
      e[i].prev = &e[i - 1];
    }
    e[i].md = grpc_mdelem_from_strings(key, value);
  }
  e[0].prev = NULL;
  e[nheaders - 1].next = NULL;
  va_end(l);

  b.list.head = &e[0];
  b.list.tail = &e[nheaders - 1];

  if (cap_to_delete == num_to_delete) {
    cap_to_delete = GPR_MAX(2 * cap_to_delete, 1000);
    to_delete = gpr_realloc(to_delete, sizeof(*to_delete) * cap_to_delete);
  }
  to_delete[num_to_delete++] = e;

  grpc_slice_buffer_init(&output);

  grpc_transport_one_way_stats stats;
  memset(&stats, 0, sizeof(stats));
  grpc_chttp2_encode_header(&g_compressor, 0xdeadbeef, &b, eof, 16384, &stats,
                            &output);
  merged = grpc_slice_merge(output.slices, output.count);
  grpc_slice_buffer_destroy(&output);
  grpc_metadata_batch_destroy(&b);

  if (0 != grpc_slice_cmp(merged, expect)) {
    char *expect_str = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII);
    char *got_str = grpc_dump_slice(merged, GPR_DUMP_HEX | GPR_DUMP_ASCII);
    gpr_log(GPR_ERROR, "mismatched output for %s", expected);
    gpr_log(GPR_ERROR, "EXPECT: %s", expect_str);
    gpr_log(GPR_ERROR, "GOT:    %s", got_str);
    gpr_free(expect_str);
    gpr_free(got_str);
    g_failure = 1;
  }

  grpc_slice_unref(merged);
  grpc_slice_unref(expect);
}
开发者ID:izouxv,项目名称:grpc,代码行数:61,代码来源:hpack_encoder_test.c

示例11: pg_merge

static void pg_merge(grpc_exec_ctx *exec_ctx, polling_group *a,
                     polling_group *b) {
  for (;;) {
    if (a == b) {
      pg_unref(a);
      pg_unref(b);
      return;
    }
    if (a > b) GPR_SWAP(polling_group *, a, b);
    gpr_mu_lock(&a->po.mu);
    gpr_mu_lock(&b->po.mu);
    if (a->po.group != NULL) {
      polling_group *m2 = pg_ref(a->po.group);
      gpr_mu_unlock(&a->po.mu);
      gpr_mu_unlock(&b->po.mu);
      pg_unref(a);
      a = m2;
    } else if (b->po.group != NULL) {
      polling_group *m2 = pg_ref(b->po.group);
      gpr_mu_unlock(&a->po.mu);
      gpr_mu_unlock(&b->po.mu);
      pg_unref(b);
      b = m2;
    } else {
      break;
    }
  }
  polling_group **unref = NULL;
  size_t unref_count = 0;
  size_t unref_cap = 0;
  b->po.group = a;
  pg_broadcast(exec_ctx, a, b);
  pg_broadcast(exec_ctx, b, a);
  while (b->po.next != &b->po) {
    polling_obj *po = b->po.next;
    gpr_mu_lock(&po->mu);
    if (unref_count == unref_cap) {
      unref_cap = GPR_MAX(8, 3 * unref_cap / 2);
      unref = gpr_realloc(unref, unref_cap * sizeof(*unref));
    }
    unref[unref_count++] = po->group;
    po->group = pg_ref(a);
    // unlink from b
    po->prev->next = po->next;
    po->next->prev = po->prev;
    // link to a
    po->next = &a->po;
    po->prev = a->po.prev;
    po->next->prev = po->prev->next = po;
    gpr_mu_unlock(&po->mu);
  }
  gpr_mu_unlock(&a->po.mu);
  gpr_mu_unlock(&b->po.mu);
  for (size_t i = 0; i < unref_count; i++) {
    pg_unref(unref[i]);
  }
  gpr_free(unref);
  pg_unref(b);
}
开发者ID:aaronjheng,项目名称:grpc,代码行数:59,代码来源:ev_epollex_linux.c

示例12: addbuf

static void addbuf(const void *data, size_t len) {
  if (g_count + len > g_cap) {
    g_cap = GPR_MAX(g_count + len, g_cap * 2);
    g_buffer = gpr_realloc(g_buffer, g_cap);
  }
  memcpy(g_buffer + g_count, data, len);
  g_count += len;
}
开发者ID:WeiZhang555,项目名称:grpc,代码行数:8,代码来源:window_overflow.c

示例13: add_to_free

static void add_to_free(call_state *call, void *p) {
  if (call->num_to_free == call->cap_to_free) {
    call->cap_to_free = GPR_MAX(8, 2 * call->cap_to_free);
    call->to_free =
        gpr_realloc(call->to_free, sizeof(*call->to_free) * call->cap_to_free);
  }
  call->to_free[call->num_to_free++] = p;
}
开发者ID:MoCuishleHp,项目名称:grpc,代码行数:8,代码来源:api_fuzzer.c

示例14: add_header

static int add_header(grpc_http_parser *parser) {
  uint8_t *beg = parser->cur_line;
  uint8_t *cur = beg;
  uint8_t *end = beg + parser->cur_line_length;
  size_t *hdr_count = NULL;
  grpc_http_header **hdrs = NULL;
  grpc_http_header hdr = {NULL, NULL};

  GPR_ASSERT(cur != end);

  if (*cur == ' ' || *cur == '\t') {
    if (grpc_http1_trace)
      gpr_log(GPR_ERROR, "Continued header lines not supported yet");
    goto error;
  }

  while (cur != end && *cur != ':') {
    cur++;
  }
  if (cur == end) {
    if (grpc_http1_trace) {
      gpr_log(GPR_ERROR, "Didn't find ':' in header string");
    }
    goto error;
  }
  GPR_ASSERT(cur >= beg);
  hdr.key = buf2str(beg, (size_t)(cur - beg));
  cur++; /* skip : */

  while (cur != end && (*cur == ' ' || *cur == '\t')) {
    cur++;
  }
  GPR_ASSERT((size_t)(end - cur) >= parser->cur_line_end_length);
  hdr.value = buf2str(cur, (size_t)(end - cur) - parser->cur_line_end_length);

  if (parser->type == GRPC_HTTP_RESPONSE) {
    hdr_count = &parser->http.response.hdr_count;
    hdrs = &parser->http.response.hdrs;
  } else if (parser->type == GRPC_HTTP_REQUEST) {
    hdr_count = &parser->http.request.hdr_count;
    hdrs = &parser->http.request.hdrs;
  } else {
    return 0;
  }

  if (*hdr_count == parser->hdr_capacity) {
    parser->hdr_capacity =
        GPR_MAX(parser->hdr_capacity + 1, parser->hdr_capacity * 3 / 2);
    *hdrs = gpr_realloc(*hdrs, parser->hdr_capacity * sizeof(**hdrs));
  }
  (*hdrs)[(*hdr_count)++] = hdr;
  return 1;

error:
  gpr_free(hdr.key);
  gpr_free(hdr.value);
  return 0;
}
开发者ID:201528013359030,项目名称:grpc,代码行数:58,代码来源:parser.c

示例15: grpc_chttp2_incoming_metadata_buffer_add

void grpc_chttp2_incoming_metadata_buffer_add(
    grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem) {
  if (buffer->capacity == buffer->count) {
    buffer->capacity = GPR_MAX(8, 2 * buffer->capacity);
    buffer->elems =
        gpr_realloc(buffer->elems, sizeof(*buffer->elems) * buffer->capacity);
  }
  buffer->elems[buffer->count++].md = elem;
}
开发者ID:luoweisong,项目名称:grpc,代码行数:9,代码来源:incoming_metadata.c


注:本文中的GPR_MAX函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。