aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/support')
-rw-r--r--src/core/lib/support/alloc.cc (renamed from src/core/lib/support/alloc.c)44
-rw-r--r--src/core/lib/support/arena.cc (renamed from src/core/lib/support/arena.c)24
-rw-r--r--src/core/lib/support/arena.h14
-rw-r--r--src/core/lib/support/atm.cc (renamed from src/core/lib/support/atm.c)2
-rw-r--r--src/core/lib/support/avl.cc (renamed from src/core/lib/support/avl.c)141
-rw-r--r--src/core/lib/support/backoff.c72
-rw-r--r--src/core/lib/support/backoff.h56
-rw-r--r--src/core/lib/support/block_annotate.h55
-rw-r--r--src/core/lib/support/cmdline.cc (renamed from src/core/lib/support/cmdline.c)124
-rw-r--r--src/core/lib/support/cpu_iphone.cc (renamed from src/core/lib/support/cpu_iphone.c)2
-rw-r--r--src/core/lib/support/cpu_linux.cc (renamed from src/core/lib/support/cpu_linux.c)10
-rw-r--r--src/core/lib/support/cpu_posix.cc (renamed from src/core/lib/support/cpu_posix.c)1
-rw-r--r--src/core/lib/support/cpu_windows.cc (renamed from src/core/lib/support/cpu_windows.c)1
-rw-r--r--src/core/lib/support/env.h6
-rw-r--r--src/core/lib/support/env_linux.cc (renamed from src/core/lib/support/env_linux.c)22
-rw-r--r--src/core/lib/support/env_posix.cc (renamed from src/core/lib/support/env_posix.c)8
-rw-r--r--src/core/lib/support/env_windows.cc (renamed from src/core/lib/support/env_windows.c)10
-rw-r--r--src/core/lib/support/fork.cc (renamed from src/core/lib/support/fork.c)0
-rw-r--r--src/core/lib/support/histogram.cc (renamed from src/core/lib/support/histogram.c)51
-rw-r--r--src/core/lib/support/host_port.cc (renamed from src/core/lib/support/host_port.c)32
-rw-r--r--src/core/lib/support/log.cc (renamed from src/core/lib/support/log.c)16
-rw-r--r--src/core/lib/support/log_android.cc (renamed from src/core/lib/support/log_android.c)14
-rw-r--r--src/core/lib/support/log_linux.cc (renamed from src/core/lib/support/log_linux.c)16
-rw-r--r--src/core/lib/support/log_posix.cc (renamed from src/core/lib/support/log_posix.c)19
-rw-r--r--src/core/lib/support/log_windows.cc (renamed from src/core/lib/support/log_windows.c)14
-rw-r--r--src/core/lib/support/manual_constructor.h76
-rw-r--r--src/core/lib/support/memory.h41
-rw-r--r--src/core/lib/support/mpscq.c79
-rw-r--r--src/core/lib/support/mpscq.cc114
-rw-r--r--src/core/lib/support/mpscq.h52
-rw-r--r--src/core/lib/support/murmur_hash.cc (renamed from src/core/lib/support/murmur_hash.c)8
-rw-r--r--src/core/lib/support/murmur_hash.h10
-rw-r--r--src/core/lib/support/spinlock.h9
-rw-r--r--src/core/lib/support/stack_lockfree.cc (renamed from src/core/lib/support/stack_lockfree.c)16
-rw-r--r--src/core/lib/support/stack_lockfree.h16
-rw-r--r--src/core/lib/support/string.cc (renamed from src/core/lib/support/string.c)111
-rw-r--r--src/core/lib/support/string.h42
-rw-r--r--src/core/lib/support/string_posix.cc (renamed from src/core/lib/support/string_posix.c)9
-rw-r--r--src/core/lib/support/string_util_windows.cc (renamed from src/core/lib/support/string_util_windows.c)15
-rw-r--r--src/core/lib/support/string_windows.cc (renamed from src/core/lib/support/string_windows.c)5
-rw-r--r--src/core/lib/support/string_windows.h8
-rw-r--r--src/core/lib/support/subprocess_posix.cc (renamed from src/core/lib/support/subprocess_posix.c)26
-rw-r--r--src/core/lib/support/subprocess_windows.cc (renamed from src/core/lib/support/subprocess_windows.c)18
-rw-r--r--src/core/lib/support/sync.cc (renamed from src/core/lib/support/sync.c)44
-rw-r--r--src/core/lib/support/sync_posix.cc (renamed from src/core/lib/support/sync_posix.c)8
-rw-r--r--src/core/lib/support/sync_windows.cc (renamed from src/core/lib/support/sync_windows.c)28
-rw-r--r--src/core/lib/support/thd.cc (renamed from src/core/lib/support/thd.c)0
-rw-r--r--src/core/lib/support/thd_posix.cc (renamed from src/core/lib/support/thd_posix.c)20
-rw-r--r--src/core/lib/support/thd_windows.cc (renamed from src/core/lib/support/thd_windows.c)20
-rw-r--r--src/core/lib/support/time.cc (renamed from src/core/lib/support/time.c)0
-rw-r--r--src/core/lib/support/time_posix.cc (renamed from src/core/lib/support/time_posix.c)11
-rw-r--r--src/core/lib/support/time_precise.cc (renamed from src/core/lib/support/time_precise.c)10
-rw-r--r--src/core/lib/support/time_precise.h10
-rw-r--r--src/core/lib/support/time_windows.cc (renamed from src/core/lib/support/time_windows.c)5
-rw-r--r--src/core/lib/support/tls_pthread.cc (renamed from src/core/lib/support/tls_pthread.c)4
-rw-r--r--src/core/lib/support/tmpfile.h2
-rw-r--r--src/core/lib/support/tmpfile_msys.cc (renamed from src/core/lib/support/tmpfile_msys.c)4
-rw-r--r--src/core/lib/support/tmpfile_posix.cc (renamed from src/core/lib/support/tmpfile_posix.c)14
-rw-r--r--src/core/lib/support/tmpfile_windows.cc (renamed from src/core/lib/support/tmpfile_windows.c)4
-rw-r--r--src/core/lib/support/vector.h32
-rw-r--r--src/core/lib/support/wrap_memcpy.cc (renamed from src/core/lib/support/wrap_memcpy.c)6
61 files changed, 871 insertions, 760 deletions
diff --git a/src/core/lib/support/alloc.c b/src/core/lib/support/alloc.cc
index 886d69d64c..518bdb99f7 100644
--- a/src/core/lib/support/alloc.c
+++ 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;
}
@@ -40,18 +40,18 @@ gpr_allocation_functions gpr_get_allocation_functions() {
}
void gpr_set_allocation_functions(gpr_allocation_functions functions) {
- GPR_ASSERT(functions.malloc_fn != NULL);
- GPR_ASSERT(functions.realloc_fn != NULL);
- GPR_ASSERT(functions.free_fn != NULL);
- if (functions.zalloc_fn == NULL) {
+ GPR_ASSERT(functions.malloc_fn != nullptr);
+ GPR_ASSERT(functions.realloc_fn != nullptr);
+ GPR_ASSERT(functions.free_fn != nullptr);
+ if (functions.zalloc_fn == nullptr) {
functions.zalloc_fn = zalloc_with_gpr_malloc;
}
g_alloc_functions = functions;
}
-void *gpr_malloc(size_t size) {
- void *p;
- if (size == 0) return NULL;
+void* gpr_malloc(size_t size) {
+ void* p;
+ if (size == 0) return nullptr;
GPR_TIMER_BEGIN("gpr_malloc", 0);
p = g_alloc_functions.malloc_fn(size);
if (!p) {
@@ -61,9 +61,9 @@ void *gpr_malloc(size_t size) {
return p;
}
-void *gpr_zalloc(size_t size) {
- void *p;
- if (size == 0) return NULL;
+void* gpr_zalloc(size_t size) {
+ void* p;
+ if (size == 0) return nullptr;
GPR_TIMER_BEGIN("gpr_zalloc", 0);
p = g_alloc_functions.zalloc_fn(size);
if (!p) {
@@ -73,14 +73,14 @@ 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) {
- if ((size == 0) && (p == NULL)) return NULL;
+void* gpr_realloc(void* p, size_t size) {
+ if ((size == 0) && (p == nullptr)) return nullptr;
GPR_TIMER_BEGIN("gpr_realloc", 0);
p = g_alloc_functions.realloc_fn(p, size);
if (!p) {
@@ -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.c b/src/core/lib/support/arena.cc
index 9e0f73ae3d..5b9dd370d8 100644
--- a/src/core/lib/support/arena.c
+++ 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);
- if (next_z == NULL) {
+ zone* next_z = (zone*)gpr_atm_acq_load(&z->next_atm);
+ if (next_z == nullptr) {
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 47f0e4d16b..4d43c56bb9 100644
--- a/src/core/lib/support/arena.h
+++ b/src/core/lib/support/arena.h
@@ -27,13 +27,21 @@
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
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
+}
+#endif
#endif /* GRPC_CORE_LIB_SUPPORT_ARENA_H */
diff --git a/src/core/lib/support/atm.c b/src/core/lib/support/atm.cc
index 2f37d62f76..15bfe52d64 100644
--- a/src/core/lib/support/atm.c
+++ 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.c b/src/core/lib/support/avl.cc
index 0e28b24c98..0b67a21f2f 100644
--- a/src/core/lib/support/avl.c
+++ b/src/core/lib/support/avl.cc
@@ -25,23 +25,23 @@
#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;
+ out.root = nullptr;
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) {
- if (node == NULL) {
+static void unref_node(const gpr_avl_vtable* vtable, gpr_avl_node* node,
+ void* user_data) {
+ if (node == nullptr) {
return;
}
if (gpr_unref(&node->refs)) {
@@ -53,18 +53,19 @@ static void unref_node(const gpr_avl_vtable *vtable, gpr_avl_node *node,
}
}
-static long node_height(gpr_avl_node *node) {
- return node == NULL ? 0 : node->height;
+static long node_height(gpr_avl_node* node) {
+ return node == nullptr ? 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 == nullptr ? 0
+ : 1 + GPR_MAX(calculate_height(node->left),
+ calculate_height(node->right));
}
-static gpr_avl_node *assert_invariants(gpr_avl_node *n) {
- if (n == NULL) return NULL;
+static gpr_avl_node* assert_invariants(gpr_avl_node* n) {
+ if (n == nullptr) return nullptr;
assert_invariants(n->left);
assert_invariants(n->right);
assert(calculate_height(n) == n->height);
@@ -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,12 +88,12 @@ 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) {
- return NULL;
+ if (node == nullptr) {
+ return nullptr;
}
cmp = vtable->compare_keys(node->key, key, user_data);
@@ -105,24 +106,24 @@ 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);
- return node ? node->value : NULL;
+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 : nullptr;
}
-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) {
+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 != nullptr) {
*value = node->value;
return 1;
}
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,11 +197,11 @@ 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);
+ if (node == nullptr) {
+ return new_node(key, value, nullptr, nullptr);
}
cmp = vtable->compare_keys(node->key, key, user_data);
if (cmp == 0) {
@@ -218,49 +219,49 @@ 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) {
- while (node->left != NULL) {
+static gpr_avl_node* in_order_head(gpr_avl_node* node) {
+ while (node->left != nullptr) {
node = node->left;
}
return node;
}
-static gpr_avl_node *in_order_tail(gpr_avl_node *node) {
- while (node->right != NULL) {
+static gpr_avl_node* in_order_tail(gpr_avl_node* node) {
+ while (node->right != nullptr) {
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;
+ if (node == nullptr) {
+ return nullptr;
}
cmp = vtable->compare_keys(node->key, key, user_data);
if (cmp == 0) {
- if (node->left == NULL) {
+ if (node->left == nullptr) {
return ref_node(node->right);
- } else if (node->right == NULL) {
+ } else if (node->right == nullptr) {
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,21 +280,21 @@ 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);
}
-int gpr_avl_is_empty(gpr_avl avl) { return avl.root == NULL; }
+int gpr_avl_is_empty(gpr_avl avl) { return avl.root == nullptr; }
diff --git a/src/core/lib/support/backoff.c b/src/core/lib/support/backoff.c
deleted file mode 100644
index 6dc0df473b..0000000000
--- a/src/core/lib/support/backoff.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- *
- * Copyright 2016 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.
- *
- */
-
-#include "src/core/lib/support/backoff.h"
-
-#include <grpc/support/useful.h>
-
-void gpr_backoff_init(gpr_backoff *backoff, int64_t initial_connect_timeout,
- double multiplier, double jitter,
- int64_t min_timeout_millis, int64_t max_timeout_millis) {
- backoff->initial_connect_timeout = initial_connect_timeout;
- backoff->multiplier = multiplier;
- backoff->jitter = jitter;
- backoff->min_timeout_millis = min_timeout_millis;
- backoff->max_timeout_millis = max_timeout_millis;
- backoff->rng_state = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec;
-}
-
-gpr_timespec gpr_backoff_begin(gpr_backoff *backoff, gpr_timespec now) {
- backoff->current_timeout_millis = backoff->initial_connect_timeout;
- const int64_t first_timeout =
- GPR_MAX(backoff->current_timeout_millis, backoff->min_timeout_millis);
- return gpr_time_add(now, gpr_time_from_millis(first_timeout, GPR_TIMESPAN));
-}
-
-/* Generate a random number between 0 and 1. */
-static double generate_uniform_random_number(uint32_t *rng_state) {
- *rng_state = (1103515245 * *rng_state + 12345) % ((uint32_t)1 << 31);
- return *rng_state / (double)((uint32_t)1 << 31);
-}
-
-gpr_timespec gpr_backoff_step(gpr_backoff *backoff, gpr_timespec now) {
- const double new_timeout_millis =
- backoff->multiplier * (double)backoff->current_timeout_millis;
- backoff->current_timeout_millis =
- GPR_MIN((int64_t)new_timeout_millis, backoff->max_timeout_millis);
-
- const double jitter_range_width = backoff->jitter * new_timeout_millis;
- const double jitter =
- (2 * generate_uniform_random_number(&backoff->rng_state) - 1) *
- jitter_range_width;
-
- backoff->current_timeout_millis =
- (int64_t)((double)(backoff->current_timeout_millis) + jitter);
-
- const gpr_timespec current_deadline = gpr_time_add(
- now, gpr_time_from_millis(backoff->current_timeout_millis, GPR_TIMESPAN));
-
- const gpr_timespec min_deadline = gpr_time_add(
- now, gpr_time_from_millis(backoff->min_timeout_millis, GPR_TIMESPAN));
-
- return gpr_time_max(current_deadline, min_deadline);
-}
-
-void gpr_backoff_reset(gpr_backoff *backoff) {
- backoff->current_timeout_millis = backoff->initial_connect_timeout;
-}
diff --git a/src/core/lib/support/backoff.h b/src/core/lib/support/backoff.h
deleted file mode 100644
index 6e0cc3a4b6..0000000000
--- a/src/core/lib/support/backoff.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- *
- * Copyright 2016 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_BACKOFF_H
-#define GRPC_CORE_LIB_SUPPORT_BACKOFF_H
-
-#include <grpc/support/time.h>
-
-typedef struct {
- /// const: how long to wait after the first failure before retrying
- int64_t initial_connect_timeout;
- /// const: factor with which to multiply backoff after a failed retry
- double multiplier;
- /// const: amount to randomize backoffs
- double jitter;
- /// const: minimum time between retries in milliseconds
- int64_t min_timeout_millis;
- /// const: maximum time between retries in milliseconds
- int64_t max_timeout_millis;
-
- /// random number generator
- uint32_t rng_state;
-
- /// current retry timeout in milliseconds
- int64_t current_timeout_millis;
-} gpr_backoff;
-
-/// Initialize backoff machinery - does not need to be destroyed
-void gpr_backoff_init(gpr_backoff *backoff, int64_t initial_connect_timeout,
- double multiplier, double jitter,
- int64_t min_timeout_millis, int64_t max_timeout_millis);
-
-/// Begin retry loop: returns a timespec for the NEXT retry
-gpr_timespec gpr_backoff_begin(gpr_backoff *backoff, gpr_timespec now);
-/// Step a retry loop: returns a timespec for the NEXT retry
-gpr_timespec gpr_backoff_step(gpr_backoff *backoff, gpr_timespec now);
-/// Reset the backoff, so the next gpr_backoff_step will be a gpr_backoff_begin
-/// instead
-void gpr_backoff_reset(gpr_backoff *backoff);
-
-#endif /* GRPC_CORE_LIB_SUPPORT_BACKOFF_H */
diff --git a/src/core/lib/support/block_annotate.h b/src/core/lib/support/block_annotate.h
deleted file mode 100644
index 8e3ef7df65..0000000000
--- a/src/core/lib/support/block_annotate.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *
- * Copyright 2015 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_BLOCK_ANNOTATE_H
-#define GRPC_CORE_LIB_SUPPORT_BLOCK_ANNOTATE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void gpr_thd_start_blocking_region();
-void gpr_thd_end_blocking_region();
-
-#ifdef __cplusplus
-}
-#endif
-
-/* These annotations identify the beginning and end of regions where
- the code may block for reasons other than synchronization functions.
- These include poll, epoll, and getaddrinfo. */
-
-#ifdef GRPC_SCHEDULING_MARK_BLOCKING_REGION
-#define GRPC_SCHEDULING_START_BLOCKING_REGION \
- do { \
- gpr_thd_start_blocking_region(); \
- } while (0)
-#define GRPC_SCHEDULING_END_BLOCKING_REGION \
- do { \
- gpr_thd_end_blocking_region(); \
- } while (0)
-#else
-#define GRPC_SCHEDULING_START_BLOCKING_REGION \
- do { \
- } while (0)
-#define GRPC_SCHEDULING_END_BLOCKING_REGION \
- do { \
- } while (0)
-#endif
-
-#endif /* GRPC_CORE_LIB_SUPPORT_BLOCK_ANNOTATE_H */
diff --git a/src/core/lib/support/cmdline.c b/src/core/lib/support/cmdline.cc
index 9fb80d4460..da9f10a496 100644
--- a/src/core/lib/support/cmdline.c
+++ 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++;
@@ -169,13 +169,13 @@ char *gpr_cmdline_usage_string(gpr_cmdline *cl, const char *argv0) {
}
gpr_strvec_add(&s, gpr_strdup("\n"));
- tmp = gpr_strvec_flatten(&s, NULL);
+ tmp = gpr_strvec_flatten(&s, nullptr);
gpr_strvec_destroy(&s);
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)) {
@@ -203,15 +203,15 @@ static arg *find_arg(gpr_cmdline *cl, char *name) {
if (!a) {
fprintf(stderr, "Unknown argument: %s\n", name);
- return NULL;
+ return nullptr;
}
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 = nullptr;
+ char* tmp = nullptr;
+ char* arg_name = nullptr;
int r = 1;
if (0 == strcmp(str, "-help") || 0 == strcmp(str, "--help") ||
@@ -256,7 +256,7 @@ static int normal_state(gpr_cmdline *cl, char *str) {
return print_usage_and_die(cl);
}
- cl->cur_arg = NULL;
+ cl->cur_arg = nullptr;
if (str[0] == '-') {
if (str[1] == '-') {
@@ -274,30 +274,30 @@ static int normal_state(gpr_cmdline *cl, char *str) {
/* str is of the form '--no-foo' - it's a flag disable */
str += 3;
cl->cur_arg = find_arg(cl, str);
- if (cl->cur_arg == NULL) {
+ if (cl->cur_arg == nullptr) {
return print_usage_and_die(cl);
}
if (cl->cur_arg->type != ARGTYPE_BOOL) {
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) {
+ if (eq != nullptr) {
/* 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 {
arg_name = str;
}
cl->cur_arg = find_arg(cl, arg_name);
- if (cl->cur_arg == NULL) {
+ if (cl->cur_arg == nullptr) {
return print_usage_and_die(cl);
}
- if (eq != NULL) {
+ if (eq != nullptr) {
/* str was of the type --foo=value, parse the value */
r = value_state(cl, eq + 1);
} else if (cl->cur_arg->type != ARGTYPE_BOOL) {
@@ -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/cpu_iphone.c b/src/core/lib/support/cpu_iphone.cc
index dfd69b9fd8..2847e03ba5 100644
--- a/src/core/lib/support/cpu_iphone.c
+++ b/src/core/lib/support/cpu_iphone.cc
@@ -18,6 +18,8 @@
#include <grpc/support/port_platform.h>
+#include <grpc/support/cpu.h>
+
#ifdef GPR_CPU_IPHONE
/* Probably 2 instead of 1, but see comment on gpr_cpu_current_cpu. */
diff --git a/src/core/lib/support/cpu_linux.c b/src/core/lib/support/cpu_linux.cc
index 2280668442..21b1a71dc9 100644
--- a/src/core/lib/support/cpu_linux.c
+++ b/src/core/lib/support/cpu_linux.cc
@@ -36,6 +36,13 @@
static int ncpus = 0;
static void init_num_cpus() {
+#ifndef GPR_MUSL_LIBC_COMPAT
+ if (sched_getcpu() < 0) {
+ gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
+ ncpus = 1;
+ return;
+ }
+#endif
/* This must be signed. sysconf returns -1 when the number cannot be
determined */
ncpus = (int)sysconf(_SC_NPROCESSORS_ONLN);
@@ -56,6 +63,9 @@ unsigned gpr_cpu_current_cpu(void) {
// sched_getcpu() is undefined on musl
return 0;
#else
+ if (gpr_cpu_num_cores() == 1) {
+ return 0;
+ }
int cpu = sched_getcpu();
if (cpu < 0) {
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
diff --git a/src/core/lib/support/cpu_posix.c b/src/core/lib/support/cpu_posix.cc
index a1ba8202a8..503a96b4c8 100644
--- a/src/core/lib/support/cpu_posix.c
+++ b/src/core/lib/support/cpu_posix.cc
@@ -24,6 +24,7 @@
#include <string.h>
#include <unistd.h>
+#include <grpc/support/cpu.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>
diff --git a/src/core/lib/support/cpu_windows.c b/src/core/lib/support/cpu_windows.cc
index af26ff3679..8d89453403 100644
--- a/src/core/lib/support/cpu_windows.c
+++ b/src/core/lib/support/cpu_windows.cc
@@ -19,6 +19,7 @@
#include <grpc/support/port_platform.h>
#ifdef GPR_WINDOWS
+#include <grpc/support/cpu.h>
#include <grpc/support/log.h>
unsigned gpr_cpu_num_cores(void) {
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.c b/src/core/lib/support/env_linux.cc
index 4c45a977ca..0af2de9f7e 100644
--- a/src/core/lib/support/env_linux.c
+++ 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 = nullptr;
+ char* result = nullptr;
#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) {
@@ -60,21 +60,21 @@ const char *gpr_getenv_silent(const char *name, char **dst) {
result = getenv(name);
insecure_func_used = "getenv";
#endif
- *dst = result == NULL ? result : gpr_strdup(result);
+ *dst = result == nullptr ? result : gpr_strdup(result);
return insecure_func_used;
}
-char *gpr_getenv(const char *name) {
- char *result = NULL;
- const char *insecure_func_used = gpr_getenv_silent(name, &result);
- if (insecure_func_used != NULL) {
+char* gpr_getenv(const char* name) {
+ char* result = nullptr;
+ const char* insecure_func_used = gpr_getenv_silent(name, &result);
+ if (insecure_func_used != nullptr) {
gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used",
insecure_func_used);
}
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.c b/src/core/lib/support/env_posix.cc
index b88822ca02..7bea31ca55 100644
--- a/src/core/lib/support/env_posix.c
+++ 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.c b/src/core/lib/support/env_windows.cc
index a6499543f8..cdb1d58ccd 100644
--- a/src/core/lib/support/env_windows.c
+++ 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);
@@ -48,7 +48,7 @@ char *gpr_getenv(const char *name) {
return NULL;
}
size = ret * (DWORD)sizeof(TCHAR);
- tresult = gpr_malloc(size);
+ tresult = (LPTSTR)gpr_malloc(size);
ret = GetEnvironmentVariable(tname, tresult, size);
gpr_free(tname);
if (ret == 0) {
@@ -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/fork.c b/src/core/lib/support/fork.cc
index 2f29af899d..2f29af899d 100644
--- a/src/core/lib/support/fork.c
+++ b/src/core/lib/support/fork.cc
diff --git a/src/core/lib/support/histogram.c b/src/core/lib/support/histogram.cc
index 6d5ead9aa6..73c821a28b 100644
--- a/src/core/lib/support/histogram.c
+++ 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.c b/src/core/lib/support/host_port.cc
index 3302e574ab..cb8e3d4479 100644
--- a/src/core/lib/support/host_port.c
+++ b/src/core/lib/support/host_port.cc
@@ -25,8 +25,8 @@
#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) {
- if (host[0] != '[' && strchr(host, ':') != NULL) {
+int gpr_join_host_port(char** out, const char* host, int port) {
+ if (host[0] != '[' && strchr(host, ':') != nullptr) {
/* IPv6 literals must be enclosed in brackets. */
return gpr_asprintf(out, "[%s]:%d", host, port);
} else {
@@ -35,24 +35,24 @@ 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;
+ *host = nullptr;
+ *port = nullptr;
if (name[0] == '[') {
/* Parse a bracketed host, typically an IPv6 literal. */
- const char *rbracket = strchr(name, ']');
- if (rbracket == NULL) {
+ const char* rbracket = strchr(name, ']');
+ if (rbracket == nullptr) {
/* Unmatched [ */
return 0;
}
if (rbracket[1] == '\0') {
/* ]<end> */
- port_start = NULL;
+ port_start = nullptr;
} else if (rbracket[1] == ':') {
/* ]:<port?> */
port_start = rbracket + 2;
@@ -62,14 +62,14 @@ int gpr_split_host_port(const char *name, char **host, char **port) {
}
host_start = name + 1;
host_len = (size_t)(rbracket - host_start);
- if (memchr(host_start, ':', host_len) == NULL) {
+ if (memchr(host_start, ':', host_len) == nullptr) {
/* Require all bracketed hosts to contain a colon, because a hostname or
IPv4 address should never use brackets. */
return 0;
}
} else {
- const char *colon = strchr(name, ':');
- if (colon != NULL && strchr(colon + 1, ':') == NULL) {
+ const char* colon = strchr(name, ':');
+ if (colon != nullptr && strchr(colon + 1, ':') == nullptr) {
/* Exactly 1 colon. Split into host:port. */
host_start = name;
host_len = (size_t)(colon - name);
@@ -78,16 +78,16 @@ int gpr_split_host_port(const char *name, char **host, char **port) {
/* 0 or 2+ colons. Bare hostname or IPv6 litearal. */
host_start = name;
host_len = strlen(name);
- port_start = NULL;
+ port_start = nullptr;
}
}
/* 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';
- if (port_start != NULL) {
+ if (port_start != nullptr) {
*port = gpr_strdup(port_start);
}
diff --git a/src/core/lib/support/log.c b/src/core/lib/support/log.cc
index fadb4d9a2c..e9adc6c349 100644
--- a/src/core/lib/support/log.c
+++ b/src/core/lib/support/log.cc
@@ -27,11 +27,11 @@
#include <stdio.h>
#include <string.h>
-extern 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,11 +64,11 @@ 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 = nullptr;
+ const char* insecure_getenv = gpr_getenv_silent("GRPC_VERBOSITY", &verbosity);
gpr_atm min_severity_to_print = GPR_LOG_SEVERITY_ERROR;
- if (verbosity != NULL) {
+ if (verbosity != nullptr) {
if (gpr_stricmp(verbosity, "DEBUG") == 0) {
min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_DEBUG;
} else if (gpr_stricmp(verbosity, "INFO") == 0) {
@@ -83,7 +83,7 @@ void gpr_log_verbosity_init() {
gpr_atm_no_barrier_store(&g_min_severity_to_print, min_severity_to_print);
}
- if (insecure_getenv != NULL) {
+ if (insecure_getenv != nullptr) {
gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used",
insecure_getenv);
}
diff --git a/src/core/lib/support/log_android.c b/src/core/lib/support/log_android.cc
index 6f1cec51f1..73d24cd84d 100644
--- a/src/core/lib/support/log_android.c
+++ 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;
}
-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 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
free(message);
}
-void gpr_default_log(gpr_log_func_args *args) {
- 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.c b/src/core/lib/support/log_linux.cc
index 7755018693..e0e277fe87 100644
--- a/src/core/lib/support/log_linux.c
+++ 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 = nullptr;
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);
}
-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);
@@ -69,7 +69,7 @@ void gpr_default_log(gpr_log_func_args *args) {
timer = (time_t)now.tv_sec;
final_slash = strrchr(args->file, '/');
- if (final_slash == NULL)
+ if (final_slash == nullptr)
display_file = args->file;
else
display_file = final_slash + 1;
diff --git a/src/core/lib/support/log_posix.c b/src/core/lib/support/log_posix.cc
index 8b376fce41..e765f91390 100644
--- a/src/core/lib/support/log_posix.c
+++ 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 = 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);
}
-void gpr_default_log(gpr_log_func_args *args) {
- 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 @@ 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.c b/src/core/lib/support/log_windows.cc
index 0fdab79ae6..d4481791e2 100644
--- a/src/core/lib/support/log_windows.c
+++ 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 = 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 */
-void gpr_default_log(gpr_log_func_args *args) {
- 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/manual_constructor.h b/src/core/lib/support/manual_constructor.h
new file mode 100644
index 0000000000..d753cf98a0
--- /dev/null
+++ b/src/core/lib/support/manual_constructor.h
@@ -0,0 +1,76 @@
+/*
+ *
+ * Copyright 2016 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_MANUAL_CONSTRUCTOR_H
+#define GRPC_CORE_LIB_SUPPORT_MANUAL_CONSTRUCTOR_H
+
+// manually construct a region of memory with some type
+
+#include <stddef.h>
+#include <new>
+#include <type_traits>
+#include <utility>
+
+namespace grpc_core {
+
+template <typename Type>
+class ManualConstructor {
+ public:
+ // No constructor or destructor because one of the most useful uses of
+ // this class is as part of a union, and members of a union could not have
+ // constructors or destructors till C++11. And, anyway, the whole point of
+ // this class is to bypass constructor and destructor.
+
+ Type* get() { return reinterpret_cast<Type*>(&space_); }
+ const Type* get() const { return reinterpret_cast<const Type*>(&space_); }
+
+ Type* operator->() { return get(); }
+ const Type* operator->() const { return get(); }
+
+ Type& operator*() { return *get(); }
+ const Type& operator*() const { return *get(); }
+
+ void Init() { new (&space_) Type; }
+
+ // Init() constructs the Type instance using the given arguments
+ // (which are forwarded to Type's constructor).
+ //
+ // Note that Init() with no arguments performs default-initialization,
+ // not zero-initialization (i.e it behaves the same as "new Type;", not
+ // "new Type();"), so it will leave non-class types uninitialized.
+ template <typename... Ts>
+ void Init(Ts&&... args) {
+ new (&space_) Type(std::forward<Ts>(args)...);
+ }
+
+ // Init() that is equivalent to copy and move construction.
+ // Enables usage like this:
+ // ManualConstructor<std::vector<int>> v;
+ // v.Init({1, 2, 3});
+ void Init(const Type& x) { new (&space_) Type(x); }
+ void Init(Type&& x) { new (&space_) Type(std::move(x)); }
+
+ void Destroy() { get()->~Type(); }
+
+ private:
+ typename std::aligned_storage<sizeof(Type), alignof(Type)>::type space_;
+};
+
+} // namespace grpc_core
+
+#endif
diff --git a/src/core/lib/support/memory.h b/src/core/lib/support/memory.h
index dc3d32e1c2..695418e3e1 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 = nullptr) {
+ 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.c b/src/core/lib/support/mpscq.c
deleted file mode 100644
index e9f893988d..0000000000
--- a/src/core/lib/support/mpscq.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- *
- * Copyright 2016 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.
- *
- */
-
-#include "src/core/lib/support/mpscq.h"
-
-#include <grpc/support/log.h>
-
-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) {
- 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) {
- 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_atm_rel_store(&prev->next, (gpr_atm)n);
-}
-
-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);
- if (tail == &q->stub) {
- // indicates the list is actually (ephemerally) empty
- if (next == NULL) {
- *empty = true;
- return NULL;
- }
- q->tail = next;
- 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);
- 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);
- if (next != NULL) {
- q->tail = next;
- return tail;
- }
- // indicates a retry is in order: we're still adding
- *empty = false;
- return NULL;
-}
diff --git a/src/core/lib/support/mpscq.cc b/src/core/lib/support/mpscq.cc
new file mode 100644
index 0000000000..47e896d2df
--- /dev/null
+++ b/src/core/lib/support/mpscq.cc
@@ -0,0 +1,114 @@
+/*
+ *
+ * Copyright 2016 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.
+ *
+ */
+
+#include "src/core/lib/support/mpscq.h"
+
+#include <grpc/support/log.h>
+
+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) {
+ GPR_ASSERT(gpr_atm_no_barrier_load(&q->head) == (gpr_atm)&q->stub);
+ GPR_ASSERT(q->tail == &q->stub);
+}
+
+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_atm_rel_store(&prev->next, (gpr_atm)n);
+ return prev == &q->stub;
+}
+
+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);
+ if (tail == &q->stub) {
+ // indicates the list is actually (ephemerally) empty
+ if (next == nullptr) {
+ *empty = true;
+ return nullptr;
+ }
+ q->tail = next;
+ tail = next;
+ next = (gpr_mpscq_node*)gpr_atm_acq_load(&tail->next);
+ }
+ if (next != nullptr) {
+ *empty = false;
+ q->tail = next;
+ return tail;
+ }
+ 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 nullptr;
+ }
+ gpr_mpscq_push(q, &q->stub);
+ next = (gpr_mpscq_node*)gpr_atm_acq_load(&tail->next);
+ if (next != nullptr) {
+ q->tail = next;
+ return tail;
+ }
+ // indicates a retry is in order: we're still adding
+ *empty = false;
+ return nullptr;
+}
+
+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 nullptr;
+}
+
+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 == nullptr && !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 daa51768f7..fb22742050 100644
--- a/src/core/lib/support/mpscq.h
+++ b/src/core/lib/support/mpscq.h
@@ -20,34 +20,72 @@
#define GRPC_CORE_LIB_SUPPORT_MPSCQ_H
#include <grpc/support/atm.h>
+#include <grpc/support/sync.h>
#include <stdbool.h>
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// Multiple-producer single-consumer lock free queue, based upon the
// implementation from Dmitry Vyukov here:
// http://www.1024cores.net/home/lock-free-algorithms/queues/intrusive-mpsc-node-based-queue
// 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
#endif /* GRPC_CORE_LIB_SUPPORT_MPSCQ_H */
diff --git a/src/core/lib/support/murmur_hash.c b/src/core/lib/support/murmur_hash.cc
index f06b970de7..4e08579a1d 100644
--- a/src/core/lib/support/murmur_hash.c
+++ 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 7510b4d09c..d02bba6962 100644
--- a/src/core/lib/support/murmur_hash.h
+++ b/src/core/lib/support/murmur_hash.h
@@ -23,7 +23,15 @@
#include <stddef.h>
+#ifdef __cplusplus
+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
+}
+#endif
#endif /* GRPC_CORE_LIB_SUPPORT_MURMUR_HASH_H */
diff --git a/src/core/lib/support/spinlock.h b/src/core/lib/support/spinlock.h
index 37adda11b0..8b439642e9 100644
--- a/src/core/lib/support/spinlock.h
+++ b/src/core/lib/support/spinlock.h
@@ -23,11 +23,18 @@
/* 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})
+#else
#define GPR_SPINLOCK_INITIALIZER ((gpr_spinlock){0})
+#endif
#define GPR_SPINLOCK_STATIC_INITIALIZER \
{ 0 }
+
#define gpr_spinlock_trylock(lock) (gpr_atm_acq_cas(&(lock)->atm, 0, 1))
#define gpr_spinlock_unlock(lock) (gpr_atm_rel_store(&(lock)->atm, 0))
#define gpr_spinlock_lock(lock) \
diff --git a/src/core/lib/support/stack_lockfree.c b/src/core/lib/support/stack_lockfree.cc
index 0fb64ed001..7a4ede3b92 100644
--- a/src/core/lib/support/stack_lockfree.c
+++ 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 6324211b72..337ecc2b17 100644
--- a/src/core/lib/support/stack_lockfree.h
+++ b/src/core/lib/support/stack_lockfree.h
@@ -21,18 +21,26 @@
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
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
+}
+#endif
#endif /* GRPC_CORE_LIB_SUPPORT_STACK_LOCKFREE_H */
diff --git a/src/core/lib/support/string.c b/src/core/lib/support/string.cc
index 6b172df82f..e31ad72c68 100644
--- a/src/core/lib/support/string.c
+++ b/src/core/lib/support/string.cc
@@ -27,18 +27,19 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
+#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) {
- return NULL;
+ return nullptr;
}
len = strlen(src) + 1;
- dst = (char *)gpr_malloc(len);
+ dst = (char*)gpr_malloc(len);
memcpy(dst, src, len);
@@ -48,28 +49,28 @@ 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) {
- dump_out r = {0, 0, NULL};
+ dump_out r = {0, 0, nullptr};
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, ' ');
@@ -78,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);
@@ -107,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;
@@ -125,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;
@@ -134,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;
@@ -155,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;
@@ -176,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]);
}
@@ -210,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]);
@@ -222,15 +223,15 @@ char *gpr_strjoin_sep(const char **strs, size_t nstrs, const char *sep,
out_length += slen;
}
out[out_length] = 0;
- if (final_length != NULL) {
+ if (final_length != nullptr) {
*final_length = out_length;
}
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]);
@@ -238,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);
@@ -261,23 +262,23 @@ 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;
- *strs = NULL;
+void gpr_string_split(const char* input, const char* sep, char*** strs,
+ size_t* nstrs) {
+ const char* next;
+ *strs = nullptr;
*nstrs = 0;
size_t capstrs = 0;
while ((next = strstr(input, sep))) {
@@ -287,24 +288,24 @@ 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) {
- if (s == NULL) return NULL;
- char *b = (char *)s;
+void* gpr_memrchr(const void* s, int c, size_t n) {
+ if (s == nullptr) return nullptr;
+ char* b = (char*)s;
size_t i;
for (i = 0; i < n; i++) {
if (b[n - i - 1] == c) {
return &b[n - i - 1];
}
}
- return NULL;
+ return nullptr;
}
-bool gpr_is_true(const char *s) {
+bool gpr_is_true(const char* s) {
size_t i;
- if (s == NULL) {
+ if (s == nullptr) {
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.c b/src/core/lib/support/string_posix.cc
index e768faf739..8b818e39b9 100644
--- a/src/core/lib/support/string_posix.c
+++ b/src/core/lib/support/string_posix.cc
@@ -25,8 +25,9 @@
#include <string.h>
#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];
@@ -37,13 +38,13 @@ int gpr_asprintf(char **strp, const char *format, ...) {
ret = vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
if (ret < 0) {
- *strp = NULL;
+ *strp = nullptr;
return -1;
}
/* 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)) == nullptr) {
/* This shouldn't happen, because gpr_malloc() calls abort(). */
return -1;
}
@@ -64,7 +65,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
/* This should never happen. */
gpr_free(*strp);
- *strp = NULL;
+ *strp = nullptr;
return -1;
}
diff --git a/src/core/lib/support/string_util_windows.c b/src/core/lib/support/string_util_windows.cc
index 2a03404448..e2b386be55 100644
--- a/src/core/lib/support/string_util_windows.c
+++ b/src/core/lib/support/string_util_windows.cc
@@ -26,15 +26,18 @@
anything else, especially strsafe.h. */
#include <wchar.h>
+#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <strsafe.h>
#include <grpc/support/alloc.h>
+#include <grpc/support/log_windows.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/support/string.h"
+#include "src/core/lib/support/string_windows.h"
#if defined UNICODE || defined _UNICODE
LPTSTR
@@ -42,7 +45,7 @@ gpr_char_to_tchar(LPCSTR input) {
LPTSTR ret;
int needed = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0);
if (needed <= 0) return NULL;
- ret = gpr_malloc((unsigned)needed * sizeof(TCHAR));
+ ret = (LPTSTR)gpr_malloc((unsigned)needed * sizeof(TCHAR));
MultiByteToWideChar(CP_UTF8, 0, input, -1, ret, needed);
return ret;
}
@@ -52,19 +55,19 @@ gpr_tchar_to_char(LPCTSTR input) {
LPSTR ret;
int needed = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
if (needed <= 0) return NULL;
- ret = gpr_malloc((unsigned)needed);
+ ret = (LPSTR)gpr_malloc((unsigned)needed);
WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, needed, NULL, NULL);
return ret;
}
#else
-char *gpr_tchar_to_char(LPTSTR input) { return gpr_strdup(input); }
+LPSTR gpr_tchar_to_char(LPCTSTR input) { return (LPSTR)gpr_strdup(input); }
-char *gpr_char_to_tchar(LPTSTR input) { return 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.c b/src/core/lib/support/string_windows.cc
index 50278d9559..ceb78f0054 100644
--- a/src/core/lib/support/string_windows.c
+++ b/src/core/lib/support/string_windows.cc
@@ -27,10 +27,11 @@
#include <string.h>
#include <grpc/support/alloc.h>
+#include <grpc/support/string_util.h>
#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;
@@ -46,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 = 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_windows.h b/src/core/lib/support/string_windows.h
index 7c7f31e7aa..6771647581 100644
--- a/src/core/lib/support/string_windows.h
+++ b/src/core/lib/support/string_windows.h
@@ -21,6 +21,10 @@
#include <grpc/support/port_platform.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifdef GPR_WINDOWS
/* These allocate new strings using gpr_malloc to convert from and to utf-8. */
@@ -29,4 +33,8 @@ LPSTR gpr_tchar_to_char(LPCTSTR input);
#endif /* GPR_WINDOWS */
+#ifdef __cplusplus
+}
+#endif
+
#endif /* GRPC_CORE_LIB_SUPPORT_STRING_WINDOWS_H */
diff --git a/src/core/lib/support/subprocess_posix.c b/src/core/lib/support/subprocess_posix.cc
index af75162ee9..dc046b6499 100644
--- a/src/core/lib/support/subprocess_posix.c
+++ b/src/core/lib/support/subprocess_posix.cc
@@ -41,33 +41,33 @@ 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;
+ return nullptr;
} 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[argc] = NULL;
+ exec_args = (char**)gpr_malloc(((size_t)argc + 1) * sizeof(char*));
+ memcpy(exec_args, argv, (size_t)argc * sizeof(char*));
+ exec_args[argc] = nullptr;
execv(exec_args[0], exec_args);
/* if we reach here, an error has occurred */
gpr_log(GPR_ERROR, "execv '%s' failed: %s", exec_args[0], strerror(errno));
_exit(1);
- return NULL;
+ return nullptr;
} 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.c b/src/core/lib/support/subprocess_windows.cc
index 7412f8d344..dcdafb5a63 100644
--- a/src/core/lib/support/subprocess_windows.c
+++ 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_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.c b/src/core/lib/support/sync.cc
index 994dcb0e14..347ffcd00e 100644
--- a/src/core/lib/support/sync.c
+++ b/src/core/lib/support/sync.cc
@@ -45,47 +45,47 @@ 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);
gpr_cv_broadcast(&s->cv);
gpr_mu_unlock(&s->mu);
- GPR_ASSERT(value != NULL);
+ GPR_ASSERT(value != nullptr);
}
-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);
- if (result == NULL) {
- struct sync_array_s *s = hash(ev);
+void* gpr_event_wait(gpr_event* ev, gpr_timespec abs_deadline) {
+ void* result = (void*)gpr_atm_acq_load(&ev->state);
+ if (result == nullptr) {
+ struct sync_array_s* s = hash(ev);
gpr_mu_lock(&s->mu);
do {
- result = (void *)gpr_atm_acq_load(&ev->state);
- } while (result == NULL && !gpr_cv_wait(&s->cv, &s->mu, abs_deadline));
+ result = (void*)gpr_atm_acq_load(&ev->state);
+ } while (result == nullptr && !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_posix.c b/src/core/lib/support/sync_posix.cc
index 62d800b18c..dfdd233bf4 100644
--- a/src/core/lib/support/sync_posix.c
+++ b/src/core/lib/support/sync_posix.cc
@@ -33,7 +33,9 @@ gpr_atm gpr_counter_atm_cas = 0;
gpr_atm gpr_counter_atm_add = 0;
#endif
-void gpr_mu_init(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_init(mu, NULL) == 0); }
+void gpr_mu_init(gpr_mu* mu) {
+ GPR_ASSERT(pthread_mutex_init(mu, nullptr) == 0);
+}
void gpr_mu_destroy(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_destroy(mu) == 0); }
@@ -63,7 +65,9 @@ int gpr_mu_trylock(gpr_mu* mu) {
/*----------------------------------------*/
-void gpr_cv_init(gpr_cv* cv) { GPR_ASSERT(pthread_cond_init(cv, NULL) == 0); }
+void gpr_cv_init(gpr_cv* cv) {
+ GPR_ASSERT(pthread_cond_init(cv, nullptr) == 0);
+}
void gpr_cv_destroy(gpr_cv* cv) { GPR_ASSERT(pthread_cond_destroy(cv) == 0); }
diff --git a/src/core/lib/support/sync_windows.c b/src/core/lib/support/sync_windows.cc
index 008c5aecba..7cd41633d5 100644
--- a/src/core/lib/support/sync_windows.c
+++ 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 = 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.c b/src/core/lib/support/thd.cc
index ca62615d65..ca62615d65 100644
--- a/src/core/lib/support/thd.c
+++ b/src/core/lib/support/thd.cc
diff --git a/src/core/lib/support/thd_posix.c b/src/core/lib/support/thd_posix.cc
index 219297c046..c2a4f4198f 100644
--- a/src/core/lib/support/thd_posix.c
+++ b/src/core/lib/support/thd_posix.cc
@@ -39,31 +39,31 @@ static int g_thread_count;
static int g_awaiting_threads;
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 */
};
static void inc_thd_count();
static void dec_thd_count();
/* 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);
dec_thd_count();
- return NULL;
+ return nullptr;
}
-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));
- GPR_ASSERT(a != NULL);
+ struct thd_arg* a = (struct thd_arg*)malloc(sizeof(*a));
+ GPR_ASSERT(a != nullptr);
a->body = thd_body;
a->arg = arg;
inc_thd_count();
@@ -89,7 +89,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)pthread_self(); }
-void gpr_thd_join(gpr_thd_id t) { pthread_join((pthread_t)t, NULL); }
+void gpr_thd_join(gpr_thd_id t) { pthread_join((pthread_t)t, nullptr); }
/*****************************************
* Only used when fork support is enabled
diff --git a/src/core/lib/support/thd_windows.c b/src/core/lib/support/thd_windows.cc
index 4c6013bf33..0875c2f03e 100644
--- a/src/core/lib/support/thd_windows.c
+++ b/src/core/lib/support/thd_windows.cc
@@ -36,16 +36,16 @@
#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);
}
@@ -53,8 +53,8 @@ static void destroy_thread(struct thd_info *t) {
void gpr_thd_init(void) {}
/* 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);
@@ -65,10 +65,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 = gpr_malloc(sizeof(*info));
+ struct thd_info* info = (struct thd_info*)gpr_malloc(sizeof(*info));
info->body = thd_body;
info->arg = arg;
*t = 0;
@@ -95,7 +95,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.c b/src/core/lib/support/time.cc
index 6903674d75..6903674d75 100644
--- a/src/core/lib/support/time.c
+++ b/src/core/lib/support/time.cc
diff --git a/src/core/lib/support/time_posix.c b/src/core/lib/support/time_posix.cc
index 3ead40d807..7f65205800 100644
--- a/src/core/lib/support/time_posix.c
+++ b/src/core/lib/support/time_posix.cc
@@ -30,7 +30,6 @@
#include <grpc/support/atm.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
-#include "src/core/lib/support/block_annotate.h"
static struct timespec timespec_from_gpr(gpr_timespec gts) {
struct timespec rv;
@@ -43,7 +42,7 @@ static struct timespec timespec_from_gpr(gpr_timespec gts) {
return rv;
}
-#if _POSIX_TIMERS > 0
+#if _POSIX_TIMERS > 0 || defined(__OpenBSD__)
static gpr_timespec gpr_from_timespec(struct timespec ts,
gpr_clock_type clock_type) {
/*
@@ -82,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>
@@ -128,7 +127,9 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
}
#endif
+extern "C" {
gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type) = now_impl;
+}
#ifdef GPR_LOW_LEVEL_COUNTERS
gpr_atm gpr_now_call_count;
@@ -157,9 +158,7 @@ void gpr_sleep_until(gpr_timespec until) {
delta = gpr_time_sub(until, now);
delta_ts = timespec_from_gpr(delta);
- GRPC_SCHEDULING_START_BLOCKING_REGION;
- ns_result = nanosleep(&delta_ts, NULL);
- GRPC_SCHEDULING_END_BLOCKING_REGION;
+ ns_result = nanosleep(&delta_ts, nullptr);
if (ns_result == 0) {
break;
}
diff --git a/src/core/lib/support/time_precise.c b/src/core/lib/support/time_precise.cc
index 6ce19e53cc..b7372df1b8 100644
--- a/src/core/lib/support/time_precise.c
+++ b/src/core/lib/support/time_precise.cc
@@ -20,9 +20,11 @@
#include <grpc/support/time.h>
#include <stdio.h>
+#include "src/core/lib/support/time_precise.h"
+
#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;
@@ -30,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;
@@ -54,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);
@@ -67,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 aa28d6d7c4..3befda3d86 100644
--- a/src/core/lib/support/time_precise.h
+++ b/src/core/lib/support/time_precise.h
@@ -21,7 +21,15 @@
#include <grpc/support/time.h>
+#ifdef __cplusplus
+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
+}
+#endif
#endif /* GRPC_CORE_LIB_SUPPORT_TIME_PRECISE_H */
diff --git a/src/core/lib/support/time_windows.c b/src/core/lib/support/time_windows.cc
index 40df3761c0..08c1b22964 100644
--- a/src/core/lib/support/time_windows.c
+++ b/src/core/lib/support/time_windows.cc
@@ -28,7 +28,6 @@
#include <process.h>
#include <sys/timeb.h>
-#include "src/core/lib/support/block_annotate.h"
#include "src/core/lib/support/time_precise.h"
static LARGE_INTEGER g_start_time;
@@ -69,7 +68,9 @@ static gpr_timespec now_impl(gpr_clock_type clock) {
return now_tv;
}
+extern "C" {
gpr_timespec (*gpr_now_impl)(gpr_clock_type clock_type) = now_impl;
+}
gpr_timespec gpr_now(gpr_clock_type clock_type) {
return gpr_now_impl(clock_type);
@@ -92,9 +93,7 @@ void gpr_sleep_until(gpr_timespec until) {
sleep_millis =
delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS;
GPR_ASSERT((sleep_millis >= 0) && (sleep_millis <= INT_MAX));
- GRPC_SCHEDULING_START_BLOCKING_REGION;
Sleep((DWORD)sleep_millis);
- GRPC_SCHEDULING_END_BLOCKING_REGION;
}
}
diff --git a/src/core/lib/support/tls_pthread.c b/src/core/lib/support/tls_pthread.cc
index 9ebee577fe..ebeef2a8c2 100644
--- a/src/core/lib/support/tls_pthread.c
+++ 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.c b/src/core/lib/support/tmpfile_msys.cc
index 614c0a4a18..430e866629 100644
--- a/src/core/lib/support/tmpfile_msys.c
+++ 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.c b/src/core/lib/support/tmpfile_posix.cc
index 7ad3af0a57..79c5c68874 100644
--- a/src/core/lib/support/tmpfile_posix.c
+++ b/src/core/lib/support/tmpfile_posix.cc
@@ -33,15 +33,15 @@
#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 = nullptr;
+ char* filename_template;
int fd;
- if (tmp_filename != NULL) *tmp_filename = NULL;
+ if (tmp_filename != nullptr) *tmp_filename = nullptr;
gpr_asprintf(&filename_template, "/tmp/%s_XXXXXX", prefix);
- GPR_ASSERT(filename_template != NULL);
+ GPR_ASSERT(filename_template != nullptr);
fd = mkstemp(filename_template);
if (fd == -1) {
@@ -50,7 +50,7 @@ FILE *gpr_tmpfile(const char *prefix, char **tmp_filename) {
goto end;
}
result = fdopen(fd, "w+");
- if (result == NULL) {
+ if (result == nullptr) {
gpr_log(GPR_ERROR, "Could not open file %s from fd %d (error = %s).",
filename_template, fd, strerror(errno));
unlink(filename_template);
@@ -59,7 +59,7 @@ FILE *gpr_tmpfile(const char *prefix, char **tmp_filename) {
}
end:
- if (result != NULL && tmp_filename != NULL) {
+ if (result != nullptr && tmp_filename != nullptr) {
*tmp_filename = filename_template;
} else {
gpr_free(filename_template);
diff --git a/src/core/lib/support/tmpfile_windows.c b/src/core/lib/support/tmpfile_windows.cc
index 47b4510a72..2b10bcde43 100644
--- a/src/core/lib/support/tmpfile_windows.c
+++ 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.c b/src/core/lib/support/wrap_memcpy.cc
index cff056dc3b..9b8608e056 100644
--- a/src/core/lib/support/wrap_memcpy.c
+++ b/src/core/lib/support/wrap_memcpy.cc
@@ -26,15 +26,17 @@
* Enable by setting LDFLAGS=-Wl,-wrap,memcpy when linking.
*/
+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
#endif
+}