|
|
|
@ -138,6 +138,10 @@ static void bpstep_sched(grpc_exec_ctx *exec_ctx, |
|
|
|
|
|
|
|
|
|
/* returns true if all allocations are completed */ |
|
|
|
|
static bool bpalloc(grpc_exec_ctx *exec_ctx, grpc_buffer_pool *buffer_pool) { |
|
|
|
|
if (buffer_pool->free_pool <= 0) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_buffer_user *buffer_user; |
|
|
|
|
while ((buffer_user = |
|
|
|
|
bulist_pop(buffer_pool, GRPC_BULIST_AWAITING_ALLOCATION))) { |
|
|
|
@ -242,6 +246,25 @@ static void bu_post_destructive_reclaimer(grpc_exec_ctx *exec_ctx, void *bu, |
|
|
|
|
bulist_add_tail(buffer_user, GRPC_BULIST_RECLAIMER_DESTRUCTIVE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
int64_t size; |
|
|
|
|
grpc_buffer_pool *buffer_pool; |
|
|
|
|
grpc_closure closure; |
|
|
|
|
} bp_resize_args; |
|
|
|
|
|
|
|
|
|
static void bp_resize(grpc_exec_ctx *exec_ctx, void *args, grpc_error *error) { |
|
|
|
|
bp_resize_args *a = args; |
|
|
|
|
int64_t delta = a->size - a->buffer_pool->size; |
|
|
|
|
a->buffer_pool->size += delta; |
|
|
|
|
a->buffer_pool->free_pool += delta; |
|
|
|
|
if (delta < 0 && a->buffer_pool->free_pool < 0) { |
|
|
|
|
bpstep_sched(exec_ctx, a->buffer_pool); |
|
|
|
|
} else if (delta > 0 && |
|
|
|
|
!bulist_empty(a->buffer_pool, GRPC_BULIST_AWAITING_ALLOCATION)) { |
|
|
|
|
bpstep_sched(exec_ctx, a->buffer_pool); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* grpc_buffer_pool api |
|
|
|
|
*/ |
|
|
|
@ -279,6 +302,17 @@ void grpc_buffer_pool_ref(grpc_buffer_pool *buffer_pool) { |
|
|
|
|
grpc_buffer_pool_internal_ref(buffer_pool); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void grpc_buffer_pool_resize(grpc_buffer_pool *buffer_pool, size_t size) { |
|
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
|
bp_resize_args *a = gpr_malloc(sizeof(*a)); |
|
|
|
|
a->buffer_pool = grpc_buffer_pool_internal_ref(buffer_pool); |
|
|
|
|
a->size = (int64_t)size; |
|
|
|
|
grpc_closure_init(&a->closure, bp_resize, a); |
|
|
|
|
grpc_combiner_execute(&exec_ctx, buffer_pool->combiner, &a->closure, |
|
|
|
|
GRPC_ERROR_NONE); |
|
|
|
|
grpc_exec_ctx_finish(&exec_ctx); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* grpc_buffer_user api |
|
|
|
|
*/ |
|
|
|
|