aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-11-09 17:46:29 -0800
committerGravatar Yash Tibrewal <yashkt@google.com>2017-11-09 17:46:29 -0800
commit4e9265c828f0b559b5fdba04913fed46bf771399 (patch)
tree4a379fc2bdc037753cf8d81f8b86327e4bc50a42 /src/core/lib/support
parent0ee7574732a06e8cace4e099a678f4bd5dbff679 (diff)
parentd9da7387b8057f3bd99a417a5ee905377bce9296 (diff)
Merge with master
Diffstat (limited to 'src/core/lib/support')
-rw-r--r--src/core/lib/support/alloc.cc30
-rw-r--r--src/core/lib/support/arena.cc22
-rw-r--r--src/core/lib/support/arena.h6
-rw-r--r--src/core/lib/support/atm.cc2
-rw-r--r--src/core/lib/support/avl.cc107
-rw-r--r--src/core/lib/support/cmdline.cc110
-rw-r--r--src/core/lib/support/env.h6
-rw-r--r--src/core/lib/support/env_linux.cc18
-rw-r--r--src/core/lib/support/env_posix.cc8
-rw-r--r--src/core/lib/support/env_windows.cc8
-rw-r--r--src/core/lib/support/histogram.cc51
-rw-r--r--src/core/lib/support/host_port.cc14
-rw-r--r--src/core/lib/support/log.cc12
-rw-r--r--src/core/lib/support/log_android.cc14
-rw-r--r--src/core/lib/support/log_linux.cc14
-rw-r--r--src/core/lib/support/log_posix.cc19
-rw-r--r--src/core/lib/support/log_windows.cc14
-rw-r--r--src/core/lib/support/memory.h41
-rw-r--r--src/core/lib/support/mpscq.cc59
-rw-r--r--src/core/lib/support/mpscq.h44
-rw-r--r--src/core/lib/support/murmur_hash.cc8
-rw-r--r--src/core/lib/support/murmur_hash.h2
-rw-r--r--src/core/lib/support/spinlock.h4
-rw-r--r--src/core/lib/support/stack_lockfree.cc16
-rw-r--r--src/core/lib/support/stack_lockfree.h8
-rw-r--r--src/core/lib/support/string.cc96
-rw-r--r--src/core/lib/support/string.h42
-rw-r--r--src/core/lib/support/string_posix.cc4
-rw-r--r--src/core/lib/support/string_util_windows.cc4
-rw-r--r--src/core/lib/support/string_windows.cc4
-rw-r--r--src/core/lib/support/subprocess_posix.cc20
-rw-r--r--src/core/lib/support/subprocess_windows.cc18
-rw-r--r--src/core/lib/support/sync.cc38
-rw-r--r--src/core/lib/support/sync_windows.cc28
-rw-r--r--src/core/lib/support/thd_posix.cc14
-rw-r--r--src/core/lib/support/thd_windows.cc20
-rw-r--r--src/core/lib/support/time_posix.cc2
-rw-r--r--src/core/lib/support/time_precise.cc8
-rw-r--r--src/core/lib/support/time_precise.h2
-rw-r--r--src/core/lib/support/tls_pthread.cc4
-rw-r--r--src/core/lib/support/tmpfile.h2
-rw-r--r--src/core/lib/support/tmpfile_msys.cc4
-rw-r--r--src/core/lib/support/tmpfile_posix.cc6
-rw-r--r--src/core/lib/support/tmpfile_windows.cc4
-rw-r--r--src/core/lib/support/vector.h32
-rw-r--r--src/core/lib/support/wrap_memcpy.cc4
46 files changed, 566 insertions, 427 deletions
diff --git a/src/core/lib/support/alloc.cc b/src/core/lib/support/alloc.cc
index 886d69d64c..aef4cb8d51 100644
--- a/src/core/lib/support/alloc.cc
+++ b/src/core/lib/support/alloc.cc
@@ -24,10 +24,10 @@
#include <string.h>
#include "src/core/lib/profiling/timers.h"
-static void *zalloc_with_calloc(size_t sz) { return calloc(sz, 1); }
+static void* zalloc_with_calloc(size_t sz) { return calloc(sz, 1); }
-static void *zalloc_with_gpr_malloc(size_t sz) {
- void *p = gpr_malloc(sz);
+static void* zalloc_with_gpr_malloc(size_t sz) {
+ void* p = gpr_malloc(sz);
memset(p, 0, sz);
return p;
}
@@ -49,8 +49,8 @@ void gpr_set_allocation_functions(gpr_allocation_functions functions) {
g_alloc_functions = functions;
}
-void *gpr_malloc(size_t size) {
- void *p;
+void* gpr_malloc(size_t size) {
+ void* p;
if (size == 0) return NULL;
GPR_TIMER_BEGIN("gpr_malloc", 0);
p = g_alloc_functions.malloc_fn(size);
@@ -61,8 +61,8 @@ void *gpr_malloc(size_t size) {
return p;
}
-void *gpr_zalloc(size_t size) {
- void *p;
+void* gpr_zalloc(size_t size) {
+ void* p;
if (size == 0) return NULL;
GPR_TIMER_BEGIN("gpr_zalloc", 0);
p = g_alloc_functions.zalloc_fn(size);
@@ -73,13 +73,13 @@ void *gpr_zalloc(size_t size) {
return p;
}
-void gpr_free(void *p) {
+void gpr_free(void* p) {
GPR_TIMER_BEGIN("gpr_free", 0);
g_alloc_functions.free_fn(p);
GPR_TIMER_END("gpr_free", 0);
}
-void *gpr_realloc(void *p, size_t size) {
+void* gpr_realloc(void* p, size_t size) {
if ((size == 0) && (p == NULL)) return NULL;
GPR_TIMER_BEGIN("gpr_realloc", 0);
p = g_alloc_functions.realloc_fn(p, size);
@@ -90,13 +90,13 @@ void *gpr_realloc(void *p, size_t size) {
return p;
}
-void *gpr_malloc_aligned(size_t size, size_t alignment_log) {
+void* gpr_malloc_aligned(size_t size, size_t alignment_log) {
size_t alignment = ((size_t)1) << alignment_log;
- size_t extra = alignment - 1 + sizeof(void *);
- void *p = gpr_malloc(size + extra);
- void **ret = (void **)(((uintptr_t)p + extra) & ~(alignment - 1));
+ size_t extra = alignment - 1 + sizeof(void*);
+ void* p = gpr_malloc(size + extra);
+ void** ret = (void**)(((uintptr_t)p + extra) & ~(alignment - 1));
ret[-1] = p;
- return (void *)ret;
+ return (void*)ret;
}
-void gpr_free_aligned(void *ptr) { gpr_free(((void **)ptr)[-1]); }
+void gpr_free_aligned(void* ptr) { gpr_free(((void**)ptr)[-1]); }
diff --git a/src/core/lib/support/arena.cc b/src/core/lib/support/arena.cc
index 9e0f73ae3d..0b37a88230 100644
--- a/src/core/lib/support/arena.cc
+++ b/src/core/lib/support/arena.cc
@@ -36,40 +36,40 @@ struct gpr_arena {
zone initial_zone;
};
-gpr_arena *gpr_arena_create(size_t initial_size) {
+gpr_arena* gpr_arena_create(size_t initial_size) {
initial_size = ROUND_UP_TO_ALIGNMENT_SIZE(initial_size);
- gpr_arena *a = (gpr_arena *)gpr_zalloc(sizeof(gpr_arena) + initial_size);
+ gpr_arena* a = (gpr_arena*)gpr_zalloc(sizeof(gpr_arena) + initial_size);
a->initial_zone.size_end = initial_size;
return a;
}
-size_t gpr_arena_destroy(gpr_arena *arena) {
+size_t gpr_arena_destroy(gpr_arena* arena) {
gpr_atm size = gpr_atm_no_barrier_load(&arena->size_so_far);
- zone *z = (zone *)gpr_atm_no_barrier_load(&arena->initial_zone.next_atm);
+ zone* z = (zone*)gpr_atm_no_barrier_load(&arena->initial_zone.next_atm);
gpr_free(arena);
while (z) {
- zone *next_z = (zone *)gpr_atm_no_barrier_load(&z->next_atm);
+ zone* next_z = (zone*)gpr_atm_no_barrier_load(&z->next_atm);
gpr_free(z);
z = next_z;
}
return (size_t)size;
}
-void *gpr_arena_alloc(gpr_arena *arena, size_t size) {
+void* gpr_arena_alloc(gpr_arena* arena, size_t size) {
size = ROUND_UP_TO_ALIGNMENT_SIZE(size);
size_t start =
(size_t)gpr_atm_no_barrier_fetch_add(&arena->size_so_far, size);
- zone *z = &arena->initial_zone;
+ zone* z = &arena->initial_zone;
while (start > z->size_end) {
- zone *next_z = (zone *)gpr_atm_acq_load(&z->next_atm);
+ zone* next_z = (zone*)gpr_atm_acq_load(&z->next_atm);
if (next_z == NULL) {
size_t next_z_size = (size_t)gpr_atm_no_barrier_load(&arena->size_so_far);
- next_z = (zone *)gpr_zalloc(sizeof(zone) + next_z_size);
+ next_z = (zone*)gpr_zalloc(sizeof(zone) + next_z_size);
next_z->size_begin = z->size_end;
next_z->size_end = z->size_end + next_z_size;
if (!gpr_atm_rel_cas(&z->next_atm, (gpr_atm)NULL, (gpr_atm)next_z)) {
gpr_free(next_z);
- next_z = (zone *)gpr_atm_acq_load(&z->next_atm);
+ next_z = (zone*)gpr_atm_acq_load(&z->next_atm);
}
}
z = next_z;
@@ -79,5 +79,5 @@ void *gpr_arena_alloc(gpr_arena *arena, size_t size) {
}
GPR_ASSERT(start >= z->size_begin);
GPR_ASSERT(start + size <= z->size_end);
- return ((char *)(z + 1)) + start - z->size_begin;
+ return ((char*)(z + 1)) + start - z->size_begin;
}
diff --git a/src/core/lib/support/arena.h b/src/core/lib/support/arena.h
index 8a50786348..4d43c56bb9 100644
--- a/src/core/lib/support/arena.h
+++ b/src/core/lib/support/arena.h
@@ -34,11 +34,11 @@ extern "C" {
typedef struct gpr_arena gpr_arena;
// Create an arena, with \a initial_size bytes in the first allocated buffer
-gpr_arena *gpr_arena_create(size_t initial_size);
+gpr_arena* gpr_arena_create(size_t initial_size);
// Allocate \a size bytes from the arena
-void *gpr_arena_alloc(gpr_arena *arena, size_t size);
+void* gpr_arena_alloc(gpr_arena* arena, size_t size);
// Destroy an arena, returning the total number of bytes allocated
-size_t gpr_arena_destroy(gpr_arena *arena);
+size_t gpr_arena_destroy(gpr_arena* arena);
#ifdef __cplusplus
}
diff --git a/src/core/lib/support/atm.cc b/src/core/lib/support/atm.cc
index 2f37d62f76..15bfe52d64 100644
--- a/src/core/lib/support/atm.cc
+++ b/src/core/lib/support/atm.cc
@@ -19,7 +19,7 @@
#include <grpc/support/atm.h>
#include <grpc/support/useful.h>
-gpr_atm gpr_atm_no_barrier_clamped_add(gpr_atm *value, gpr_atm delta,
+gpr_atm gpr_atm_no_barrier_clamped_add(gpr_atm* value, gpr_atm delta,
gpr_atm min, gpr_atm max) {
gpr_atm current_value;
gpr_atm new_value;
diff --git a/src/core/lib/support/avl.cc b/src/core/lib/support/avl.cc
index 0e28b24c98..4ba101b74a 100644
--- a/src/core/lib/support/avl.cc
+++ b/src/core/lib/support/avl.cc
@@ -25,22 +25,22 @@
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
-gpr_avl gpr_avl_create(const gpr_avl_vtable *vtable) {
+gpr_avl gpr_avl_create(const gpr_avl_vtable* vtable) {
gpr_avl out;
out.vtable = vtable;
out.root = NULL;
return out;
}
-static gpr_avl_node *ref_node(gpr_avl_node *node) {
+static gpr_avl_node* ref_node(gpr_avl_node* node) {
if (node) {
gpr_ref(&node->refs);
}
return node;
}
-static void unref_node(const gpr_avl_vtable *vtable, gpr_avl_node *node,
- void *user_data) {
+static void unref_node(const gpr_avl_vtable* vtable, gpr_avl_node* node,
+ void* user_data) {
if (node == NULL) {
return;
}
@@ -53,17 +53,18 @@ static void unref_node(const gpr_avl_vtable *vtable, gpr_avl_node *node,
}
}
-static long node_height(gpr_avl_node *node) {
+static long node_height(gpr_avl_node* node) {
return node == NULL ? 0 : node->height;
}
#ifndef NDEBUG
-static long calculate_height(gpr_avl_node *node) {
- return node == NULL ? 0 : 1 + GPR_MAX(calculate_height(node->left),
- calculate_height(node->right));
+static long calculate_height(gpr_avl_node* node) {
+ return node == NULL ? 0
+ : 1 + GPR_MAX(calculate_height(node->left),
+ calculate_height(node->right));
}
-static gpr_avl_node *assert_invariants(gpr_avl_node *n) {
+static gpr_avl_node* assert_invariants(gpr_avl_node* n) {
if (n == NULL) return NULL;
assert_invariants(n->left);
assert_invariants(n->right);
@@ -72,12 +73,12 @@ static gpr_avl_node *assert_invariants(gpr_avl_node *n) {
return n;
}
#else
-static gpr_avl_node *assert_invariants(gpr_avl_node *n) { return n; }
+static gpr_avl_node* assert_invariants(gpr_avl_node* n) { return n; }
#endif
-gpr_avl_node *new_node(void *key, void *value, gpr_avl_node *left,
- gpr_avl_node *right) {
- gpr_avl_node *node = (gpr_avl_node *)gpr_malloc(sizeof(*node));
+gpr_avl_node* new_node(void* key, void* value, gpr_avl_node* left,
+ gpr_avl_node* right) {
+ gpr_avl_node* node = (gpr_avl_node*)gpr_malloc(sizeof(*node));
gpr_ref_init(&node->refs, 1);
node->key = key;
node->value = value;
@@ -87,8 +88,8 @@ gpr_avl_node *new_node(void *key, void *value, gpr_avl_node *left,
return node;
}
-static gpr_avl_node *get(const gpr_avl_vtable *vtable, gpr_avl_node *node,
- void *key, void *user_data) {
+static gpr_avl_node* get(const gpr_avl_vtable* vtable, gpr_avl_node* node,
+ void* key, void* user_data) {
long cmp;
if (node == NULL) {
@@ -105,13 +106,13 @@ static gpr_avl_node *get(const gpr_avl_vtable *vtable, gpr_avl_node *node,
}
}
-void *gpr_avl_get(gpr_avl avl, void *key, void *user_data) {
- gpr_avl_node *node = get(avl.vtable, avl.root, key, user_data);
+void* gpr_avl_get(gpr_avl avl, void* key, void* user_data) {
+ gpr_avl_node* node = get(avl.vtable, avl.root, key, user_data);
return node ? node->value : NULL;
}
-int gpr_avl_maybe_get(gpr_avl avl, void *key, void **value, void *user_data) {
- gpr_avl_node *node = get(avl.vtable, avl.root, key, user_data);
+int gpr_avl_maybe_get(gpr_avl avl, void* key, void** value, void* user_data) {
+ gpr_avl_node* node = get(avl.vtable, avl.root, key, user_data);
if (node != NULL) {
*value = node->value;
return 1;
@@ -119,10 +120,10 @@ int gpr_avl_maybe_get(gpr_avl avl, void *key, void **value, void *user_data) {
return 0;
}
-static gpr_avl_node *rotate_left(const gpr_avl_vtable *vtable, void *key,
- void *value, gpr_avl_node *left,
- gpr_avl_node *right, void *user_data) {
- gpr_avl_node *n = new_node(vtable->copy_key(right->key, user_data),
+static gpr_avl_node* rotate_left(const gpr_avl_vtable* vtable, void* key,
+ void* value, gpr_avl_node* left,
+ gpr_avl_node* right, void* user_data) {
+ gpr_avl_node* n = new_node(vtable->copy_key(right->key, user_data),
vtable->copy_value(right->value, user_data),
new_node(key, value, left, ref_node(right->left)),
ref_node(right->right));
@@ -130,10 +131,10 @@ static gpr_avl_node *rotate_left(const gpr_avl_vtable *vtable, void *key,
return n;
}
-static gpr_avl_node *rotate_right(const gpr_avl_vtable *vtable, void *key,
- void *value, gpr_avl_node *left,
- gpr_avl_node *right, void *user_data) {
- gpr_avl_node *n =
+static gpr_avl_node* rotate_right(const gpr_avl_vtable* vtable, void* key,
+ void* value, gpr_avl_node* left,
+ gpr_avl_node* right, void* user_data) {
+ gpr_avl_node* n =
new_node(vtable->copy_key(left->key, user_data),
vtable->copy_value(left->value, user_data), ref_node(left->left),
new_node(key, value, ref_node(left->right), right));
@@ -141,11 +142,11 @@ static gpr_avl_node *rotate_right(const gpr_avl_vtable *vtable, void *key,
return n;
}
-static gpr_avl_node *rotate_left_right(const gpr_avl_vtable *vtable, void *key,
- void *value, gpr_avl_node *left,
- gpr_avl_node *right, void *user_data) {
+static gpr_avl_node* rotate_left_right(const gpr_avl_vtable* vtable, void* key,
+ void* value, gpr_avl_node* left,
+ gpr_avl_node* right, void* user_data) {
/* rotate_right(..., rotate_left(left), right) */
- gpr_avl_node *n =
+ gpr_avl_node* n =
new_node(vtable->copy_key(left->right->key, user_data),
vtable->copy_value(left->right->value, user_data),
new_node(vtable->copy_key(left->key, user_data),
@@ -156,11 +157,11 @@ static gpr_avl_node *rotate_left_right(const gpr_avl_vtable *vtable, void *key,
return n;
}
-static gpr_avl_node *rotate_right_left(const gpr_avl_vtable *vtable, void *key,
- void *value, gpr_avl_node *left,
- gpr_avl_node *right, void *user_data) {
+static gpr_avl_node* rotate_right_left(const gpr_avl_vtable* vtable, void* key,
+ void* value, gpr_avl_node* left,
+ gpr_avl_node* right, void* user_data) {
/* rotate_left(..., left, rotate_right(right)) */
- gpr_avl_node *n =
+ gpr_avl_node* n =
new_node(vtable->copy_key(right->left->key, user_data),
vtable->copy_value(right->left->value, user_data),
new_node(key, value, left, ref_node(right->left->left)),
@@ -171,9 +172,9 @@ static gpr_avl_node *rotate_right_left(const gpr_avl_vtable *vtable, void *key,
return n;
}
-static gpr_avl_node *rebalance(const gpr_avl_vtable *vtable, void *key,
- void *value, gpr_avl_node *left,
- gpr_avl_node *right, void *user_data) {
+static gpr_avl_node* rebalance(const gpr_avl_vtable* vtable, void* key,
+ void* value, gpr_avl_node* left,
+ gpr_avl_node* right, void* user_data) {
switch (node_height(left) - node_height(right)) {
case 2:
if (node_height(left->left) - node_height(left->right) == -1) {
@@ -196,8 +197,8 @@ static gpr_avl_node *rebalance(const gpr_avl_vtable *vtable, void *key,
}
}
-static gpr_avl_node *add_key(const gpr_avl_vtable *vtable, gpr_avl_node *node,
- void *key, void *value, void *user_data) {
+static gpr_avl_node* add_key(const gpr_avl_vtable* vtable, gpr_avl_node* node,
+ void* key, void* value, void* user_data) {
long cmp;
if (node == NULL) {
return new_node(key, value, NULL, NULL);
@@ -218,31 +219,31 @@ static gpr_avl_node *add_key(const gpr_avl_vtable *vtable, gpr_avl_node *node,
}
}
-gpr_avl gpr_avl_add(gpr_avl avl, void *key, void *value, void *user_data) {
- gpr_avl_node *old_root = avl.root;
+gpr_avl gpr_avl_add(gpr_avl avl, void* key, void* value, void* user_data) {
+ gpr_avl_node* old_root = avl.root;
avl.root = add_key(avl.vtable, avl.root, key, value, user_data);
assert_invariants(avl.root);
unref_node(avl.vtable, old_root, user_data);
return avl;
}
-static gpr_avl_node *in_order_head(gpr_avl_node *node) {
+static gpr_avl_node* in_order_head(gpr_avl_node* node) {
while (node->left != NULL) {
node = node->left;
}
return node;
}
-static gpr_avl_node *in_order_tail(gpr_avl_node *node) {
+static gpr_avl_node* in_order_tail(gpr_avl_node* node) {
while (node->right != NULL) {
node = node->right;
}
return node;
}
-static gpr_avl_node *remove_key(const gpr_avl_vtable *vtable,
- gpr_avl_node *node, void *key,
- void *user_data) {
+static gpr_avl_node* remove_key(const gpr_avl_vtable* vtable,
+ gpr_avl_node* node, void* key,
+ void* user_data) {
long cmp;
if (node == NULL) {
return NULL;
@@ -254,13 +255,13 @@ static gpr_avl_node *remove_key(const gpr_avl_vtable *vtable,
} else if (node->right == NULL) {
return ref_node(node->left);
} else if (node->left->height < node->right->height) {
- gpr_avl_node *h = in_order_head(node->right);
+ gpr_avl_node* h = in_order_head(node->right);
return rebalance(
vtable, vtable->copy_key(h->key, user_data),
vtable->copy_value(h->value, user_data), ref_node(node->left),
remove_key(vtable, node->right, h->key, user_data), user_data);
} else {
- gpr_avl_node *h = in_order_tail(node->left);
+ gpr_avl_node* h = in_order_tail(node->left);
return rebalance(vtable, vtable->copy_key(h->key, user_data),
vtable->copy_value(h->value, user_data),
remove_key(vtable, node->left, h->key, user_data),
@@ -279,20 +280,20 @@ static gpr_avl_node *remove_key(const gpr_avl_vtable *vtable,
}
}
-gpr_avl gpr_avl_remove(gpr_avl avl, void *key, void *user_data) {
- gpr_avl_node *old_root = avl.root;
+gpr_avl gpr_avl_remove(gpr_avl avl, void* key, void* user_data) {
+ gpr_avl_node* old_root = avl.root;
avl.root = remove_key(avl.vtable, avl.root, key, user_data);
assert_invariants(avl.root);
unref_node(avl.vtable, old_root, user_data);
return avl;
}
-gpr_avl gpr_avl_ref(gpr_avl avl, void *user_data) {
+gpr_avl gpr_avl_ref(gpr_avl avl, void* user_data) {
ref_node(avl.root);
return avl;
}
-void gpr_avl_unref(gpr_avl avl, void *user_data) {
+void gpr_avl_unref(gpr_avl avl, void* user_data) {
unref_node(avl.vtable, avl.root, user_data);
}
diff --git a/src/core/lib/support/cmdline.cc b/src/core/lib/support/cmdline.cc
index 9fb80d4460..d2785d2f30 100644
--- a/src/core/lib/support/cmdline.cc
+++ b/src/core/lib/support/cmdline.cc
@@ -30,33 +30,33 @@
typedef enum { ARGTYPE_INT, ARGTYPE_BOOL, ARGTYPE_STRING } argtype;
typedef struct arg {
- const char *name;
- const char *help;
+ const char* name;
+ const char* help;
argtype type;
- void *value;
- struct arg *next;
+ void* value;
+ struct arg* next;
} arg;
struct gpr_cmdline {
- const char *description;
- arg *args;
- const char *argv0;
+ const char* description;
+ arg* args;
+ const char* argv0;
- const char *extra_arg_name;
- const char *extra_arg_help;
- void (*extra_arg)(void *user_data, const char *arg);
- void *extra_arg_user_data;
+ const char* extra_arg_name;
+ const char* extra_arg_help;
+ void (*extra_arg)(void* user_data, const char* arg);
+ void* extra_arg_user_data;
- int (*state)(gpr_cmdline *cl, char *arg);
- arg *cur_arg;
+ int (*state)(gpr_cmdline* cl, char* arg);
+ arg* cur_arg;
int survive_failure;
};
-static int normal_state(gpr_cmdline *cl, char *arg);
+static int normal_state(gpr_cmdline* cl, char* arg);
-gpr_cmdline *gpr_cmdline_create(const char *description) {
- gpr_cmdline *cl = (gpr_cmdline *)gpr_zalloc(sizeof(gpr_cmdline));
+gpr_cmdline* gpr_cmdline_create(const char* description) {
+ gpr_cmdline* cl = (gpr_cmdline*)gpr_zalloc(sizeof(gpr_cmdline));
cl->description = description;
cl->state = normal_state;
@@ -64,28 +64,28 @@ gpr_cmdline *gpr_cmdline_create(const char *description) {
return cl;
}
-void gpr_cmdline_set_survive_failure(gpr_cmdline *cl) {
+void gpr_cmdline_set_survive_failure(gpr_cmdline* cl) {
cl->survive_failure = 1;
}
-void gpr_cmdline_destroy(gpr_cmdline *cl) {
+void gpr_cmdline_destroy(gpr_cmdline* cl) {
while (cl->args) {
- arg *a = cl->args;
+ arg* a = cl->args;
cl->args = a->next;
gpr_free(a);
}
gpr_free(cl);
}
-static void add_arg(gpr_cmdline *cl, const char *name, const char *help,
- argtype type, void *value) {
- arg *a;
+static void add_arg(gpr_cmdline* cl, const char* name, const char* help,
+ argtype type, void* value) {
+ arg* a;
for (a = cl->args; a; a = a->next) {
GPR_ASSERT(0 != strcmp(a->name, name));
}
- a = (arg *)gpr_zalloc(sizeof(arg));
+ a = (arg*)gpr_zalloc(sizeof(arg));
a->name = name;
a->help = help;
a->type = type;
@@ -94,24 +94,24 @@ static void add_arg(gpr_cmdline *cl, const char *name, const char *help,
cl->args = a;
}
-void gpr_cmdline_add_int(gpr_cmdline *cl, const char *name, const char *help,
- int *value) {
+void gpr_cmdline_add_int(gpr_cmdline* cl, const char* name, const char* help,
+ int* value) {
add_arg(cl, name, help, ARGTYPE_INT, value);
}
-void gpr_cmdline_add_flag(gpr_cmdline *cl, const char *name, const char *help,
- int *value) {
+void gpr_cmdline_add_flag(gpr_cmdline* cl, const char* name, const char* help,
+ int* value) {
add_arg(cl, name, help, ARGTYPE_BOOL, value);
}
-void gpr_cmdline_add_string(gpr_cmdline *cl, const char *name, const char *help,
- char **value) {
+void gpr_cmdline_add_string(gpr_cmdline* cl, const char* name, const char* help,
+ const char** value) {
add_arg(cl, name, help, ARGTYPE_STRING, value);
}
void gpr_cmdline_on_extra_arg(
- gpr_cmdline *cl, const char *name, const char *help,
- void (*on_extra_arg)(void *user_data, const char *arg), void *user_data) {
+ gpr_cmdline* cl, const char* name, const char* help,
+ void (*on_extra_arg)(void* user_data, const char* arg), void* user_data) {
GPR_ASSERT(!cl->extra_arg);
GPR_ASSERT(on_extra_arg);
@@ -124,8 +124,8 @@ void gpr_cmdline_on_extra_arg(
/* recursively descend argument list, adding the last element
to s first - so that arguments are added in the order they were
added to the list by api calls */
-static void add_args_to_usage(gpr_strvec *s, arg *a) {
- char *tmp;
+static void add_args_to_usage(gpr_strvec* s, arg* a) {
+ char* tmp;
if (!a) return;
add_args_to_usage(s, a->next);
@@ -146,11 +146,11 @@ static void add_args_to_usage(gpr_strvec *s, arg *a) {
}
}
-char *gpr_cmdline_usage_string(gpr_cmdline *cl, const char *argv0) {
+char* gpr_cmdline_usage_string(gpr_cmdline* cl, const char* argv0) {
/* TODO(ctiller): make this prettier */
gpr_strvec s;
- char *tmp;
- const char *name = strrchr(argv0, '/');
+ char* tmp;
+ const char* name = strrchr(argv0, '/');
if (name) {
name++;
@@ -174,8 +174,8 @@ char *gpr_cmdline_usage_string(gpr_cmdline *cl, const char *argv0) {
return tmp;
}
-static int print_usage_and_die(gpr_cmdline *cl) {
- char *usage = gpr_cmdline_usage_string(cl, cl->argv0);
+static int print_usage_and_die(gpr_cmdline* cl) {
+ char* usage = gpr_cmdline_usage_string(cl, cl->argv0);
fprintf(stderr, "%s", usage);
gpr_free(usage);
if (!cl->survive_failure) {
@@ -184,7 +184,7 @@ static int print_usage_and_die(gpr_cmdline *cl) {
return 0;
}
-static int extra_state(gpr_cmdline *cl, char *str) {
+static int extra_state(gpr_cmdline* cl, char* str) {
if (!cl->extra_arg) {
return print_usage_and_die(cl);
}
@@ -192,8 +192,8 @@ static int extra_state(gpr_cmdline *cl, char *str) {
return 1;
}
-static arg *find_arg(gpr_cmdline *cl, char *name) {
- arg *a;
+static arg* find_arg(gpr_cmdline* cl, char* name) {
+ arg* a;
for (a = cl->args; a; a = a->next) {
if (0 == strcmp(a->name, name)) {
@@ -209,9 +209,9 @@ static arg *find_arg(gpr_cmdline *cl, char *name) {
return a;
}
-static int value_state(gpr_cmdline *cl, char *str) {
+static int value_state(gpr_cmdline* cl, char* str) {
long intval;
- char *end;
+ char* end;
GPR_ASSERT(cl->cur_arg);
@@ -223,13 +223,13 @@ static int value_state(gpr_cmdline *cl, char *str) {
cl->cur_arg->name);
return print_usage_and_die(cl);
}
- *(int *)cl->cur_arg->value = (int)intval;
+ *(int*)cl->cur_arg->value = (int)intval;
break;
case ARGTYPE_BOOL:
if (0 == strcmp(str, "1") || 0 == strcmp(str, "true")) {
- *(int *)cl->cur_arg->value = 1;
+ *(int*)cl->cur_arg->value = 1;
} else if (0 == strcmp(str, "0") || 0 == strcmp(str, "false")) {
- *(int *)cl->cur_arg->value = 0;
+ *(int*)cl->cur_arg->value = 0;
} else {
fprintf(stderr, "expected boolean, got '%s' for %s\n", str,
cl->cur_arg->name);
@@ -237,7 +237,7 @@ static int value_state(gpr_cmdline *cl, char *str) {
}
break;
case ARGTYPE_STRING:
- *(char **)cl->cur_arg->value = str;
+ *(char**)cl->cur_arg->value = str;
break;
}
@@ -245,10 +245,10 @@ static int value_state(gpr_cmdline *cl, char *str) {
return 1;
}
-static int normal_state(gpr_cmdline *cl, char *str) {
- char *eq = NULL;
- char *tmp = NULL;
- char *arg_name = NULL;
+static int normal_state(gpr_cmdline* cl, char* str) {
+ char* eq = NULL;
+ char* tmp = NULL;
+ char* arg_name = NULL;
int r = 1;
if (0 == strcmp(str, "-help") || 0 == strcmp(str, "--help") ||
@@ -281,13 +281,13 @@ static int normal_state(gpr_cmdline *cl, char *str) {
fprintf(stderr, "%s is not a flag argument\n", str);
return print_usage_and_die(cl);
}
- *(int *)cl->cur_arg->value = 0;
+ *(int*)cl->cur_arg->value = 0;
return 1; /* early out */
}
eq = strchr(str, '=');
if (eq != NULL) {
/* copy the string into a temp buffer and extract the name */
- tmp = arg_name = (char *)gpr_malloc((size_t)(eq - str + 1));
+ tmp = arg_name = (char*)gpr_malloc((size_t)(eq - str + 1));
memcpy(arg_name, str, (size_t)(eq - str));
arg_name[eq - str] = 0;
} else {
@@ -305,7 +305,7 @@ static int normal_state(gpr_cmdline *cl, char *str) {
cl->state = value_state;
} else {
/* flag parameter: just set the value */
- *(int *)cl->cur_arg->value = 1;
+ *(int*)cl->cur_arg->value = 1;
}
} else {
r = extra_state(cl, str);
@@ -315,7 +315,7 @@ static int normal_state(gpr_cmdline *cl, char *str) {
return r;
}
-int gpr_cmdline_parse(gpr_cmdline *cl, int argc, char **argv) {
+int gpr_cmdline_parse(gpr_cmdline* cl, int argc, char** argv) {
int i;
GPR_ASSERT(argc >= 1);
diff --git a/src/core/lib/support/env.h b/src/core/lib/support/env.h
index e2c012a728..f50d7bcb7a 100644
--- a/src/core/lib/support/env.h
+++ b/src/core/lib/support/env.h
@@ -31,16 +31,16 @@ extern "C" {
Returns a newly allocated string. It is the responsability of the caller to
gpr_free the return value if not NULL (which means that the environment
variable exists). */
-char *gpr_getenv(const char *name);
+char* gpr_getenv(const char* name);
/* Sets the the environment with the specified name to the specified value. */
-void gpr_setenv(const char *name, const char *value);
+void gpr_setenv(const char* name, const char* value);
/* This is a version of gpr_getenv that does not produce any output if it has to
use an insecure version of the function. It is ONLY to be used to solve the
problem in which we need to check an env variable to configure the verbosity
level of logging. So DO NOT USE THIS. */
-const char *gpr_getenv_silent(const char *name, char **dst);
+const char* gpr_getenv_silent(const char* name, char** dst);
#ifdef __cplusplus
}
diff --git a/src/core/lib/support/env_linux.cc b/src/core/lib/support/env_linux.cc
index 4c45a977ca..012ef63eff 100644
--- a/src/core/lib/support/env_linux.cc
+++ b/src/core/lib/support/env_linux.cc
@@ -38,15 +38,15 @@
#include "src/core/lib/support/string.h"
-const char *gpr_getenv_silent(const char *name, char **dst) {
- const char *insecure_func_used = NULL;
- char *result = NULL;
+const char* gpr_getenv_silent(const char* name, char** dst) {
+ const char* insecure_func_used = NULL;
+ char* result = NULL;
#if defined(GPR_BACKWARDS_COMPATIBILITY_MODE)
- typedef char *(*getenv_type)(const char *);
+ typedef char* (*getenv_type)(const char*);
static getenv_type getenv_func = NULL;
/* Check to see which getenv variant is supported (go from most
* to least secure) */
- const char *names[] = {"secure_getenv", "__secure_getenv", "getenv"};
+ const char* names[] = {"secure_getenv", "__secure_getenv", "getenv"};
for (size_t i = 0; getenv_func == NULL && i < GPR_ARRAY_SIZE(names); i++) {
getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]);
if (getenv_func != NULL && strstr(names[i], "secure") == NULL) {
@@ -64,9 +64,9 @@ const char *gpr_getenv_silent(const char *name, char **dst) {
return insecure_func_used;
}
-char *gpr_getenv(const char *name) {
- char *result = NULL;
- const char *insecure_func_used = gpr_getenv_silent(name, &result);
+char* gpr_getenv(const char* name) {
+ char* result = NULL;
+ const char* insecure_func_used = gpr_getenv_silent(name, &result);
if (insecure_func_used != NULL) {
gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used",
insecure_func_used);
@@ -74,7 +74,7 @@ char *gpr_getenv(const char *name) {
return result;
}
-void gpr_setenv(const char *name, const char *value) {
+void gpr_setenv(const char* name, const char* value) {
int res = setenv(name, value, 1);
GPR_ASSERT(res == 0);
}
diff --git a/src/core/lib/support/env_posix.cc b/src/core/lib/support/env_posix.cc
index b88822ca02..7bea31ca55 100644
--- a/src/core/lib/support/env_posix.cc
+++ b/src/core/lib/support/env_posix.cc
@@ -29,17 +29,17 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/support/string.h"
-const char *gpr_getenv_silent(const char *name, char **dst) {
+const char* gpr_getenv_silent(const char* name, char** dst) {
*dst = gpr_getenv(name);
return NULL;
}
-char *gpr_getenv(const char *name) {
- char *result = getenv(name);
+char* gpr_getenv(const char* name) {
+ char* result = getenv(name);
return result == NULL ? result : gpr_strdup(result);
}
-void gpr_setenv(const char *name, const char *value) {
+void gpr_setenv(const char* name, const char* value) {
int res = setenv(name, value, 1);
GPR_ASSERT(res == 0);
}
diff --git a/src/core/lib/support/env_windows.cc b/src/core/lib/support/env_windows.cc
index c5a25dc201..cdb1d58ccd 100644
--- a/src/core/lib/support/env_windows.cc
+++ b/src/core/lib/support/env_windows.cc
@@ -30,13 +30,13 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-const char *gpr_getenv_silent(const char *name, char **dst) {
+const char* gpr_getenv_silent(const char* name, char** dst) {
*dst = gpr_getenv(name);
return NULL;
}
-char *gpr_getenv(const char *name) {
- char *result = NULL;
+char* gpr_getenv(const char* name) {
+ char* result = NULL;
DWORD size;
LPTSTR tresult = NULL;
LPTSTR tname = gpr_char_to_tchar(name);
@@ -60,7 +60,7 @@ char *gpr_getenv(const char *name) {
return result;
}
-void gpr_setenv(const char *name, const char *value) {
+void gpr_setenv(const char* name, const char* value) {
LPTSTR tname = gpr_char_to_tchar(name);
LPTSTR tvalue = gpr_char_to_tchar(value);
BOOL res = SetEnvironmentVariable(tname, tvalue);
diff --git a/src/core/lib/support/histogram.cc b/src/core/lib/support/histogram.cc
index 6d5ead9aa6..73c821a28b 100644
--- a/src/core/lib/support/histogram.cc
+++ b/src/core/lib/support/histogram.cc
@@ -51,29 +51,29 @@ struct gpr_histogram {
/* number of buckets */
size_t num_buckets;
/* the buckets themselves */
- uint32_t *buckets;
+ uint32_t* buckets;
};
/* determine a bucket index given a value - does no bounds checking */
-static size_t bucket_for_unchecked(gpr_histogram *h, double x) {
+static size_t bucket_for_unchecked(gpr_histogram* h, double x) {
return (size_t)(log(x) * h->one_on_log_multiplier);
}
/* bounds checked version of the above */
-static size_t bucket_for(gpr_histogram *h, double x) {
+static size_t bucket_for(gpr_histogram* h, double x) {
size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 1.0, h->max_possible));
GPR_ASSERT(bucket < h->num_buckets);
return bucket;
}
/* at what value does a bucket start? */
-static double bucket_start(gpr_histogram *h, double x) {
+static double bucket_start(gpr_histogram* h, double x) {
return pow(h->multiplier, x);
}
-gpr_histogram *gpr_histogram_create(double resolution,
+gpr_histogram* gpr_histogram_create(double resolution,
double max_bucket_start) {
- gpr_histogram *h = (gpr_histogram *)gpr_malloc(sizeof(gpr_histogram));
+ gpr_histogram* h = (gpr_histogram*)gpr_malloc(sizeof(gpr_histogram));
GPR_ASSERT(resolution > 0.0);
GPR_ASSERT(max_bucket_start > resolution);
h->sum = 0.0;
@@ -87,16 +87,16 @@ gpr_histogram *gpr_histogram_create(double resolution,
h->num_buckets = bucket_for_unchecked(h, max_bucket_start) + 1;
GPR_ASSERT(h->num_buckets > 1);
GPR_ASSERT(h->num_buckets < 100000000);
- h->buckets = (uint32_t *)gpr_zalloc(sizeof(uint32_t) * h->num_buckets);
+ h->buckets = (uint32_t*)gpr_zalloc(sizeof(uint32_t) * h->num_buckets);
return h;
}
-void gpr_histogram_destroy(gpr_histogram *h) {
+void gpr_histogram_destroy(gpr_histogram* h) {
gpr_free(h->buckets);
gpr_free(h);
}
-void gpr_histogram_add(gpr_histogram *h, double x) {
+void gpr_histogram_add(gpr_histogram* h, double x) {
h->sum += x;
h->sum_of_squares += x * x;
h->count++;
@@ -109,7 +109,7 @@ void gpr_histogram_add(gpr_histogram *h, double x) {
h->buckets[bucket_for(h, x)]++;
}
-int gpr_histogram_merge(gpr_histogram *dst, const gpr_histogram *src) {
+int gpr_histogram_merge(gpr_histogram* dst, const gpr_histogram* src) {
if ((dst->num_buckets != src->num_buckets) ||
(dst->multiplier != src->multiplier)) {
/* Fail because these histograms don't match */
@@ -121,7 +121,7 @@ int gpr_histogram_merge(gpr_histogram *dst, const gpr_histogram *src) {
return 1;
}
-void gpr_histogram_merge_contents(gpr_histogram *dst, const uint32_t *data,
+void gpr_histogram_merge_contents(gpr_histogram* dst, const uint32_t* data,
size_t data_count, double min_seen,
double max_seen, double sum,
double sum_of_squares, double count) {
@@ -141,7 +141,7 @@ void gpr_histogram_merge_contents(gpr_histogram *dst, const uint32_t *data,
}
}
-static double threshold_for_count_below(gpr_histogram *h, double count_below) {
+static double threshold_for_count_below(gpr_histogram* h, double count_below) {
double count_so_far;
double lower_bound;
double upper_bound;
@@ -183,46 +183,45 @@ static double threshold_for_count_below(gpr_histogram *h, double count_below) {
should lie */
lower_bound = bucket_start(h, (double)lower_idx);
upper_bound = bucket_start(h, (double)(lower_idx + 1));
- return GPR_CLAMP(upper_bound -
- (upper_bound - lower_bound) *
- (count_so_far - count_below) /
- h->buckets[lower_idx],
+ return GPR_CLAMP(upper_bound - (upper_bound - lower_bound) *
+ (count_so_far - count_below) /
+ h->buckets[lower_idx],
h->min_seen, h->max_seen);
}
}
-double gpr_histogram_percentile(gpr_histogram *h, double percentile) {
+double gpr_histogram_percentile(gpr_histogram* h, double percentile) {
return threshold_for_count_below(h, h->count * percentile / 100.0);
}
-double gpr_histogram_mean(gpr_histogram *h) {
+double gpr_histogram_mean(gpr_histogram* h) {
GPR_ASSERT(h->count != 0);
return h->sum / h->count;
}
-double gpr_histogram_stddev(gpr_histogram *h) {
+double gpr_histogram_stddev(gpr_histogram* h) {
return sqrt(gpr_histogram_variance(h));
}
-double gpr_histogram_variance(gpr_histogram *h) {
+double gpr_histogram_variance(gpr_histogram* h) {
if (h->count == 0) return 0.0;
return (h->sum_of_squares * h->count - h->sum * h->sum) /
(h->count * h->count);
}
-double gpr_histogram_maximum(gpr_histogram *h) { return h->max_seen; }
+double gpr_histogram_maximum(gpr_histogram* h) { return h->max_seen; }
-double gpr_histogram_minimum(gpr_histogram *h) { return h->min_seen; }
+double gpr_histogram_minimum(gpr_histogram* h) { return h->min_seen; }
-double gpr_histogram_count(gpr_histogram *h) { return h->count; }
+double gpr_histogram_count(gpr_histogram* h) { return h->count; }
-double gpr_histogram_sum(gpr_histogram *h) { return h->sum; }
+double gpr_histogram_sum(gpr_histogram* h) { return h->sum; }
-double gpr_histogram_sum_of_squares(gpr_histogram *h) {
+double gpr_histogram_sum_of_squares(gpr_histogram* h) {
return h->sum_of_squares;
}
-const uint32_t *gpr_histogram_get_contents(gpr_histogram *h, size_t *size) {
+const uint32_t* gpr_histogram_get_contents(gpr_histogram* h, size_t* size) {
*size = h->num_buckets;
return h->buckets;
}
diff --git a/src/core/lib/support/host_port.cc b/src/core/lib/support/host_port.cc
index 3302e574ab..1927d5507d 100644
--- a/src/core/lib/support/host_port.cc
+++ b/src/core/lib/support/host_port.cc
@@ -25,7 +25,7 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/support/string.h"
-int gpr_join_host_port(char **out, const char *host, int port) {
+int gpr_join_host_port(char** out, const char* host, int port) {
if (host[0] != '[' && strchr(host, ':') != NULL) {
/* IPv6 literals must be enclosed in brackets. */
return gpr_asprintf(out, "[%s]:%d", host, port);
@@ -35,17 +35,17 @@ int gpr_join_host_port(char **out, const char *host, int port) {
}
}
-int gpr_split_host_port(const char *name, char **host, char **port) {
- const char *host_start;
+int gpr_split_host_port(const char* name, char** host, char** port) {
+ const char* host_start;
size_t host_len;
- const char *port_start;
+ const char* port_start;
*host = NULL;
*port = NULL;
if (name[0] == '[') {
/* Parse a bracketed host, typically an IPv6 literal. */
- const char *rbracket = strchr(name, ']');
+ const char* rbracket = strchr(name, ']');
if (rbracket == NULL) {
/* Unmatched [ */
return 0;
@@ -68,7 +68,7 @@ int gpr_split_host_port(const char *name, char **host, char **port) {
return 0;
}
} else {
- const char *colon = strchr(name, ':');
+ const char* colon = strchr(name, ':');
if (colon != NULL && strchr(colon + 1, ':') == NULL) {
/* Exactly 1 colon. Split into host:port. */
host_start = name;
@@ -83,7 +83,7 @@ int gpr_split_host_port(const char *name, char **host, char **port) {
}
/* Allocate return values. */
- *host = (char *)gpr_malloc(host_len + 1);
+ *host = (char*)gpr_malloc(host_len + 1);
memcpy(*host, host_start, host_len);
(*host)[host_len] = '\0';
diff --git a/src/core/lib/support/log.cc b/src/core/lib/support/log.cc
index 69f92e001c..2140e4bd69 100644
--- a/src/core/lib/support/log.cc
+++ b/src/core/lib/support/log.cc
@@ -27,11 +27,11 @@
#include <stdio.h>
#include <string.h>
-extern "C" void gpr_default_log(gpr_log_func_args *args);
+extern "C" void gpr_default_log(gpr_log_func_args* args);
static gpr_atm g_log_func = (gpr_atm)gpr_default_log;
static gpr_atm g_min_severity_to_print = GPR_LOG_VERBOSITY_UNSET;
-const char *gpr_log_severity_string(gpr_log_severity severity) {
+const char* gpr_log_severity_string(gpr_log_severity severity) {
switch (severity) {
case GPR_LOG_SEVERITY_DEBUG:
return "D";
@@ -43,8 +43,8 @@ const char *gpr_log_severity_string(gpr_log_severity severity) {
GPR_UNREACHABLE_CODE(return "UNKNOWN");
}
-void gpr_log_message(const char *file, int line, gpr_log_severity severity,
- const char *message) {
+void gpr_log_message(const char* file, int line, gpr_log_severity severity,
+ const char* message) {
if ((gpr_atm)severity < gpr_atm_no_barrier_load(&g_min_severity_to_print)) {
return;
}
@@ -64,8 +64,8 @@ void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print) {
}
void gpr_log_verbosity_init() {
- char *verbosity = NULL;
- const char *insecure_getenv = gpr_getenv_silent("GRPC_VERBOSITY", &verbosity);
+ char* verbosity = NULL;
+ const char* insecure_getenv = gpr_getenv_silent("GRPC_VERBOSITY", &verbosity);
gpr_atm min_severity_to_print = GPR_LOG_SEVERITY_ERROR;
if (verbosity != NULL) {
diff --git a/src/core/lib/support/log_android.cc b/src/core/lib/support/log_android.cc
index 9e8529cbac..73d24cd84d 100644
--- a/src/core/lib/support/log_android.cc
+++ b/src/core/lib/support/log_android.cc
@@ -39,9 +39,9 @@ static android_LogPriority severity_to_log_priority(gpr_log_severity severity) {
return ANDROID_LOG_DEFAULT;
}
-extern "C" void gpr_log(const char *file, int line, gpr_log_severity severity,
- const char *format, ...) {
- char *message = NULL;
+extern "C" void gpr_log(const char* file, int line, gpr_log_severity severity,
+ const char* format, ...) {
+ char* message = NULL;
va_list args;
va_start(args, format);
vasprintf(&message, format, args);
@@ -50,10 +50,10 @@ extern "C" void gpr_log(const char *file, int line, gpr_log_severity severity,
free(message);
}
-extern "C" void gpr_default_log(gpr_log_func_args *args) {
- const char *final_slash;
- const char *display_file;
- char *output = NULL;
+extern "C" void gpr_default_log(gpr_log_func_args* args) {
+ const char* final_slash;
+ const char* display_file;
+ char* output = NULL;
final_slash = strrchr(args->file, '/');
if (final_slash == NULL)
diff --git a/src/core/lib/support/log_linux.cc b/src/core/lib/support/log_linux.cc
index 0914acedf4..e9be970305 100644
--- a/src/core/lib/support/log_linux.cc
+++ b/src/core/lib/support/log_linux.cc
@@ -41,9 +41,9 @@
static long gettid(void) { return syscall(__NR_gettid); }
-void gpr_log(const char *file, int line, gpr_log_severity severity,
- const char *format, ...) {
- char *message = NULL;
+void gpr_log(const char* file, int line, gpr_log_severity severity,
+ const char* format, ...) {
+ char* message = NULL;
va_list args;
va_start(args, format);
if (vasprintf(&message, format, args) == -1) {
@@ -56,10 +56,10 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
free(message);
}
-extern "C" void gpr_default_log(gpr_log_func_args *args) {
- const char *final_slash;
- char *prefix;
- const char *display_file;
+extern "C" void gpr_default_log(gpr_log_func_args* args) {
+ const char* final_slash;
+ char* prefix;
+ const char* display_file;
char time_buffer[64];
time_t timer;
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
diff --git a/src/core/lib/support/log_posix.cc b/src/core/lib/support/log_posix.cc
index 29530c858f..e765f91390 100644
--- a/src/core/lib/support/log_posix.cc
+++ b/src/core/lib/support/log_posix.cc
@@ -27,17 +27,16 @@
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
-#include <stdio.h>
#include <string.h>
#include <time.h>
static intptr_t gettid(void) { return (intptr_t)pthread_self(); }
-void gpr_log(const char *file, int line, gpr_log_severity severity,
- const char *format, ...) {
+void gpr_log(const char* file, int line, gpr_log_severity severity,
+ const char* format, ...) {
char buf[64];
- char *allocated = NULL;
- char *message = NULL;
+ char* allocated = NULL;
+ char* message = NULL;
int ret;
va_list args;
va_start(args, format);
@@ -48,7 +47,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
} else if ((size_t)ret <= sizeof(buf) - 1) {
message = buf;
} else {
- message = allocated = (char *)gpr_malloc((size_t)ret + 1);
+ message = allocated = (char*)gpr_malloc((size_t)ret + 1);
va_start(args, format);
vsnprintf(message, (size_t)(ret + 1), format, args);
va_end(args);
@@ -57,9 +56,9 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
gpr_free(allocated);
}
-extern "C" void gpr_default_log(gpr_log_func_args *args) {
- const char *final_slash;
- const char *display_file;
+extern "C" void gpr_default_log(gpr_log_func_args* args) {
+ const char* final_slash;
+ const char* display_file;
char time_buffer[64];
time_t timer;
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
@@ -79,7 +78,7 @@ extern "C" void gpr_default_log(gpr_log_func_args *args) {
strcpy(time_buffer, "error:strftime");
}
- char *prefix;
+ char* prefix;
gpr_asprintf(&prefix, "%s%s.%09d %7tu %s:%d]",
gpr_log_severity_string(args->severity), time_buffer,
(int)(now.tv_nsec), gettid(), display_file, args->line);
diff --git a/src/core/lib/support/log_windows.cc b/src/core/lib/support/log_windows.cc
index ee52abea73..d4481791e2 100644
--- a/src/core/lib/support/log_windows.cc
+++ b/src/core/lib/support/log_windows.cc
@@ -32,9 +32,9 @@
#include "src/core/lib/support/string.h"
#include "src/core/lib/support/string_windows.h"
-void gpr_log(const char *file, int line, gpr_log_severity severity,
- const char *format, ...) {
- char *message = NULL;
+void gpr_log(const char* file, int line, gpr_log_severity severity,
+ const char* format, ...) {
+ char* message = NULL;
va_list args;
int ret;
@@ -47,7 +47,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
} else {
/* Allocate a new buffer, with space for the NUL terminator. */
size_t strp_buflen = (size_t)ret + 1;
- message = (char *)gpr_malloc(strp_buflen);
+ message = (char*)gpr_malloc(strp_buflen);
/* Print to the buffer. */
va_start(args, format);
@@ -65,9 +65,9 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
}
/* Simple starter implementation */
-extern "C" void gpr_default_log(gpr_log_func_args *args) {
- const char *final_slash;
- const char *display_file;
+extern "C" void gpr_default_log(gpr_log_func_args* args) {
+ const char* final_slash;
+ const char* display_file;
char time_buffer[64];
time_t timer;
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
diff --git a/src/core/lib/support/memory.h b/src/core/lib/support/memory.h
index dc3d32e1c2..6b336681db 100644
--- a/src/core/lib/support/memory.h
+++ b/src/core/lib/support/memory.h
@@ -21,6 +21,7 @@
#include <grpc/support/alloc.h>
+#include <limits>
#include <memory>
#include <utility>
@@ -54,6 +55,46 @@ inline UniquePtr<T> MakeUnique(Args&&... args) {
return UniquePtr<T>(New<T>(std::forward<Args>(args)...));
}
+// an allocator that uses gpr_malloc/gpr_free
+template <class T>
+class Allocator {
+ public:
+ typedef T value_type;
+ typedef T* pointer;
+ typedef const T* const_pointer;
+ typedef T& reference;
+ typedef const T& const_reference;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef std::false_type propagate_on_container_move_assignment;
+ template <class U>
+ struct rebind {
+ typedef Allocator<U> other;
+ };
+ typedef std::true_type is_always_equal;
+
+ pointer address(reference x) const { return &x; }
+ const_pointer address(const_reference x) const { return &x; }
+ pointer allocate(std::size_t n,
+ std::allocator<void>::const_pointer hint = 0) {
+ return static_cast<pointer>(gpr_malloc(n * sizeof(T)));
+ }
+ void deallocate(T* p, std::size_t n) { gpr_free(p); }
+ size_t max_size() const {
+ return std::numeric_limits<size_type>::max() / sizeof(value_type);
+ }
+ void construct(pointer p, const_reference val) { new ((void*)p) T(val); }
+ template <class U, class... Args>
+ void construct(U* p, Args&&... args) {
+ ::new ((void*)p) U(std::forward<Args>(args)...);
+ }
+ void destroy(pointer p) { p->~T(); }
+ template <class U>
+ void destroy(U* p) {
+ p->~U();
+ }
+};
+
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_SUPPORT_MEMORY_H */
diff --git a/src/core/lib/support/mpscq.cc b/src/core/lib/support/mpscq.cc
index e9f893988d..b270777d5c 100644
--- a/src/core/lib/support/mpscq.cc
+++ b/src/core/lib/support/mpscq.cc
@@ -20,32 +20,33 @@
#include <grpc/support/log.h>
-void gpr_mpscq_init(gpr_mpscq *q) {
+void gpr_mpscq_init(gpr_mpscq* q) {
gpr_atm_no_barrier_store(&q->head, (gpr_atm)&q->stub);
q->tail = &q->stub;
gpr_atm_no_barrier_store(&q->stub.next, (gpr_atm)NULL);
}
-void gpr_mpscq_destroy(gpr_mpscq *q) {
+void gpr_mpscq_destroy(gpr_mpscq* q) {
GPR_ASSERT(gpr_atm_no_barrier_load(&q->head) == (gpr_atm)&q->stub);
GPR_ASSERT(q->tail == &q->stub);
}
-void gpr_mpscq_push(gpr_mpscq *q, gpr_mpscq_node *n) {
+bool gpr_mpscq_push(gpr_mpscq* q, gpr_mpscq_node* n) {
gpr_atm_no_barrier_store(&n->next, (gpr_atm)NULL);
- gpr_mpscq_node *prev =
- (gpr_mpscq_node *)gpr_atm_full_xchg(&q->head, (gpr_atm)n);
+ gpr_mpscq_node* prev =
+ (gpr_mpscq_node*)gpr_atm_full_xchg(&q->head, (gpr_atm)n);
gpr_atm_rel_store(&prev->next, (gpr_atm)n);
+ return prev == &q->stub;
}
-gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q) {
+gpr_mpscq_node* gpr_mpscq_pop(gpr_mpscq* q) {
bool empty;
return gpr_mpscq_pop_and_check_end(q, &empty);
}
-gpr_mpscq_node *gpr_mpscq_pop_and_check_end(gpr_mpscq *q, bool *empty) {
- gpr_mpscq_node *tail = q->tail;
- gpr_mpscq_node *next = (gpr_mpscq_node *)gpr_atm_acq_load(&tail->next);
+gpr_mpscq_node* gpr_mpscq_pop_and_check_end(gpr_mpscq* q, bool* empty) {
+ gpr_mpscq_node* tail = q->tail;
+ gpr_mpscq_node* next = (gpr_mpscq_node*)gpr_atm_acq_load(&tail->next);
if (tail == &q->stub) {
// indicates the list is actually (ephemerally) empty
if (next == NULL) {
@@ -54,21 +55,21 @@ gpr_mpscq_node *gpr_mpscq_pop_and_check_end(gpr_mpscq *q, bool *empty) {
}
q->tail = next;
tail = next;
- next = (gpr_mpscq_node *)gpr_atm_acq_load(&tail->next);
+ next = (gpr_mpscq_node*)gpr_atm_acq_load(&tail->next);
}
if (next != NULL) {
*empty = false;
q->tail = next;
return tail;
}
- gpr_mpscq_node *head = (gpr_mpscq_node *)gpr_atm_acq_load(&q->head);
+ gpr_mpscq_node* head = (gpr_mpscq_node*)gpr_atm_acq_load(&q->head);
if (tail != head) {
*empty = false;
// indicates a retry is in order: we're still adding
return NULL;
}
gpr_mpscq_push(q, &q->stub);
- next = (gpr_mpscq_node *)gpr_atm_acq_load(&tail->next);
+ next = (gpr_mpscq_node*)gpr_atm_acq_load(&tail->next);
if (next != NULL) {
q->tail = next;
return tail;
@@ -77,3 +78,37 @@ gpr_mpscq_node *gpr_mpscq_pop_and_check_end(gpr_mpscq *q, bool *empty) {
*empty = false;
return NULL;
}
+
+void gpr_locked_mpscq_init(gpr_locked_mpscq* q) {
+ gpr_mpscq_init(&q->queue);
+ gpr_mu_init(&q->mu);
+}
+
+void gpr_locked_mpscq_destroy(gpr_locked_mpscq* q) {
+ gpr_mpscq_destroy(&q->queue);
+ gpr_mu_destroy(&q->mu);
+}
+
+bool gpr_locked_mpscq_push(gpr_locked_mpscq* q, gpr_mpscq_node* n) {
+ return gpr_mpscq_push(&q->queue, n);
+}
+
+gpr_mpscq_node* gpr_locked_mpscq_try_pop(gpr_locked_mpscq* q) {
+ if (gpr_mu_trylock(&q->mu)) {
+ gpr_mpscq_node* n = gpr_mpscq_pop(&q->queue);
+ gpr_mu_unlock(&q->mu);
+ return n;
+ }
+ return NULL;
+}
+
+gpr_mpscq_node* gpr_locked_mpscq_pop(gpr_locked_mpscq* q) {
+ gpr_mu_lock(&q->mu);
+ bool empty = false;
+ gpr_mpscq_node* n;
+ do {
+ n = gpr_mpscq_pop_and_check_end(&q->queue, &empty);
+ } while (n == NULL && !empty);
+ gpr_mu_unlock(&q->mu);
+ return n;
+}
diff --git a/src/core/lib/support/mpscq.h b/src/core/lib/support/mpscq.h
index ca63a044bb..fb22742050 100644
--- a/src/core/lib/support/mpscq.h
+++ b/src/core/lib/support/mpscq.h
@@ -20,6 +20,7 @@
#define GRPC_CORE_LIB_SUPPORT_MPSCQ_H
#include <grpc/support/atm.h>
+#include <grpc/support/sync.h>
#include <stdbool.h>
#include <stddef.h>
@@ -33,27 +34,56 @@ extern "C" {
// List node (include this in a data structure at the top, and add application
// fields after it - to simulate inheritance)
-typedef struct gpr_mpscq_node { gpr_atm next; } gpr_mpscq_node;
+typedef struct gpr_mpscq_node {
+ gpr_atm next;
+} gpr_mpscq_node;
// Actual queue type
typedef struct gpr_mpscq {
gpr_atm head;
// make sure head & tail don't share a cacheline
char padding[GPR_CACHELINE_SIZE];
- gpr_mpscq_node *tail;
+ gpr_mpscq_node* tail;
gpr_mpscq_node stub;
} gpr_mpscq;
-void gpr_mpscq_init(gpr_mpscq *q);
-void gpr_mpscq_destroy(gpr_mpscq *q);
+void gpr_mpscq_init(gpr_mpscq* q);
+void gpr_mpscq_destroy(gpr_mpscq* q);
// Push a node
-void gpr_mpscq_push(gpr_mpscq *q, gpr_mpscq_node *n);
+// Thread safe - can be called from multiple threads concurrently
+// Returns true if this was possibly the first node (may return true
+// sporadically, will not return false sporadically)
+bool gpr_mpscq_push(gpr_mpscq* q, gpr_mpscq_node* n);
// Pop a node (returns NULL if no node is ready - which doesn't indicate that
// the queue is empty!!)
-gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q);
+// Thread compatible - can only be called from one thread at a time
+gpr_mpscq_node* gpr_mpscq_pop(gpr_mpscq* q);
// Pop a node; sets *empty to true if the queue is empty, or false if it is not
-gpr_mpscq_node *gpr_mpscq_pop_and_check_end(gpr_mpscq *q, bool *empty);
+gpr_mpscq_node* gpr_mpscq_pop_and_check_end(gpr_mpscq* q, bool* empty);
+// An mpscq with a lock: it's safe to pop from multiple threads, but doing
+// only one thread will succeed concurrently
+typedef struct gpr_locked_mpscq {
+ gpr_mpscq queue;
+ gpr_mu mu;
+} gpr_locked_mpscq;
+
+void gpr_locked_mpscq_init(gpr_locked_mpscq* q);
+void gpr_locked_mpscq_destroy(gpr_locked_mpscq* q);
+// Push a node
+// Thread safe - can be called from multiple threads concurrently
+// Returns true if this was possibly the first node (may return true
+// sporadically, will not return false sporadically)
+bool gpr_locked_mpscq_push(gpr_locked_mpscq* q, gpr_mpscq_node* n);
+
+// Pop a node (returns NULL if no node is ready - which doesn't indicate that
+// the queue is empty!!)
+// Thread safe - can be called from multiple threads concurrently
+gpr_mpscq_node* gpr_locked_mpscq_try_pop(gpr_locked_mpscq* q);
+
+// Pop a node. Returns NULL only if the queue was empty at some point after
+// calling this function
+gpr_mpscq_node* gpr_locked_mpscq_pop(gpr_locked_mpscq* q);
#ifdef __cplusplus
}
#endif
diff --git a/src/core/lib/support/murmur_hash.cc b/src/core/lib/support/murmur_hash.cc
index f06b970de7..4e08579a1d 100644
--- a/src/core/lib/support/murmur_hash.cc
+++ b/src/core/lib/support/murmur_hash.cc
@@ -29,8 +29,8 @@
(h) *= 0xc2b2ae35; \
(h) ^= (h) >> 16;
-uint32_t gpr_murmur_hash3(const void *key, size_t len, uint32_t seed) {
- const uint8_t *data = (const uint8_t *)key;
+uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) {
+ const uint8_t* data = (const uint8_t*)key;
const size_t nblocks = len / 4;
int i;
@@ -40,8 +40,8 @@ uint32_t gpr_murmur_hash3(const void *key, size_t len, uint32_t seed) {
const uint32_t c1 = 0xcc9e2d51;
const uint32_t c2 = 0x1b873593;
- const uint32_t *blocks = ((const uint32_t *)key) + nblocks;
- const uint8_t *tail = (const uint8_t *)(data + nblocks * 4);
+ const uint32_t* blocks = ((const uint32_t*)key) + nblocks;
+ const uint8_t* tail = (const uint8_t*)(data + nblocks * 4);
/* body */
for (i = -(int)nblocks; i; i++) {
diff --git a/src/core/lib/support/murmur_hash.h b/src/core/lib/support/murmur_hash.h
index a4c642e49f..d02bba6962 100644
--- a/src/core/lib/support/murmur_hash.h
+++ b/src/core/lib/support/murmur_hash.h
@@ -28,7 +28,7 @@ extern "C" {
#endif
/* compute the hash of key (length len) */
-uint32_t gpr_murmur_hash3(const void *key, size_t len, uint32_t seed);
+uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed);
#ifdef __cplusplus
}
diff --git a/src/core/lib/support/spinlock.h b/src/core/lib/support/spinlock.h
index 47584f6279..8b439642e9 100644
--- a/src/core/lib/support/spinlock.h
+++ b/src/core/lib/support/spinlock.h
@@ -23,7 +23,9 @@
/* Simple spinlock. No backoff strategy, gpr_spinlock_lock is almost always
a concurrency code smell. */
-typedef struct { gpr_atm atm; } gpr_spinlock;
+typedef struct {
+ gpr_atm atm;
+} gpr_spinlock;
#ifdef __cplusplus
#define GPR_SPINLOCK_INITIALIZER (gpr_spinlock{0})
diff --git a/src/core/lib/support/stack_lockfree.cc b/src/core/lib/support/stack_lockfree.cc
index 0fb64ed001..7a4ede3b92 100644
--- a/src/core/lib/support/stack_lockfree.cc
+++ b/src/core/lib/support/stack_lockfree.cc
@@ -55,18 +55,18 @@ typedef union lockfree_node {
#define INVALID_ENTRY_INDEX ((1 << 16) - 1)
struct gpr_stack_lockfree {
- lockfree_node *entries;
+ lockfree_node* entries;
lockfree_node head; /* An atomic entry describing curr head */
};
-gpr_stack_lockfree *gpr_stack_lockfree_create(size_t entries) {
- gpr_stack_lockfree *stack;
- stack = (gpr_stack_lockfree *)gpr_malloc(sizeof(*stack));
+gpr_stack_lockfree* gpr_stack_lockfree_create(size_t entries) {
+ gpr_stack_lockfree* stack;
+ stack = (gpr_stack_lockfree*)gpr_malloc(sizeof(*stack));
/* Since we only allocate 16 bits to represent an entry number,
* make sure that we are within the desired range */
/* Reserve the highest entry number as a dummy */
GPR_ASSERT(entries < INVALID_ENTRY_INDEX);
- stack->entries = (lockfree_node *)gpr_malloc_aligned(
+ stack->entries = (lockfree_node*)gpr_malloc_aligned(
entries * sizeof(stack->entries[0]), ENTRY_ALIGNMENT_BITS);
/* Clear out all entries */
memset(stack->entries, 0, entries * sizeof(stack->entries[0]));
@@ -84,12 +84,12 @@ gpr_stack_lockfree *gpr_stack_lockfree_create(size_t entries) {
return stack;
}
-void gpr_stack_lockfree_destroy(gpr_stack_lockfree *stack) {
+void gpr_stack_lockfree_destroy(gpr_stack_lockfree* stack) {
gpr_free_aligned(stack->entries);
gpr_free(stack);
}
-int gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) {
+int gpr_stack_lockfree_push(gpr_stack_lockfree* stack, int entry) {
lockfree_node head;
lockfree_node newhead;
lockfree_node curent;
@@ -119,7 +119,7 @@ int gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) {
return head.contents.index == INVALID_ENTRY_INDEX;
}
-int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack) {
+int gpr_stack_lockfree_pop(gpr_stack_lockfree* stack) {
lockfree_node head;
lockfree_node newhead;
diff --git a/src/core/lib/support/stack_lockfree.h b/src/core/lib/support/stack_lockfree.h
index 706f63fbf6..337ecc2b17 100644
--- a/src/core/lib/support/stack_lockfree.h
+++ b/src/core/lib/support/stack_lockfree.h
@@ -29,15 +29,15 @@ typedef struct gpr_stack_lockfree gpr_stack_lockfree;
/* This stack must specify the maximum number of entries to track.
The current implementation only allows up to 65534 entries */
-gpr_stack_lockfree *gpr_stack_lockfree_create(size_t entries);
-void gpr_stack_lockfree_destroy(gpr_stack_lockfree *stack);
+gpr_stack_lockfree* gpr_stack_lockfree_create(size_t entries);
+void gpr_stack_lockfree_destroy(gpr_stack_lockfree* stack);
/* Pass in a valid entry number for the next stack entry */
/* Returns 1 if this is the first element on the stack, 0 otherwise */
-int gpr_stack_lockfree_push(gpr_stack_lockfree *, int entry);
+int gpr_stack_lockfree_push(gpr_stack_lockfree*, int entry);
/* Returns -1 on empty or the actual entry number */
-int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack);
+int gpr_stack_lockfree_pop(gpr_stack_lockfree* stack);
#ifdef __cplusplus
}
diff --git a/src/core/lib/support/string.cc b/src/core/lib/support/string.cc
index d55863892f..6dc4fbc921 100644
--- a/src/core/lib/support/string.cc
+++ b/src/core/lib/support/string.cc
@@ -30,8 +30,8 @@
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
-char *gpr_strdup(const char *src) {
- char *dst;
+char* gpr_strdup(const char* src) {
+ char* dst;
size_t len;
if (!src) {
@@ -39,7 +39,7 @@ char *gpr_strdup(const char *src) {
}
len = strlen(src) + 1;
- dst = (char *)gpr_malloc(len);
+ dst = (char*)gpr_malloc(len);
memcpy(dst, src, len);
@@ -49,7 +49,7 @@ char *gpr_strdup(const char *src) {
typedef struct {
size_t capacity;
size_t length;
- char *data;
+ char* data;
} dump_out;
static dump_out dump_out_create(void) {
@@ -57,20 +57,20 @@ static dump_out dump_out_create(void) {
return r;
}
-static void dump_out_append(dump_out *out, char c) {
+static void dump_out_append(dump_out* out, char c) {
if (out->length == out->capacity) {
out->capacity = GPR_MAX(8, 2 * out->capacity);
- out->data = (char *)gpr_realloc(out->data, out->capacity);
+ out->data = (char*)gpr_realloc(out->data, out->capacity);
}
out->data[out->length++] = c;
}
-static void hexdump(dump_out *out, const char *buf, size_t len) {
- static const char *hex = "0123456789abcdef";
+static void hexdump(dump_out* out, const char* buf, size_t len) {
+ static const char* hex = "0123456789abcdef";
- const uint8_t *const beg = (const uint8_t *)buf;
- const uint8_t *const end = beg + len;
- const uint8_t *cur;
+ const uint8_t* const beg = (const uint8_t*)buf;
+ const uint8_t* const end = beg + len;
+ const uint8_t* cur;
for (cur = beg; cur != end; ++cur) {
if (cur != beg) dump_out_append(out, ' ');
@@ -79,24 +79,24 @@ static void hexdump(dump_out *out, const char *buf, size_t len) {
}
}
-static void asciidump(dump_out *out, const char *buf, size_t len) {
- const uint8_t *const beg = (const uint8_t *)buf;
- const uint8_t *const end = beg + len;
- const uint8_t *cur;
+static void asciidump(dump_out* out, const char* buf, size_t len) {
+ const uint8_t* const beg = (const uint8_t*)buf;
+ const uint8_t* const end = beg + len;
+ const uint8_t* cur;
int out_was_empty = (out->length == 0);
if (!out_was_empty) {
dump_out_append(out, ' ');
dump_out_append(out, '\'');
}
for (cur = beg; cur != end; ++cur) {
- dump_out_append(out, (char)(isprint(*cur) ? *(char *)cur : '.'));
+ dump_out_append(out, (char)(isprint(*cur) ? *(char*)cur : '.'));
}
if (!out_was_empty) {
dump_out_append(out, '\'');
}
}
-char *gpr_dump(const char *buf, size_t len, uint32_t flags) {
+char* gpr_dump(const char* buf, size_t len, uint32_t flags) {
dump_out out = dump_out_create();
if (flags & GPR_DUMP_HEX) {
hexdump(&out, buf, len);
@@ -108,7 +108,7 @@ char *gpr_dump(const char *buf, size_t len, uint32_t flags) {
return out.data;
}
-int gpr_parse_bytes_to_uint32(const char *buf, size_t len, uint32_t *result) {
+int gpr_parse_bytes_to_uint32(const char* buf, size_t len, uint32_t* result) {
uint32_t out = 0;
uint32_t new_val;
size_t i;
@@ -126,7 +126,7 @@ int gpr_parse_bytes_to_uint32(const char *buf, size_t len, uint32_t *result) {
return 1;
}
-void gpr_reverse_bytes(char *str, int len) {
+void gpr_reverse_bytes(char* str, int len) {
char *p1, *p2;
for (p1 = str, p2 = str + len - 1; p2 > p1; ++p1, --p2) {
char temp = *p1;
@@ -135,7 +135,7 @@ void gpr_reverse_bytes(char *str, int len) {
}
}
-int gpr_ltoa(long value, char *string) {
+int gpr_ltoa(long value, char* string) {
long sign;
int i = 0;
@@ -156,7 +156,7 @@ int gpr_ltoa(long value, char *string) {
return i;
}
-int int64_ttoa(int64_t value, char *string) {
+int int64_ttoa(int64_t value, char* string) {
int64_t sign;
int i = 0;
@@ -177,33 +177,33 @@ int int64_ttoa(int64_t value, char *string) {
return i;
}
-int gpr_parse_nonnegative_int(const char *value) {
- char *end;
+int gpr_parse_nonnegative_int(const char* value) {
+ char* end;
long result = strtol(value, &end, 0);
if (*end != '\0' || result < 0 || result > INT_MAX) return -1;
return (int)result;
}
-char *gpr_leftpad(const char *str, char flag, size_t length) {
+char* gpr_leftpad(const char* str, char flag, size_t length) {
const size_t str_length = strlen(str);
const size_t out_length = str_length > length ? str_length : length;
- char *out = (char *)gpr_malloc(out_length + 1);
+ char* out = (char*)gpr_malloc(out_length + 1);
memset(out, flag, out_length - str_length);
memcpy(out + out_length - str_length, str, str_length);
out[out_length] = 0;
return out;
}
-char *gpr_strjoin(const char **strs, size_t nstrs, size_t *final_length) {
+char* gpr_strjoin(const char** strs, size_t nstrs, size_t* final_length) {
return gpr_strjoin_sep(strs, nstrs, "", final_length);
}
-char *gpr_strjoin_sep(const char **strs, size_t nstrs, const char *sep,
- size_t *final_length) {
+char* gpr_strjoin_sep(const char** strs, size_t nstrs, const char* sep,
+ size_t* final_length) {
const size_t sep_len = strlen(sep);
size_t out_length = 0;
size_t i;
- char *out;
+ char* out;
for (i = 0; i < nstrs; i++) {
out_length += strlen(strs[i]);
}
@@ -211,7 +211,7 @@ char *gpr_strjoin_sep(const char **strs, size_t nstrs, const char *sep,
if (nstrs > 0) {
out_length += sep_len * (nstrs - 1); /* separators */
}
- out = (char *)gpr_malloc(out_length);
+ out = (char*)gpr_malloc(out_length);
out_length = 0;
for (i = 0; i < nstrs; i++) {
const size_t slen = strlen(strs[i]);
@@ -229,9 +229,9 @@ char *gpr_strjoin_sep(const char **strs, size_t nstrs, const char *sep,
return out;
}
-void gpr_strvec_init(gpr_strvec *sv) { memset(sv, 0, sizeof(*sv)); }
+void gpr_strvec_init(gpr_strvec* sv) { memset(sv, 0, sizeof(*sv)); }
-void gpr_strvec_destroy(gpr_strvec *sv) {
+void gpr_strvec_destroy(gpr_strvec* sv) {
size_t i;
for (i = 0; i < sv->count; i++) {
gpr_free(sv->strs[i]);
@@ -239,19 +239,19 @@ void gpr_strvec_destroy(gpr_strvec *sv) {
gpr_free(sv->strs);
}
-void gpr_strvec_add(gpr_strvec *sv, char *str) {
+void gpr_strvec_add(gpr_strvec* sv, char* str) {
if (sv->count == sv->capacity) {
sv->capacity = GPR_MAX(sv->capacity + 8, sv->capacity * 2);
- sv->strs = (char **)gpr_realloc(sv->strs, sizeof(char *) * sv->capacity);
+ sv->strs = (char**)gpr_realloc(sv->strs, sizeof(char*) * sv->capacity);
}
sv->strs[sv->count++] = str;
}
-char *gpr_strvec_flatten(gpr_strvec *sv, size_t *final_length) {
- return gpr_strjoin((const char **)sv->strs, sv->count, final_length);
+char* gpr_strvec_flatten(gpr_strvec* sv, size_t* final_length) {
+ return gpr_strjoin((const char**)sv->strs, sv->count, final_length);
}
-int gpr_stricmp(const char *a, const char *b) {
+int gpr_stricmp(const char* a, const char* b) {
int ca, cb;
do {
ca = tolower(*a);
@@ -262,22 +262,22 @@ int gpr_stricmp(const char *a, const char *b) {
return ca - cb;
}
-static void add_string_to_split(const char *beg, const char *end, char ***strs,
- size_t *nstrs, size_t *capstrs) {
- char *out = (char *)gpr_malloc((size_t)(end - beg) + 1);
+static void add_string_to_split(const char* beg, const char* end, char*** strs,
+ size_t* nstrs, size_t* capstrs) {
+ char* out = (char*)gpr_malloc((size_t)(end - beg) + 1);
memcpy(out, beg, (size_t)(end - beg));
out[end - beg] = 0;
if (*nstrs == *capstrs) {
*capstrs = GPR_MAX(8, 2 * *capstrs);
- *strs = (char **)gpr_realloc(*strs, sizeof(*strs) * *capstrs);
+ *strs = (char**)gpr_realloc(*strs, sizeof(*strs) * *capstrs);
}
(*strs)[*nstrs] = out;
++*nstrs;
}
-void gpr_string_split(const char *input, const char *sep, char ***strs,
- size_t *nstrs) {
- const char *next;
+void gpr_string_split(const char* input, const char* sep, char*** strs,
+ size_t* nstrs) {
+ const char* next;
*strs = NULL;
*nstrs = 0;
size_t capstrs = 0;
@@ -288,9 +288,9 @@ void gpr_string_split(const char *input, const char *sep, char ***strs,
add_string_to_split(input, input + strlen(input), strs, nstrs, &capstrs);
}
-void *gpr_memrchr(const void *s, int c, size_t n) {
+void* gpr_memrchr(const void* s, int c, size_t n) {
if (s == NULL) return NULL;
- char *b = (char *)s;
+ char* b = (char*)s;
size_t i;
for (i = 0; i < n; i++) {
if (b[n - i - 1] == c) {
@@ -300,12 +300,12 @@ void *gpr_memrchr(const void *s, int c, size_t n) {
return NULL;
}
-bool gpr_is_true(const char *s) {
+bool gpr_is_true(const char* s) {
size_t i;
if (s == NULL) {
return false;
}
- static const char *truthy[] = {"yes", "true", "1"};
+ static const char* truthy[] = {"yes", "true", "1"};
for (i = 0; i < GPR_ARRAY_SIZE(truthy); i++) {
if (0 == gpr_stricmp(s, truthy[i])) {
return true;
diff --git a/src/core/lib/support/string.h b/src/core/lib/support/string.h
index 5a56fa3a0a..0b18ffcec1 100644
--- a/src/core/lib/support/string.h
+++ b/src/core/lib/support/string.h
@@ -36,12 +36,12 @@ extern "C" {
/* Converts array buf, of length len, into a C string according to the flags.
Result should be freed with gpr_free() */
-char *gpr_dump(const char *buf, size_t len, uint32_t flags);
+char* gpr_dump(const char* buf, size_t len, uint32_t flags);
/* Parses an array of bytes into an integer (base 10). Returns 1 on success,
0 on failure. */
-int gpr_parse_bytes_to_uint32(const char *data, size_t length,
- uint32_t *result);
+int gpr_parse_bytes_to_uint32(const char* data, size_t length,
+ uint32_t* result);
/* Minimum buffer size for calling ltoa */
#define GPR_LTOA_MIN_BUFSIZE (3 * sizeof(long))
@@ -49,7 +49,7 @@ int gpr_parse_bytes_to_uint32(const char *data, size_t length,
/* Convert a long to a string in base 10; returns the length of the
output string (or 0 on failure).
output must be at least GPR_LTOA_MIN_BUFSIZE bytes long. */
-int gpr_ltoa(long value, char *output);
+int gpr_ltoa(long value, char* output);
/* Minimum buffer size for calling int64toa */
#define GPR_INT64TOA_MIN_BUFSIZE (3 * sizeof(int64_t))
@@ -59,56 +59,56 @@ output string (or 0 on failure).
output must be at least GPR_INT64TOA_MIN_BUFSIZE bytes long.
NOTE: This function ensures sufficient bit width even on Win x64,
where long is 32bit is size.*/
-int int64_ttoa(int64_t value, char *output);
+int int64_ttoa(int64_t value, char* output);
// Parses a non-negative number from a value string. Returns -1 on error.
-int gpr_parse_nonnegative_int(const char *value);
+int gpr_parse_nonnegative_int(const char* value);
/* Reverse a run of bytes */
-void gpr_reverse_bytes(char *str, int len);
+void gpr_reverse_bytes(char* str, int len);
/* Pad a string with flag characters. The given length specifies the minimum
field width. The input string is never truncated. */
-char *gpr_leftpad(const char *str, char flag, size_t length);
+char* gpr_leftpad(const char* str, char flag, size_t length);
/* Join a set of strings, returning the resulting string.
Total combined length (excluding null terminator) is returned in total_length
if it is non-null. */
-char *gpr_strjoin(const char **strs, size_t nstrs, size_t *total_length);
+char* gpr_strjoin(const char** strs, size_t nstrs, size_t* total_length);
/* Join a set of strings using a separator, returning the resulting string.
Total combined length (excluding null terminator) is returned in total_length
if it is non-null. */
-char *gpr_strjoin_sep(const char **strs, size_t nstrs, const char *sep,
- size_t *total_length);
+char* gpr_strjoin_sep(const char** strs, size_t nstrs, const char* sep,
+ size_t* total_length);
-void gpr_string_split(const char *input, const char *sep, char ***strs,
- size_t *nstrs);
+void gpr_string_split(const char* input, const char* sep, char*** strs,
+ size_t* nstrs);
/* A vector of strings... for building up a final string one piece at a time */
typedef struct {
- char **strs;
+ char** strs;
size_t count;
size_t capacity;
} gpr_strvec;
/* Initialize/destroy */
-void gpr_strvec_init(gpr_strvec *strs);
-void gpr_strvec_destroy(gpr_strvec *strs);
+void gpr_strvec_init(gpr_strvec* strs);
+void gpr_strvec_destroy(gpr_strvec* strs);
/* Add a string to a strvec, takes ownership of the string */
-void gpr_strvec_add(gpr_strvec *strs, char *add);
+void gpr_strvec_add(gpr_strvec* strs, char* add);
/* Return a joined string with all added substrings, optionally setting
total_length as per gpr_strjoin */
-char *gpr_strvec_flatten(gpr_strvec *strs, size_t *total_length);
+char* gpr_strvec_flatten(gpr_strvec* strs, size_t* total_length);
/** Case insensitive string comparison... return <0 if lower(a)<lower(b), ==0 if
lower(a)==lower(b), >0 if lower(a)>lower(b) */
-int gpr_stricmp(const char *a, const char *b);
+int gpr_stricmp(const char* a, const char* b);
-void *gpr_memrchr(const void *s, int c, size_t n);
+void* gpr_memrchr(const void* s, int c, size_t n);
/** Return true if lower(s) equals "true", "yes" or "1", otherwise false. */
-bool gpr_is_true(const char *s);
+bool gpr_is_true(const char* s);
#ifdef __cplusplus
}
#endif
diff --git a/src/core/lib/support/string_posix.cc b/src/core/lib/support/string_posix.cc
index 92de21a6e1..79c81656cc 100644
--- a/src/core/lib/support/string_posix.cc
+++ b/src/core/lib/support/string_posix.cc
@@ -27,7 +27,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
-int gpr_asprintf(char **strp, const char *format, ...) {
+int gpr_asprintf(char** strp, const char* format, ...) {
va_list args;
int ret;
char buf[64];
@@ -44,7 +44,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
/* Allocate a new buffer, with space for the NUL terminator. */
strp_buflen = (size_t)ret + 1;
- if ((*strp = (char *)gpr_malloc(strp_buflen)) == NULL) {
+ if ((*strp = (char*)gpr_malloc(strp_buflen)) == NULL) {
/* This shouldn't happen, because gpr_malloc() calls abort(). */
return -1;
}
diff --git a/src/core/lib/support/string_util_windows.cc b/src/core/lib/support/string_util_windows.cc
index b365512ee3..e2b386be55 100644
--- a/src/core/lib/support/string_util_windows.cc
+++ b/src/core/lib/support/string_util_windows.cc
@@ -65,9 +65,9 @@ LPSTR gpr_tchar_to_char(LPCTSTR input) { return (LPSTR)gpr_strdup(input); }
LPTSTR gpr_char_to_tchar(LPCTSTR input) { return (LPTSTR)gpr_strdup(input); }
#endif
-char *gpr_format_message(int messageid) {
+char* gpr_format_message(int messageid) {
LPTSTR tmessage;
- char *message;
+ char* message;
DWORD status = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
diff --git a/src/core/lib/support/string_windows.cc b/src/core/lib/support/string_windows.cc
index d37863c066..ceb78f0054 100644
--- a/src/core/lib/support/string_windows.cc
+++ b/src/core/lib/support/string_windows.cc
@@ -31,7 +31,7 @@
#include "src/core/lib/support/string.h"
-int gpr_asprintf(char **strp, const char *format, ...) {
+int gpr_asprintf(char** strp, const char* format, ...) {
va_list args;
int ret;
size_t strp_buflen;
@@ -47,7 +47,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
/* Allocate a new buffer, with space for the NUL terminator. */
strp_buflen = (size_t)ret + 1;
- if ((*strp = (char *)gpr_malloc(strp_buflen)) == NULL) {
+ if ((*strp = (char*)gpr_malloc(strp_buflen)) == NULL) {
/* This shouldn't happen, because gpr_malloc() calls abort(). */
return -1;
}
diff --git a/src/core/lib/support/subprocess_posix.cc b/src/core/lib/support/subprocess_posix.cc
index af75162ee9..4d6972a0c4 100644
--- a/src/core/lib/support/subprocess_posix.cc
+++ b/src/core/lib/support/subprocess_posix.cc
@@ -41,19 +41,19 @@ struct gpr_subprocess {
bool joined;
};
-const char *gpr_subprocess_binary_extension() { return ""; }
+const char* gpr_subprocess_binary_extension() { return ""; }
-gpr_subprocess *gpr_subprocess_create(int argc, const char **argv) {
- gpr_subprocess *r;
+gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) {
+ gpr_subprocess* r;
int pid;
- char **exec_args;
+ char** exec_args;
pid = fork();
if (pid == -1) {
return NULL;
} else if (pid == 0) {
- exec_args = (char **)gpr_malloc(((size_t)argc + 1) * sizeof(char *));
- memcpy(exec_args, argv, (size_t)argc * sizeof(char *));
+ exec_args = (char**)gpr_malloc(((size_t)argc + 1) * sizeof(char*));
+ memcpy(exec_args, argv, (size_t)argc * sizeof(char*));
exec_args[argc] = NULL;
execv(exec_args[0], exec_args);
/* if we reach here, an error has occurred */
@@ -61,13 +61,13 @@ gpr_subprocess *gpr_subprocess_create(int argc, const char **argv) {
_exit(1);
return NULL;
} else {
- r = (gpr_subprocess *)gpr_zalloc(sizeof(gpr_subprocess));
+ r = (gpr_subprocess*)gpr_zalloc(sizeof(gpr_subprocess));
r->pid = pid;
return r;
}
}
-void gpr_subprocess_destroy(gpr_subprocess *p) {
+void gpr_subprocess_destroy(gpr_subprocess* p) {
if (!p->joined) {
kill(p->pid, SIGKILL);
gpr_subprocess_join(p);
@@ -75,7 +75,7 @@ void gpr_subprocess_destroy(gpr_subprocess *p) {
gpr_free(p);
}
-int gpr_subprocess_join(gpr_subprocess *p) {
+int gpr_subprocess_join(gpr_subprocess* p) {
int status;
retry:
if (waitpid(p->pid, &status, 0) == -1) {
@@ -90,7 +90,7 @@ retry:
return status;
}
-void gpr_subprocess_interrupt(gpr_subprocess *p) {
+void gpr_subprocess_interrupt(gpr_subprocess* p) {
if (!p->joined) {
kill(p->pid, SIGINT);
}
diff --git a/src/core/lib/support/subprocess_windows.cc b/src/core/lib/support/subprocess_windows.cc
index 6769f1d3a4..dcdafb5a63 100644
--- a/src/core/lib/support/subprocess_windows.cc
+++ b/src/core/lib/support/subprocess_windows.cc
@@ -36,16 +36,16 @@ struct gpr_subprocess {
int interrupted;
};
-const char *gpr_subprocess_binary_extension() { return ".exe"; }
+const char* gpr_subprocess_binary_extension() { return ".exe"; }
-gpr_subprocess *gpr_subprocess_create(int argc, const char **argv) {
- gpr_subprocess *r;
+gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) {
+ gpr_subprocess* r;
STARTUPINFO si;
PROCESS_INFORMATION pi;
- char *args = gpr_strjoin_sep(argv, (size_t)argc, " ", NULL);
- TCHAR *args_tchar;
+ char* args = gpr_strjoin_sep(argv, (size_t)argc, " ", NULL);
+ TCHAR* args_tchar;
args_tchar = gpr_char_to_tchar(args);
gpr_free(args);
@@ -61,13 +61,13 @@ gpr_subprocess *gpr_subprocess_create(int argc, const char **argv) {
}
gpr_free(args_tchar);
- r = (gpr_subprocess *)gpr_malloc(sizeof(gpr_subprocess));
+ r = (gpr_subprocess*)gpr_malloc(sizeof(gpr_subprocess));
memset(r, 0, sizeof(*r));
r->pi = pi;
return r;
}
-void gpr_subprocess_destroy(gpr_subprocess *p) {
+void gpr_subprocess_destroy(gpr_subprocess* p) {
if (p) {
if (!p->joined) {
gpr_subprocess_interrupt(p);
@@ -83,7 +83,7 @@ void gpr_subprocess_destroy(gpr_subprocess *p) {
}
}
-int gpr_subprocess_join(gpr_subprocess *p) {
+int gpr_subprocess_join(gpr_subprocess* p) {
DWORD dwExitCode;
if (GetExitCodeProcess(p->pi.hProcess, &dwExitCode)) {
if (dwExitCode == STILL_ACTIVE) {
@@ -110,7 +110,7 @@ getExitCode:
}
}
-void gpr_subprocess_interrupt(gpr_subprocess *p) {
+void gpr_subprocess_interrupt(gpr_subprocess* p) {
DWORD dwExitCode;
if (GetExitCodeProcess(p->pi.hProcess, &dwExitCode)) {
if (dwExitCode == STILL_ACTIVE) {
diff --git a/src/core/lib/support/sync.cc b/src/core/lib/support/sync.cc
index 994dcb0e14..1c051a1ca4 100644
--- a/src/core/lib/support/sync.cc
+++ b/src/core/lib/support/sync.cc
@@ -45,17 +45,17 @@ static void event_initialize(void) {
}
/* Hash ev into an element of sync_array[]. */
-static struct sync_array_s *hash(gpr_event *ev) {
+static struct sync_array_s* hash(gpr_event* ev) {
return &sync_array[((uintptr_t)ev) % event_sync_partitions];
}
-void gpr_event_init(gpr_event *ev) {
+void gpr_event_init(gpr_event* ev) {
gpr_once_init(&event_once, &event_initialize);
ev->state = 0;
}
-void gpr_event_set(gpr_event *ev, void *value) {
- struct sync_array_s *s = hash(ev);
+void gpr_event_set(gpr_event* ev, void* value) {
+ struct sync_array_s* s = hash(ev);
gpr_mu_lock(&s->mu);
GPR_ASSERT(gpr_atm_acq_load(&ev->state) == 0);
gpr_atm_rel_store(&ev->state, (gpr_atm)value);
@@ -64,28 +64,28 @@ void gpr_event_set(gpr_event *ev, void *value) {
GPR_ASSERT(value != NULL);
}
-void *gpr_event_get(gpr_event *ev) {
- return (void *)gpr_atm_acq_load(&ev->state);
+void* gpr_event_get(gpr_event* ev) {
+ return (void*)gpr_atm_acq_load(&ev->state);
}
-void *gpr_event_wait(gpr_event *ev, gpr_timespec abs_deadline) {
- void *result = (void *)gpr_atm_acq_load(&ev->state);
+void* gpr_event_wait(gpr_event* ev, gpr_timespec abs_deadline) {
+ void* result = (void*)gpr_atm_acq_load(&ev->state);
if (result == NULL) {
- struct sync_array_s *s = hash(ev);
+ struct sync_array_s* s = hash(ev);
gpr_mu_lock(&s->mu);
do {
- result = (void *)gpr_atm_acq_load(&ev->state);
+ result = (void*)gpr_atm_acq_load(&ev->state);
} while (result == NULL && !gpr_cv_wait(&s->cv, &s->mu, abs_deadline));
gpr_mu_unlock(&s->mu);
}
return result;
}
-void gpr_ref_init(gpr_refcount *r, int n) { gpr_atm_rel_store(&r->count, n); }
+void gpr_ref_init(gpr_refcount* r, int n) { gpr_atm_rel_store(&r->count, n); }
-void gpr_ref(gpr_refcount *r) { gpr_atm_no_barrier_fetch_add(&r->count, 1); }
+void gpr_ref(gpr_refcount* r) { gpr_atm_no_barrier_fetch_add(&r->count, 1); }
-void gpr_ref_non_zero(gpr_refcount *r) {
+void gpr_ref_non_zero(gpr_refcount* r) {
#ifndef NDEBUG
gpr_atm prior = gpr_atm_no_barrier_fetch_add(&r->count, 1);
assert(prior > 0);
@@ -94,29 +94,29 @@ void gpr_ref_non_zero(gpr_refcount *r) {
#endif
}
-void gpr_refn(gpr_refcount *r, int n) {
+void gpr_refn(gpr_refcount* r, int n) {
gpr_atm_no_barrier_fetch_add(&r->count, n);
}
-int gpr_unref(gpr_refcount *r) {
+int gpr_unref(gpr_refcount* r) {
gpr_atm prior = gpr_atm_full_fetch_add(&r->count, -1);
GPR_ASSERT(prior > 0);
return prior == 1;
}
-int gpr_ref_is_unique(gpr_refcount *r) {
+int gpr_ref_is_unique(gpr_refcount* r) {
return gpr_atm_acq_load(&r->count) == 1;
}
-void gpr_stats_init(gpr_stats_counter *c, intptr_t n) {
+void gpr_stats_init(gpr_stats_counter* c, intptr_t n) {
gpr_atm_rel_store(&c->value, n);
}
-void gpr_stats_inc(gpr_stats_counter *c, intptr_t inc) {
+void gpr_stats_inc(gpr_stats_counter* c, intptr_t inc) {
gpr_atm_no_barrier_fetch_add(&c->value, inc);
}
-intptr_t gpr_stats_read(const gpr_stats_counter *c) {
+intptr_t gpr_stats_read(const gpr_stats_counter* c) {
/* don't need acquire-load, but we have no no-barrier load yet */
return gpr_atm_acq_load(&c->value);
}
diff --git a/src/core/lib/support/sync_windows.cc b/src/core/lib/support/sync_windows.cc
index 62fdd40af7..7cd41633d5 100644
--- a/src/core/lib/support/sync_windows.cc
+++ b/src/core/lib/support/sync_windows.cc
@@ -26,25 +26,25 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
-void gpr_mu_init(gpr_mu *mu) {
+void gpr_mu_init(gpr_mu* mu) {
InitializeCriticalSection(&mu->cs);
mu->locked = 0;
}
-void gpr_mu_destroy(gpr_mu *mu) { DeleteCriticalSection(&mu->cs); }
+void gpr_mu_destroy(gpr_mu* mu) { DeleteCriticalSection(&mu->cs); }
-void gpr_mu_lock(gpr_mu *mu) {
+void gpr_mu_lock(gpr_mu* mu) {
EnterCriticalSection(&mu->cs);
GPR_ASSERT(!mu->locked);
mu->locked = 1;
}
-void gpr_mu_unlock(gpr_mu *mu) {
+void gpr_mu_unlock(gpr_mu* mu) {
mu->locked = 0;
LeaveCriticalSection(&mu->cs);
}
-int gpr_mu_trylock(gpr_mu *mu) {
+int gpr_mu_trylock(gpr_mu* mu) {
int result = TryEnterCriticalSection(&mu->cs);
if (result) {
if (mu->locked) { /* This thread already holds the lock. */
@@ -58,13 +58,13 @@ int gpr_mu_trylock(gpr_mu *mu) {
/*----------------------------------------*/
-void gpr_cv_init(gpr_cv *cv) { InitializeConditionVariable(cv); }
+void gpr_cv_init(gpr_cv* cv) { InitializeConditionVariable(cv); }
-void gpr_cv_destroy(gpr_cv *cv) {
+void gpr_cv_destroy(gpr_cv* cv) {
/* Condition variables don't need destruction in Win32. */
}
-int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) {
+int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) {
int timeout = 0;
DWORD timeout_max_ms;
mu->locked = 0;
@@ -93,23 +93,23 @@ int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) {
return timeout;
}
-void gpr_cv_signal(gpr_cv *cv) { WakeConditionVariable(cv); }
+void gpr_cv_signal(gpr_cv* cv) { WakeConditionVariable(cv); }
-void gpr_cv_broadcast(gpr_cv *cv) { WakeAllConditionVariable(cv); }
+void gpr_cv_broadcast(gpr_cv* cv) { WakeAllConditionVariable(cv); }
/*----------------------------------------*/
-static void *dummy;
+static void* dummy;
struct run_once_func_arg {
void (*init_function)(void);
};
-static BOOL CALLBACK run_once_func(gpr_once *once, void *v, void **pv) {
- struct run_once_func_arg *arg = (struct run_once_func_arg *)v;
+static BOOL CALLBACK run_once_func(gpr_once* once, void* v, void** pv) {
+ struct run_once_func_arg* arg = (struct run_once_func_arg*)v;
(*arg->init_function)();
return 1;
}
-void gpr_once_init(gpr_once *once, void (*init_function)(void)) {
+void gpr_once_init(gpr_once* once, void (*init_function)(void)) {
struct run_once_func_arg arg;
arg.init_function = init_function;
InitOnceExecuteOnce(once, run_once_func, &arg, &dummy);
diff --git a/src/core/lib/support/thd_posix.cc b/src/core/lib/support/thd_posix.cc
index 98afd10df7..297714e659 100644
--- a/src/core/lib/support/thd_posix.cc
+++ b/src/core/lib/support/thd_posix.cc
@@ -31,26 +31,26 @@
#include <string.h>
struct thd_arg {
- void (*body)(void *arg); /* body of a thread */
- void *arg; /* argument to a thread */
+ void (*body)(void* arg); /* body of a thread */
+ void* arg; /* argument to a thread */
};
/* Body of every thread started via gpr_thd_new. */
-static void *thread_body(void *v) {
- struct thd_arg a = *(struct thd_arg *)v;
+static void* thread_body(void* v) {
+ struct thd_arg a = *(struct thd_arg*)v;
free(v);
(*a.body)(a.arg);
return NULL;
}
-int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg,
- const gpr_thd_options *options) {
+int gpr_thd_new(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg,
+ const gpr_thd_options* options) {
int thread_started;
pthread_attr_t attr;
pthread_t p;
/* don't use gpr_malloc as we may cause an infinite recursion with
* the profiling code */
- struct thd_arg *a = (struct thd_arg *)malloc(sizeof(*a));
+ struct thd_arg* a = (struct thd_arg*)malloc(sizeof(*a));
GPR_ASSERT(a != NULL);
a->body = thd_body;
a->arg = arg;
diff --git a/src/core/lib/support/thd_windows.cc b/src/core/lib/support/thd_windows.cc
index 1a82805dd9..5bda7f440c 100644
--- a/src/core/lib/support/thd_windows.cc
+++ b/src/core/lib/support/thd_windows.cc
@@ -36,23 +36,23 @@
#endif
struct thd_info {
- void (*body)(void *arg); /* body of a thread */
- void *arg; /* argument to a thread */
+ void (*body)(void* arg); /* body of a thread */
+ void* arg; /* argument to a thread */
HANDLE join_event; /* if joinable, the join event */
int joinable; /* true if not detached */
};
-static thread_local struct thd_info *g_thd_info;
+static thread_local struct thd_info* g_thd_info;
/* Destroys a thread info */
-static void destroy_thread(struct thd_info *t) {
+static void destroy_thread(struct thd_info* t) {
if (t->joinable) CloseHandle(t->join_event);
gpr_free(t);
}
/* Body of every thread started via gpr_thd_new. */
-static DWORD WINAPI thread_body(void *v) {
- g_thd_info = (struct thd_info *)v;
+static DWORD WINAPI thread_body(void* v) {
+ g_thd_info = (struct thd_info*)v;
g_thd_info->body(g_thd_info->arg);
if (g_thd_info->joinable) {
BOOL ret = SetEvent(g_thd_info->join_event);
@@ -63,10 +63,10 @@ static DWORD WINAPI thread_body(void *v) {
return 0;
}
-int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg,
- const gpr_thd_options *options) {
+int gpr_thd_new(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg,
+ const gpr_thd_options* options) {
HANDLE handle;
- struct thd_info *info = (struct thd_info *)gpr_malloc(sizeof(*info));
+ struct thd_info* info = (struct thd_info*)gpr_malloc(sizeof(*info));
info->body = thd_body;
info->arg = arg;
*t = 0;
@@ -93,7 +93,7 @@ int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg,
gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)g_thd_info; }
void gpr_thd_join(gpr_thd_id t) {
- struct thd_info *info = (struct thd_info *)t;
+ struct thd_info* info = (struct thd_info*)t;
DWORD ret = WaitForSingleObject(info->join_event, INFINITE);
GPR_ASSERT(ret == WAIT_OBJECT_0);
destroy_thread(info);
diff --git a/src/core/lib/support/time_posix.cc b/src/core/lib/support/time_posix.cc
index 3f8a9094fd..3674ef7184 100644
--- a/src/core/lib/support/time_posix.cc
+++ b/src/core/lib/support/time_posix.cc
@@ -81,7 +81,7 @@ static gpr_timespec now_impl(gpr_clock_type clock_type) {
}
}
#else
-/* For some reason Apple's OSes haven't implemented clock_gettime. */
+ /* For some reason Apple's OSes haven't implemented clock_gettime. */
#include <mach/mach.h>
#include <mach/mach_time.h>
diff --git a/src/core/lib/support/time_precise.cc b/src/core/lib/support/time_precise.cc
index 05ef7c59bc..b7372df1b8 100644
--- a/src/core/lib/support/time_precise.cc
+++ b/src/core/lib/support/time_precise.cc
@@ -24,7 +24,7 @@
#ifdef GRPC_TIMERS_RDTSC
#if defined(__i386__)
-static void gpr_get_cycle_counter(int64_t int *clk) {
+static void gpr_get_cycle_counter(int64_t int* clk) {
int64_t int ret;
__asm__ volatile("rdtsc" : "=A"(ret));
*clk = ret;
@@ -32,7 +32,7 @@ static void gpr_get_cycle_counter(int64_t int *clk) {
// ----------------------------------------------------------------
#elif defined(__x86_64__) || defined(__amd64__)
-static void gpr_get_cycle_counter(int64_t *clk) {
+static void gpr_get_cycle_counter(int64_t* clk) {
uint64_t low, high;
__asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
*clk = (int64_t)(high << 32) | (int64_t)low;
@@ -56,7 +56,7 @@ void gpr_precise_clock_init(void) {
gpr_log(GPR_DEBUG, "... cycles_per_second = %f\n", cycles_per_second);
}
-void gpr_precise_clock_now(gpr_timespec *clk) {
+void gpr_precise_clock_now(gpr_timespec* clk) {
int64_t counter;
double secs;
gpr_get_cycle_counter(&counter);
@@ -69,7 +69,7 @@ void gpr_precise_clock_now(gpr_timespec *clk) {
#else /* GRPC_TIMERS_RDTSC */
void gpr_precise_clock_init(void) {}
-void gpr_precise_clock_now(gpr_timespec *clk) {
+void gpr_precise_clock_now(gpr_timespec* clk) {
*clk = gpr_now(GPR_CLOCK_REALTIME);
clk->clock_type = GPR_CLOCK_PRECISE;
}
diff --git a/src/core/lib/support/time_precise.h b/src/core/lib/support/time_precise.h
index cb15cdf919..3befda3d86 100644
--- a/src/core/lib/support/time_precise.h
+++ b/src/core/lib/support/time_precise.h
@@ -26,7 +26,7 @@ extern "C" {
#endif
void gpr_precise_clock_init(void);
-void gpr_precise_clock_now(gpr_timespec *clk);
+void gpr_precise_clock_now(gpr_timespec* clk);
#ifdef __cplusplus
}
diff --git a/src/core/lib/support/tls_pthread.cc b/src/core/lib/support/tls_pthread.cc
index 9ebee577fe..ebeef2a8c2 100644
--- a/src/core/lib/support/tls_pthread.cc
+++ b/src/core/lib/support/tls_pthread.cc
@@ -22,8 +22,8 @@
#include <grpc/support/tls.h>
-intptr_t gpr_tls_set(struct gpr_pthread_thread_local *tls, intptr_t value) {
- GPR_ASSERT(0 == pthread_setspecific(tls->key, (void *)value));
+intptr_t gpr_tls_set(struct gpr_pthread_thread_local* tls, intptr_t value) {
+ GPR_ASSERT(0 == pthread_setspecific(tls->key, (void*)value));
return value;
}
diff --git a/src/core/lib/support/tmpfile.h b/src/core/lib/support/tmpfile.h
index caa1d0f4d2..437d871786 100644
--- a/src/core/lib/support/tmpfile.h
+++ b/src/core/lib/support/tmpfile.h
@@ -29,7 +29,7 @@ extern "C" {
If tmp_filename is not NULL, *tmp_filename is assigned the name of the
created file and it is the responsibility of the caller to gpr_free it
unless an error occurs in which case it will be set to NULL. */
-FILE *gpr_tmpfile(const char *prefix, char **tmp_filename);
+FILE* gpr_tmpfile(const char* prefix, char** tmp_filename);
#ifdef __cplusplus
}
diff --git a/src/core/lib/support/tmpfile_msys.cc b/src/core/lib/support/tmpfile_msys.cc
index 614c0a4a18..430e866629 100644
--- a/src/core/lib/support/tmpfile_msys.cc
+++ b/src/core/lib/support/tmpfile_msys.cc
@@ -32,8 +32,8 @@
#include "src/core/lib/support/string_windows.h"
#include "src/core/lib/support/tmpfile.h"
-FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) {
- FILE *result = NULL;
+FILE* gpr_tmpfile(const char* prefix, char** tmp_filename_out) {
+ FILE* result = NULL;
char tmp_filename[MAX_PATH];
UINT success;
diff --git a/src/core/lib/support/tmpfile_posix.cc b/src/core/lib/support/tmpfile_posix.cc
index 7ad3af0a57..2e14d28598 100644
--- a/src/core/lib/support/tmpfile_posix.cc
+++ b/src/core/lib/support/tmpfile_posix.cc
@@ -33,9 +33,9 @@
#include "src/core/lib/support/string.h"
-FILE *gpr_tmpfile(const char *prefix, char **tmp_filename) {
- FILE *result = NULL;
- char *filename_template;
+FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) {
+ FILE* result = NULL;
+ char* filename_template;
int fd;
if (tmp_filename != NULL) *tmp_filename = NULL;
diff --git a/src/core/lib/support/tmpfile_windows.cc b/src/core/lib/support/tmpfile_windows.cc
index 47b4510a72..2b10bcde43 100644
--- a/src/core/lib/support/tmpfile_windows.cc
+++ b/src/core/lib/support/tmpfile_windows.cc
@@ -32,8 +32,8 @@
#include "src/core/lib/support/string_windows.h"
#include "src/core/lib/support/tmpfile.h"
-FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) {
- FILE *result = NULL;
+FILE* gpr_tmpfile(const char* prefix, char** tmp_filename_out) {
+ FILE* result = NULL;
LPTSTR template_string = NULL;
TCHAR tmp_path[MAX_PATH];
TCHAR tmp_filename[MAX_PATH];
diff --git a/src/core/lib/support/vector.h b/src/core/lib/support/vector.h
new file mode 100644
index 0000000000..4a7db80676
--- /dev/null
+++ b/src/core/lib/support/vector.h
@@ -0,0 +1,32 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef GRPC_CORE_LIB_SUPPORT_VECTOR_H
+#define GRPC_CORE_LIB_SUPPORT_VECTOR_H
+
+#include "absl/container/inlined_vector.h"
+#include "src/core/lib/support/memory.h"
+
+namespace grpc_core {
+
+template <typename T, size_t N>
+using InlinedVector = absl::InlinedVector<T, N, Allocator<T>>;
+
+} // namespace grpc_core
+
+#endif
diff --git a/src/core/lib/support/wrap_memcpy.cc b/src/core/lib/support/wrap_memcpy.cc
index c2362bf5b8..9b8608e056 100644
--- a/src/core/lib/support/wrap_memcpy.cc
+++ b/src/core/lib/support/wrap_memcpy.cc
@@ -30,11 +30,11 @@ extern "C" {
#ifdef __linux__
#if defined(__x86_64__) && !defined(GPR_MUSL_LIBC_COMPAT)
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
-void *__wrap_memcpy(void *destination, const void *source, size_t num) {
+void* __wrap_memcpy(void* destination, const void* source, size_t num) {
return memcpy(destination, source, num);
}
#else /* !__x86_64__ */
-void *__wrap_memcpy(void *destination, const void *source, size_t num) {
+void* __wrap_memcpy(void* destination, const void* source, size_t num) {
return memmove(destination, source, num);
}
#endif