diff options
author | 2017-12-06 09:05:05 -0800 | |
---|---|---|
committer | 2017-12-06 09:05:05 -0800 | |
commit | ad4d2dde0052efbbf49d64b0843c45f0381cfeb3 (patch) | |
tree | 6a657f8c6179d873b34505cdc24bce9462ca68eb /src/core/lib/slice | |
parent | a3df36cc2505a89c2f481eea4a66a87b3002844a (diff) |
Revert "All instances of exec_ctx being passed around in src/core removed"
Diffstat (limited to 'src/core/lib/slice')
-rw-r--r-- | src/core/lib/slice/b64.cc | 11 | ||||
-rw-r--r-- | src/core/lib/slice/b64.h | 7 | ||||
-rw-r--r-- | src/core/lib/slice/slice.cc | 17 | ||||
-rw-r--r-- | src/core/lib/slice/slice_buffer.cc | 27 | ||||
-rw-r--r-- | src/core/lib/slice/slice_hash_table.cc | 12 | ||||
-rw-r--r-- | src/core/lib/slice/slice_hash_table.h | 6 | ||||
-rw-r--r-- | src/core/lib/slice/slice_intern.cc | 7 | ||||
-rw-r--r-- | src/core/lib/slice/slice_internal.h | 11 |
8 files changed, 57 insertions, 41 deletions
diff --git a/src/core/lib/slice/b64.cc b/src/core/lib/slice/b64.cc index f36b13ef1b..fe7a86ef84 100644 --- a/src/core/lib/slice/b64.cc +++ b/src/core/lib/slice/b64.cc @@ -122,8 +122,9 @@ void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size, result[current - result] = '\0'; } -grpc_slice grpc_base64_decode(const char* b64, int url_safe) { - return grpc_base64_decode_with_len(b64, strlen(b64), url_safe); +grpc_slice grpc_base64_decode(grpc_exec_ctx* exec_ctx, const char* b64, + int url_safe) { + return grpc_base64_decode_with_len(exec_ctx, b64, strlen(b64), url_safe); } static void decode_one_char(const unsigned char* codes, unsigned char* result, @@ -184,8 +185,8 @@ static int decode_group(const unsigned char* codes, size_t num_codes, return 1; } -grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, - int url_safe) { +grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx* exec_ctx, const char* b64, + size_t b64_len, int url_safe) { grpc_slice result = GRPC_SLICE_MALLOC(b64_len); unsigned char* current = GRPC_SLICE_START_PTR(result); size_t result_size = 0; @@ -230,6 +231,6 @@ grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, return result; fail: - grpc_slice_unref_internal(result); + grpc_slice_unref_internal(exec_ctx, result); return grpc_empty_slice(); } diff --git a/src/core/lib/slice/b64.h b/src/core/lib/slice/b64.h index 17e7306303..f86c1d9901 100644 --- a/src/core/lib/slice/b64.h +++ b/src/core/lib/slice/b64.h @@ -40,10 +40,11 @@ void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size, /* Decodes data according to the base64 specification. Returns an empty slice in case of failure. */ -grpc_slice grpc_base64_decode(const char* b64, int url_safe); +grpc_slice grpc_base64_decode(grpc_exec_ctx* exec_ctx, const char* b64, + int url_safe); /* Same as above except that the length is provided by the caller. */ -grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, - int url_safe); +grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx* exec_ctx, const char* b64, + size_t b64_len, int url_safe); #endif /* GRPC_CORE_LIB_SLICE_B64_H */ diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 1eb15290eb..bbaf87ba23 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -54,9 +54,9 @@ grpc_slice grpc_slice_ref_internal(grpc_slice slice) { return slice; } -void grpc_slice_unref_internal(grpc_slice slice) { +void grpc_slice_unref_internal(grpc_exec_ctx* exec_ctx, grpc_slice slice) { if (slice.refcount) { - slice.refcount->vtable->unref(slice.refcount); + slice.refcount->vtable->unref(exec_ctx, slice.refcount); } } @@ -67,14 +67,15 @@ grpc_slice grpc_slice_ref(grpc_slice slice) { /* Public API */ void grpc_slice_unref(grpc_slice slice) { - grpc_core::ExecCtx exec_ctx; - grpc_slice_unref_internal(slice); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_unref_internal(&exec_ctx, slice); + grpc_exec_ctx_finish(&exec_ctx); } /* grpc_slice_from_static_string support structure - a refcount that does nothing */ static void noop_ref(void* unused) {} -static void noop_unref(void* unused) {} +static void noop_unref(grpc_exec_ctx* exec_ctx, void* unused) {} static const grpc_slice_refcount_vtable noop_refcount_vtable = { noop_ref, noop_unref, grpc_slice_default_eq_impl, @@ -108,7 +109,7 @@ static void new_slice_ref(void* p) { gpr_ref(&r->refs); } -static void new_slice_unref(void* p) { +static void new_slice_unref(grpc_exec_ctx* exec_ctx, void* p) { new_slice_refcount* r = (new_slice_refcount*)p; if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data); @@ -158,7 +159,7 @@ static void new_with_len_ref(void* p) { gpr_ref(&r->refs); } -static void new_with_len_unref(void* p) { +static void new_with_len_unref(grpc_exec_ctx* exec_ctx, void* p) { new_with_len_slice_refcount* r = (new_with_len_slice_refcount*)p; if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data, r->user_length); @@ -209,7 +210,7 @@ static void malloc_ref(void* p) { gpr_ref(&r->refs); } -static void malloc_unref(void* p) { +static void malloc_unref(grpc_exec_ctx* exec_ctx, void* p) { malloc_refcount* r = (malloc_refcount*)p; if (gpr_unref(&r->refs)) { gpr_free(r); diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 33ec2af683..5db54dad91 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -65,16 +65,18 @@ void grpc_slice_buffer_init(grpc_slice_buffer* sb) { sb->base_slices = sb->slices = sb->inlined; } -void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb) { - grpc_slice_buffer_reset_and_unref_internal(sb); +void grpc_slice_buffer_destroy_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb) { + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, sb); if (sb->base_slices != sb->inlined) { gpr_free(sb->base_slices); } } void grpc_slice_buffer_destroy(grpc_slice_buffer* sb) { - grpc_core::ExecCtx exec_ctx; - grpc_slice_buffer_destroy_internal(sb); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_buffer_destroy_internal(&exec_ctx, sb); + grpc_exec_ctx_finish(&exec_ctx); } uint8_t* grpc_slice_buffer_tiny_add(grpc_slice_buffer* sb, size_t n) { @@ -161,10 +163,11 @@ void grpc_slice_buffer_pop(grpc_slice_buffer* sb) { } } -void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb) { +void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb) { size_t i; for (i = 0; i < sb->count; i++) { - grpc_slice_unref_internal(sb->slices[i]); + grpc_slice_unref_internal(exec_ctx, sb->slices[i]); } sb->count = 0; @@ -172,8 +175,9 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb) { } void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) { - grpc_core::ExecCtx exec_ctx; - grpc_slice_buffer_reset_and_unref_internal(sb); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, sb); + grpc_exec_ctx_finish(&exec_ctx); } void grpc_slice_buffer_swap(grpc_slice_buffer* a, grpc_slice_buffer* b) { @@ -285,7 +289,8 @@ void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer* src, size_t n, slice_buffer_move_first_maybe_ref(src, n, dst, false); } -void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n, +void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* src, size_t n, void* dst) { char* dstp = (char*)dst; GPR_ASSERT(src->length >= n); @@ -300,13 +305,13 @@ void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n, n = 0; } else if (slice_len == n) { memcpy(dstp, GRPC_SLICE_START_PTR(slice), n); - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); n = 0; } else { memcpy(dstp, GRPC_SLICE_START_PTR(slice), slice_len); dstp += slice_len; n -= slice_len; - grpc_slice_unref_internal(slice); + grpc_slice_unref_internal(exec_ctx, slice); } } } diff --git a/src/core/lib/slice/slice_hash_table.cc b/src/core/lib/slice/slice_hash_table.cc index 89340eff84..8f8e5a6b34 100644 --- a/src/core/lib/slice/slice_hash_table.cc +++ b/src/core/lib/slice/slice_hash_table.cc @@ -27,7 +27,7 @@ struct grpc_slice_hash_table { gpr_refcount refs; - void (*destroy_value)(void* value); + void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value); int (*value_cmp)(void* a, void* b); size_t size; size_t max_num_probes; @@ -58,7 +58,8 @@ static void grpc_slice_hash_table_add(grpc_slice_hash_table* table, grpc_slice_hash_table* grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry* entries, - void (*destroy_value)(void* value), int (*value_cmp)(void* a, void* b)) { + void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value), + int (*value_cmp)(void* a, void* b)) { grpc_slice_hash_table* table = (grpc_slice_hash_table*)gpr_zalloc(sizeof(*table)); gpr_ref_init(&table->refs, 1); @@ -80,13 +81,14 @@ grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table) { return table; } -void grpc_slice_hash_table_unref(grpc_slice_hash_table* table) { +void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, + grpc_slice_hash_table* table) { if (table != nullptr && gpr_unref(&table->refs)) { for (size_t i = 0; i < table->size; ++i) { grpc_slice_hash_table_entry* entry = &table->entries[i]; if (!is_empty(entry)) { - grpc_slice_unref_internal(entry->key); - table->destroy_value(entry->value); + grpc_slice_unref_internal(exec_ctx, entry->key); + table->destroy_value(exec_ctx, entry->value); } } gpr_free(table->entries); diff --git a/src/core/lib/slice/slice_hash_table.h b/src/core/lib/slice/slice_hash_table.h index db69da662a..85102bd67d 100644 --- a/src/core/lib/slice/slice_hash_table.h +++ b/src/core/lib/slice/slice_hash_table.h @@ -46,10 +46,12 @@ typedef struct grpc_slice_hash_table_entry { will be used. */ grpc_slice_hash_table* grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry* entries, - void (*destroy_value)(void* value), int (*value_cmp)(void* a, void* b)); + void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value), + int (*value_cmp)(void* a, void* b)); grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table); -void grpc_slice_hash_table_unref(grpc_slice_hash_table* table); +void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, + grpc_slice_hash_table* table); /** Returns the value from \a table associated with \a key. Returns NULL if \a key is not found. */ diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc index c578c6d9de..e8949135c0 100644 --- a/src/core/lib/slice/slice_intern.cc +++ b/src/core/lib/slice/slice_intern.cc @@ -90,7 +90,7 @@ static void interned_slice_destroy(interned_slice_refcount* s) { gpr_mu_unlock(&shard->mu); } -static void interned_slice_unref(void* 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); @@ -101,8 +101,9 @@ static void interned_slice_sub_ref(void* p) { interned_slice_ref(((char*)p) - offsetof(interned_slice_refcount, sub)); } -static void interned_slice_sub_unref(void* p) { - interned_slice_unref(((char*)p) - offsetof(interned_slice_refcount, sub)); +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)); } static uint32_t interned_slice_hash(grpc_slice slice) { diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 4e9ab80261..ed0070d375 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -25,11 +25,14 @@ #include "src/core/lib/iomgr/exec_ctx.h" grpc_slice grpc_slice_ref_internal(grpc_slice slice); -void grpc_slice_unref_internal(grpc_slice slice); -void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb); -void grpc_slice_buffer_partial_unref_internal(grpc_slice_buffer* sb, +void grpc_slice_unref_internal(grpc_exec_ctx* exec_ctx, grpc_slice slice); +void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb); +void grpc_slice_buffer_partial_unref_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb, size_t idx); -void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb); +void grpc_slice_buffer_destroy_internal(grpc_exec_ctx* exec_ctx, + grpc_slice_buffer* sb); /* Check if a slice is interned */ bool grpc_slice_is_interned(grpc_slice slice); |