aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/slice/slice_intern.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/slice/slice_intern.cc')
-rw-r--r--src/core/lib/slice/slice_intern.cc64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc
index 1ea9a2aa67..50a0eba49c 100644
--- a/src/core/lib/slice/slice_intern.cc
+++ b/src/core/lib/slice/slice_intern.cc
@@ -43,12 +43,12 @@ typedef struct interned_slice_refcount {
size_t length;
gpr_atm refcnt;
uint32_t hash;
- struct interned_slice_refcount *bucket_next;
+ struct interned_slice_refcount* bucket_next;
} interned_slice_refcount;
typedef struct slice_shard {
gpr_mu mu;
- interned_slice_refcount **strs;
+ interned_slice_refcount** strs;
size_t count;
size_t capacity;
} slice_shard;
@@ -69,17 +69,17 @@ static static_metadata_hash_ent
static uint32_t max_static_metadata_hash_probe;
static uint32_t static_metadata_hash_values[GRPC_STATIC_MDSTR_COUNT];
-static void interned_slice_ref(void *p) {
- interned_slice_refcount *s = (interned_slice_refcount *)p;
+static void interned_slice_ref(void* p) {
+ interned_slice_refcount* s = (interned_slice_refcount*)p;
GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) > 0);
}
-static void interned_slice_destroy(interned_slice_refcount *s) {
- slice_shard *shard = &g_shards[SHARD_IDX(s->hash)];
+static void interned_slice_destroy(interned_slice_refcount* s) {
+ slice_shard* shard = &g_shards[SHARD_IDX(s->hash)];
gpr_mu_lock(&shard->mu);
GPR_ASSERT(0 == gpr_atm_no_barrier_load(&s->refcnt));
- interned_slice_refcount **prev_next;
- interned_slice_refcount *cur;
+ interned_slice_refcount** prev_next;
+ interned_slice_refcount* cur;
for (prev_next = &shard->strs[TABLE_IDX(s->hash, shard->capacity)],
cur = *prev_next;
cur != s; prev_next = &cur->bucket_next, cur = cur->bucket_next)
@@ -90,24 +90,24 @@ static void interned_slice_destroy(interned_slice_refcount *s) {
gpr_mu_unlock(&shard->mu);
}
-static void interned_slice_unref(grpc_exec_ctx *exec_ctx, void *p) {
- interned_slice_refcount *s = (interned_slice_refcount *)p;
+static void interned_slice_unref(grpc_exec_ctx* exec_ctx, void* p) {
+ interned_slice_refcount* s = (interned_slice_refcount*)p;
if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) {
interned_slice_destroy(s);
}
}
-static void interned_slice_sub_ref(void *p) {
- interned_slice_ref(((char *)p) - offsetof(interned_slice_refcount, sub));
+static void interned_slice_sub_ref(void* p) {
+ interned_slice_ref(((char*)p) - offsetof(interned_slice_refcount, sub));
}
-static void interned_slice_sub_unref(grpc_exec_ctx *exec_ctx, void *p) {
+static void interned_slice_sub_unref(grpc_exec_ctx* exec_ctx, void* p) {
interned_slice_unref(exec_ctx,
- ((char *)p) - offsetof(interned_slice_refcount, sub));
+ ((char*)p) - offsetof(interned_slice_refcount, sub));
}
static uint32_t interned_slice_hash(grpc_slice slice) {
- interned_slice_refcount *s = (interned_slice_refcount *)slice.refcount;
+ interned_slice_refcount* s = (interned_slice_refcount*)slice.refcount;
return s->hash;
}
@@ -122,16 +122,16 @@ static const grpc_slice_refcount_vtable interned_slice_sub_vtable = {
interned_slice_sub_ref, interned_slice_sub_unref,
grpc_slice_default_eq_impl, grpc_slice_default_hash_impl};
-static void grow_shard(slice_shard *shard) {
+static void grow_shard(slice_shard* shard) {
size_t capacity = shard->capacity * 2;
size_t i;
- interned_slice_refcount **strtab;
+ interned_slice_refcount** strtab;
interned_slice_refcount *s, *next;
GPR_TIMER_BEGIN("grow_strtab", 0);
- strtab = (interned_slice_refcount **)gpr_zalloc(
- sizeof(interned_slice_refcount *) * capacity);
+ strtab = (interned_slice_refcount**)gpr_zalloc(
+ sizeof(interned_slice_refcount*) * capacity);
for (i = 0; i < shard->capacity; i++) {
for (s = shard->strs[i]; s; s = next) {
@@ -149,10 +149,10 @@ static void grow_shard(slice_shard *shard) {
GPR_TIMER_END("grow_strtab", 0);
}
-static grpc_slice materialize(interned_slice_refcount *s) {
+static grpc_slice materialize(interned_slice_refcount* s) {
grpc_slice slice;
slice.refcount = &s->base;
- slice.data.refcounted.bytes = (uint8_t *)(s + 1);
+ slice.data.refcounted.bytes = (uint8_t*)(s + 1);
slice.data.refcounted.length = s->length;
return slice;
}
@@ -176,7 +176,7 @@ uint32_t grpc_slice_hash(grpc_slice s) {
}
grpc_slice grpc_slice_maybe_static_intern(grpc_slice slice,
- bool *returned_slice_is_different) {
+ bool* returned_slice_is_different) {
if (GRPC_IS_STATIC_METADATA_STRING(slice)) {
return slice;
}
@@ -218,8 +218,8 @@ grpc_slice grpc_slice_intern(grpc_slice slice) {
}
}
- interned_slice_refcount *s;
- slice_shard *shard = &g_shards[SHARD_IDX(hash)];
+ interned_slice_refcount* s;
+ slice_shard* shard = &g_shards[SHARD_IDX(hash)];
gpr_mu_lock(&shard->mu);
@@ -244,8 +244,8 @@ grpc_slice grpc_slice_intern(grpc_slice slice) {
/* not found: create a new string */
/* string data goes after the internal_string header */
- s = (interned_slice_refcount *)gpr_malloc(sizeof(*s) +
- GRPC_SLICE_LENGTH(slice));
+ s = (interned_slice_refcount*)gpr_malloc(sizeof(*s) +
+ GRPC_SLICE_LENGTH(slice));
gpr_atm_rel_store(&s->refcnt, 1);
s->length = GRPC_SLICE_LENGTH(slice);
s->hash = hash;
@@ -279,12 +279,12 @@ void grpc_slice_intern_init(void) {
g_hash_seed = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec;
}
for (size_t i = 0; i < SHARD_COUNT; i++) {
- slice_shard *shard = &g_shards[i];
+ slice_shard* shard = &g_shards[i];
gpr_mu_init(&shard->mu);
shard->count = 0;
shard->capacity = INITIAL_SHARD_CAPACITY;
- shard->strs = (interned_slice_refcount **)gpr_zalloc(sizeof(*shard->strs) *
- shard->capacity);
+ shard->strs = (interned_slice_refcount**)gpr_zalloc(sizeof(*shard->strs) *
+ shard->capacity);
}
for (size_t i = 0; i < GPR_ARRAY_SIZE(static_metadata_hash); i++) {
static_metadata_hash[i].hash = 0;
@@ -311,16 +311,16 @@ void grpc_slice_intern_init(void) {
void grpc_slice_intern_shutdown(void) {
for (size_t i = 0; i < SHARD_COUNT; i++) {
- slice_shard *shard = &g_shards[i];
+ slice_shard* shard = &g_shards[i];
gpr_mu_destroy(&shard->mu);
/* TODO(ctiller): GPR_ASSERT(shard->count == 0); */
if (shard->count != 0) {
gpr_log(GPR_DEBUG, "WARNING: %" PRIuPTR " metadata strings were leaked",
shard->count);
for (size_t j = 0; j < shard->capacity; j++) {
- for (interned_slice_refcount *s = shard->strs[j]; s;
+ for (interned_slice_refcount* s = shard->strs[j]; s;
s = s->bucket_next) {
- char *text =
+ char* text =
grpc_dump_slice(materialize(s), GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "LEAKED: %s", text);
gpr_free(text);