Skip to content
Snippets Groups Projects
Commit fe4f0012 authored by Craig Tiller's avatar Craig Tiller
Browse files

Add resize test

parent 0b13fcda
No related branches found
No related tags found
No related merge requests found
......@@ -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
*/
......
......@@ -42,10 +42,18 @@ static void test_no_op(void) {
grpc_buffer_pool_unref(grpc_buffer_pool_create());
}
static void test_resize_then_destroy(void) {
gpr_log(GPR_DEBUG, "** test_resize_then_destroy **");
grpc_buffer_pool *p = grpc_buffer_pool_create();
grpc_buffer_pool_resize(p, 1024 * 1024);
grpc_buffer_pool_unref(p);
}
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
grpc_init();
test_no_op();
test_resize_then_destroy();
grpc_shutdown();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment