示例#1
0
文件: server.c 项目: PiotrSikora/grpc
static void server_delete(grpc_exec_ctx *exec_ctx, grpc_server *server) {
  registered_method *rm;
  size_t i;
  grpc_channel_args_destroy(server->channel_args);
  gpr_mu_destroy(&server->mu_global);
  gpr_mu_destroy(&server->mu_call);
  while ((rm = server->registered_methods) != NULL) {
    server->registered_methods = rm->next;
    if (server->started) {
      request_matcher_destroy(&rm->request_matcher);
    }
    gpr_free(rm->method);
    gpr_free(rm->host);
    gpr_free(rm);
  }
  if (server->started) {
    request_matcher_destroy(&server->unregistered_request_matcher);
  }
  for (i = 0; i < server->cq_count; i++) {
    GRPC_CQ_INTERNAL_UNREF(server->cqs[i], "server");
    if (server->started) {
      gpr_stack_lockfree_destroy(server->request_freelist_per_cq[i]);
      gpr_free(server->requested_calls_per_cq[i]);
    }
  }
  gpr_free(server->request_freelist_per_cq);
  gpr_free(server->requested_calls_per_cq);
  gpr_free(server->cqs);
  gpr_free(server->pollsets);
  gpr_free(server->shutdown_tags);
  gpr_free(server);
}
示例#2
0
文件: server.c 项目: PiotrSikora/grpc
static void request_matcher_destroy(request_matcher *rm) {
  for (size_t i = 0; i < rm->server->cq_count; i++) {
    GPR_ASSERT(gpr_stack_lockfree_pop(rm->requests_per_cq[i]) == -1);
    gpr_stack_lockfree_destroy(rm->requests_per_cq[i]);
  }
  gpr_free(rm->requests_per_cq);
}
示例#3
0
static void test_serial_sized(int size) {
  gpr_stack_lockfree *stack = gpr_stack_lockfree_create(size);
  int i;

  /* First try popping empty */
  GPR_ASSERT(gpr_stack_lockfree_pop(stack) == -1);

  /* Now add one item and check it */
  gpr_stack_lockfree_push(stack, 3);
  GPR_ASSERT(gpr_stack_lockfree_pop(stack) == 3);
  GPR_ASSERT(gpr_stack_lockfree_pop(stack) == -1);

  /* Now add repeatedly more items and check them */
  for (i = 1; i < size; i *= 2) {
    int j;
    for (j = 0; j <= i; j++) {
      GPR_ASSERT(gpr_stack_lockfree_push(stack, j) == (j == 0));
    }
    for (j = 0; j <= i; j++) {
      GPR_ASSERT(gpr_stack_lockfree_pop(stack) == i - j);
    }
    GPR_ASSERT(gpr_stack_lockfree_pop(stack) == -1);
  }

  gpr_stack_lockfree_destroy(stack);
}
示例#4
0
static void test_mt_sized(int size, int nth) {
  gpr_stack_lockfree *stack;
  struct test_arg args[MAX_THREADS];
  gpr_thd_id thds[MAX_THREADS];
  int sum;
  int i;
  gpr_thd_options options = gpr_thd_options_default();

  stack = gpr_stack_lockfree_create(size);
  for (i = 0; i < nth; i++) {
    args[i].stack = stack;
    args[i].stack_size = size;
    args[i].nthreads = nth;
    args[i].rank = i;
    args[i].sum = 0;
  }
  gpr_thd_options_set_joinable(&options);
  for (i = 0; i < nth; i++) {
    GPR_ASSERT(gpr_thd_new(&thds[i], test_mt_body, &args[i], &options));
  }
  sum = 0;
  for (i = 0; i < nth; i++) {
    gpr_thd_join(thds[i]);
    sum = sum + args[i].sum;
  }
  GPR_ASSERT((unsigned)sum == ((unsigned)size * (size - 1)) / 2);
  gpr_stack_lockfree_destroy(stack);
}
示例#5
0
文件: server.c 项目: An-mol/grpc
static void request_matcher_destroy(request_matcher *rm) {
  GPR_ASSERT(gpr_stack_lockfree_pop(rm->requests) == -1);
  gpr_stack_lockfree_destroy(rm->requests);
}