diff --git a/client/tarantool_checksum/tc_space.c b/client/tarantool_checksum/tc_space.c index b3af886174c922e943a9fb042a7f41058e73bc75..1d4ea1310dd34711ed9fe3176300fe76fccb0436 100644 --- a/client/tarantool_checksum/tc_space.c +++ b/client/tarantool_checksum/tc_space.c @@ -43,7 +43,7 @@ #include "tc_space.h" int tc_space_init(struct tc_spaces *s) { - s->t = mh_u32ptr_init(); + s->t = mh_u32ptr_new(); if (s->t == NULL) return -1; return 0; @@ -75,13 +75,13 @@ void tc_space_free(struct tc_spaces *s) pos++; } - mh_pk_destroy(space->hash_log); - mh_pk_destroy(space->hash_snap); + mh_pk_delete(space->hash_log); + mh_pk_delete(space->hash_snap); free(space->pk.fields); free(space); } - mh_u32ptr_destroy(s->t); + mh_u32ptr_delete(s->t); } struct tc_space *tc_space_create(struct tc_spaces *s, uint32_t id) { @@ -90,8 +90,8 @@ struct tc_space *tc_space_create(struct tc_spaces *s, uint32_t id) { return NULL; memset(space, 0, sizeof(struct tc_space)); space->id = id; - space->hash_log = mh_pk_init(); - space->hash_snap = mh_pk_init(); + space->hash_log = mh_pk_new(); + space->hash_snap = mh_pk_new(); int ret; const struct mh_u32ptr_node_t node = { .key = space->id, .val = space }; diff --git a/include/coro.h b/include/coro.h index 729b79ad0842d5d23c44353cc74402488b075b62..273e773790040f6ab45255a3a8deaea2d5788f29 100644 --- a/include/coro.h +++ b/include/coro.h @@ -39,8 +39,8 @@ struct tarantool_coro { }; void -tarantool_coro_init(struct tarantool_coro *ctx, - void (*f) (void *), void *data); +tarantool_coro_create(struct tarantool_coro *ctx, + void (*f) (void *), void *data); void tarantool_coro_destroy(struct tarantool_coro *ctx); diff --git a/include/fiber.h b/include/fiber.h index 1ef42904dfd7aeb726091f391b431b8ced81bb2b..129b744d55c9dd3a3e9b3097bde3c6c8bfd203f8 100644 --- a/include/fiber.h +++ b/include/fiber.h @@ -97,7 +97,7 @@ extern __thread struct fiber *fiber; void fiber_init(void); void fiber_free(void); -struct fiber *fiber_create(const char *name, void (*f) (va_list)); +struct fiber *fiber_new(const char *name, void (*f) (va_list)); void fiber_set_name(struct fiber *fiber, const char *name); int wait_for_child(pid_t pid); diff --git a/include/iobuf.h b/include/iobuf.h index 7ee5a07720361caaf8d960666436367bd66ec181..ea12c83e6b22a987badc0a35e36ca70a1b9497c7 100644 --- a/include/iobuf.h +++ b/include/iobuf.h @@ -205,11 +205,11 @@ struct iobuf /** Create an instance of input/output buffer. */ struct iobuf * -iobuf_create(const char *name); +iobuf_new(const char *name); /** Destroy an input/output buffer. */ void -iobuf_destroy(struct iobuf *iobuf); +iobuf_delete(struct iobuf *iobuf); /** Flush output using cooperative I/O and garbage collect. * @return number of bytes written diff --git a/include/ipc.h b/include/ipc.h index a2193177cf4f140a59c5a5978a8c946a123891f0..ec9e408d0044299f711ccd4fa0bfeb868d28e716 100644 --- a/include/ipc.h +++ b/include/ipc.h @@ -38,32 +38,22 @@ struct ipc_channel; /** - * @brief allocator - * @param size - * @return malloced channel (or NULL) + * @brief Allocate and construct new IPC channel + * @param size of channel + * @return new channel * @code - * struct ipc_channel *ch = ipc_channel_alloc(10); + * struct ipc_channel *ch = ipc_channel_new(10); * @endcode */ struct ipc_channel * -ipc_channel_alloc(unsigned size); +ipc_channel_new(unsigned size); /** - * @brief Initialize a channel - a constructor. - * @param channel - * @code - * struct ipc_channel *ch = ipc_channel_alloc(10); - * ipc_channel_init(ch); - * @endcode - */ -void -ipc_channel_init(struct ipc_channel *ch); - -/** - * Cleanup the channel - a destructor. + * @brief Destruct and free a IPC channel + * @param ch channel */ void -ipc_channel_cleanup(struct ipc_channel *ch); +ipc_channel_delete(struct ipc_channel *ch); /** * @brief Put data into a channel. diff --git a/include/latch.h b/include/latch.h index b38d65e2a1b05fcc5d7d9d830aab58a3960d21b2..438bd41a22952f80b79614f5b9817a23a4dcd14e 100644 --- a/include/latch.h +++ b/include/latch.h @@ -49,7 +49,7 @@ struct tnt_latch { * * @param latch Latch to be initialized. */ -void tnt_latch_init(struct tnt_latch *latch); +void tnt_latch_create(struct tnt_latch *latch); /** * Destroy the given latch. */ diff --git a/include/mhash.h b/include/mhash.h index df6788feeb7094c9dc29e5e075befebc2ac5a5c5..e48a71d7b0ceb2f1c7353268996c4d72c29d4eb9 100644 --- a/include/mhash.h +++ b/include/mhash.h @@ -141,9 +141,9 @@ struct _mh(t) { #define MH_DENSITY 0.7 -struct _mh(t) * _mh(init)(); +struct _mh(t) * _mh(new)(); void _mh(clear)(struct _mh(t) *h); -void _mh(destroy)(struct _mh(t) *h); +void _mh(delete)(struct _mh(t) *h); void _mh(resize)(struct _mh(t) *h, mh_hash_arg_t hash_arg, mh_eq_arg_t eq_arg); int _mh(start_resize)(struct _mh(t) *h, mh_int_t buckets, mh_int_t batch, mh_hash_arg_t hash_arg, mh_eq_arg_t eq_arg); @@ -353,7 +353,7 @@ _mh(del_resize)(struct _mh(t) *h, mh_int_t x, } struct _mh(t) * -_mh(init)() +_mh(new)() { struct _mh(t) *h = calloc(1, sizeof(*h)); h->shadow = calloc(1, sizeof(*h)); @@ -376,7 +376,7 @@ _mh(clear)(struct _mh(t) *h) } void -_mh(destroy)(struct _mh(t) *h) +_mh(delete)(struct _mh(t) *h) { free(h->shadow); free(h->b); diff --git a/include/rlist.h b/include/rlist.h index 485071cd2e4ece0439d245557408f159a03bd563..a3d10d36004b24b7781b7384f5589885bf050aed 100644 --- a/include/rlist.h +++ b/include/rlist.h @@ -44,7 +44,7 @@ struct rlist { */ inline static void -rlist_init(struct rlist *list) +rlist_create(struct rlist *list) { list->next = list; list->prev = list; @@ -82,7 +82,7 @@ rlist_del(struct rlist *item) { item->prev->next = item->next; item->next->prev = item->prev; - rlist_init(item); + rlist_create(item); } inline static struct rlist * diff --git a/include/rope.h b/include/rope.h index 8054525c0d91468194b0e277394750d488a54606..8b799afcc6b3118d71c7f5534475b215208197eb 100644 --- a/include/rope.h +++ b/include/rope.h @@ -101,9 +101,9 @@ rope_size(struct rope *rope) /** Initialize an empty rope. */ static inline void -rope_init(struct rope *rope, rope_split_func split_func, - rope_alloc_func alloc_func, rope_free_func free_func, - void *alloc_ctx) +rope_create(struct rope *rope, rope_split_func split_func, + rope_alloc_func alloc_func, rope_free_func free_func, + void *alloc_ctx) { rope->root = NULL; rope->split = split_func; @@ -133,7 +133,7 @@ rope_new(rope_split_func split_func, rope_alloc_func alloc_func, sizeof(struct rope)); if (rope == NULL) return NULL; - rope_init(rope, split_func, alloc_func, free_func, alloc_ctx); + rope_create(rope, split_func, alloc_func, free_func, alloc_ctx); return rope; } @@ -201,7 +201,7 @@ rope_erase(struct rope *rope, rsize_t offset); /** Initialize an iterator. */ static inline void -rope_iter_init(struct rope_iter *it, struct rope *rope) +rope_iter_create(struct rope_iter *it, struct rope *rope) { it->rope = rope; } @@ -215,7 +215,7 @@ rope_iter_new(struct rope *rope) if (it == NULL) return NULL; - rope_iter_init(it, rope); + rope_iter_create(it, rope); return it; } diff --git a/include/salloc.h b/include/salloc.h index ad4477bf716675996a48b70511fd5360c22cc801..fb8520e5492839f7b85ba9863b9c8485661d37c8 100644 --- a/include/salloc.h +++ b/include/salloc.h @@ -35,7 +35,7 @@ struct tbuf; bool salloc_init(size_t size, size_t minimal, double factor); -void salloc_destroy(void); +void salloc_free(void); void *salloc(size_t size, const char *what); void sfree(void *ptr); void slab_validate(); diff --git a/include/tbuf.h b/include/tbuf.h index aea8b10be6f21864a26efe0961dfd12b71fac10e..50844d28ea3e29cabf9e0fa38482b658cf24c272 100644 --- a/include/tbuf.h +++ b/include/tbuf.h @@ -44,8 +44,8 @@ struct tbuf { struct palloc_pool *pool; }; -struct tbuf *tbuf_alloc(struct palloc_pool *pool); -void tbuf_init(struct tbuf *tbuf, struct palloc_pool *pool); +struct tbuf * +tbuf_new(struct palloc_pool *pool); void tbuf_ensure_resize(struct tbuf *e, size_t bytes_required); static inline void tbuf_ensure(struct tbuf *e, size_t required) diff --git a/src/admin.m b/src/admin.m index 8ccdde843e18edd83492927de2cf2bbacfbdde60..8b50cdf28a3e8413283a0e82ffabab54d17bf704 100644 --- a/src/admin.m +++ b/src/admin.m @@ -202,8 +202,8 @@ static int admin_dispatch(struct ev_io *coio, struct iobuf *iobuf, lua_State *L) { struct ibuf *in = &iobuf->in; - struct tbuf *out = tbuf_alloc(fiber->gc_pool); - struct tbuf *err = tbuf_alloc(fiber->gc_pool); + struct tbuf *out = tbuf_new(fiber->gc_pool); + struct tbuf *err = tbuf_new(fiber->gc_pool); int cs; char *p, *pe; char *strstart, *strend; @@ -1909,7 +1909,7 @@ admin_handler(va_list ap) } @finally { luaL_unref(tarantool_L, LUA_REGISTRYINDEX, coro_ref); evio_close(&coio); - iobuf_destroy(iobuf); + iobuf_delete(iobuf); session_destroy(fiber->sid); } } diff --git a/src/admin.rl b/src/admin.rl index 5543e1b6e7061af0edf4b261cd3494e564322615..9ad64f03a3c68d4af83dfc728c7989c6f4d70ca4 100644 --- a/src/admin.rl +++ b/src/admin.rl @@ -193,8 +193,8 @@ static int admin_dispatch(struct ev_io *coio, struct iobuf *iobuf, lua_State *L) { struct ibuf *in = &iobuf->in; - struct tbuf *out = tbuf_alloc(fiber->gc_pool); - struct tbuf *err = tbuf_alloc(fiber->gc_pool); + struct tbuf *out = tbuf_new(fiber->gc_pool); + struct tbuf *err = tbuf_new(fiber->gc_pool); int cs; char *p, *pe; char *strstart, *strend; @@ -350,7 +350,7 @@ admin_handler(va_list ap) } @finally { luaL_unref(tarantool_L, LUA_REGISTRYINDEX, coro_ref); evio_close(&coio); - iobuf_destroy(iobuf); + iobuf_delete(iobuf); session_destroy(fiber->sid); } } diff --git a/src/box/box.m b/src/box/box.m index 7ea6f8af3a76437c18f91df61fd303068ac4141c..af8b195ff58e6ca1059176bdb9e3a16b6d1bbb38 100644 --- a/src/box/box.m +++ b/src/box/box.m @@ -214,7 +214,7 @@ static int snap_print(void *param __attribute__((unused)), struct tbuf *t) { @try { - struct tbuf *out = tbuf_alloc(t->pool); + struct tbuf *out = tbuf_new(t->pool); struct header_v11 *raw_row = header_v11(t); struct tbuf *b = palloc(t->pool, sizeof(*b)); b->data = t->data + sizeof(struct header_v11); @@ -238,7 +238,7 @@ static int xlog_print(void *param __attribute__((unused)), struct tbuf *t) { @try { - struct tbuf *out = tbuf_alloc(t->pool); + struct tbuf *out = tbuf_new(t->pool); box_xlog_sprint(out, t); printf("%*s\n", (int)out->size, (char *)out->data); } @catch (id e) { diff --git a/src/box/box_lua.m b/src/box/box_lua.m index 6e6241f54ee0aed87a946fa5fec628693d545f38..9e9b45547dc8265d717916b14cc0d7f674329e8c 100644 --- a/src/box/box_lua.m +++ b/src/box/box_lua.m @@ -431,7 +431,7 @@ lbox_tuple_tostring(struct lua_State *L) { struct tuple *tuple = lua_checktuple(L, 1); /* @todo: print the tuple */ - struct tbuf *tbuf = tbuf_alloc(fiber->gc_pool); + struct tbuf *tbuf = tbuf_new(fiber->gc_pool); tuple_print(tbuf, tuple->field_count, tuple->data); lua_pushlstring(L, tbuf->data, tbuf->size); return 1; @@ -715,7 +715,7 @@ lbox_create_iterator(struct lua_State *L) } else { /* Single or multi- part key. */ field_count = argc - 2; - struct tbuf *data = tbuf_alloc(fiber->gc_pool); + struct tbuf *data = tbuf_new(fiber->gc_pool); for (int i = 0; i < field_count; i++) { enum field_data_type type = UNKNOWN; if (i < index->key_def->part_count) { @@ -827,7 +827,7 @@ lbox_index_count(struct lua_State *L) } else { /* Single or multi- part key. */ key_part_count = argc; - struct tbuf *data = tbuf_alloc(fiber->gc_pool); + struct tbuf *data = tbuf_new(fiber->gc_pool); for (int i = 0; i < argc; ++i) { enum field_data_type type = UNKNOWN; if (i < index->key_def->part_count) { diff --git a/src/box/hash_index.m b/src/box/hash_index.m index 005a7f6ab83b4ce5a1745eba7b9bb8c7acb8c5f4..d72fed45c241ce04639ca0e8ce25216c257f27cb 100644 --- a/src/box/hash_index.m +++ b/src/box/hash_index.m @@ -289,7 +289,7 @@ int32_tuple_to_node(struct tuple *tuple, struct key_def *key_def) - (void) free { - mh_i32ptr_destroy(int_hash); + mh_i32ptr_delete(int_hash); [super free]; } @@ -300,7 +300,7 @@ int32_tuple_to_node(struct tuple *tuple, struct key_def *key_def) if (self == NULL) return NULL; - int_hash = mh_i32ptr_init(); + int_hash = mh_i32ptr_new(); return self; } @@ -455,7 +455,7 @@ int64_tuple_to_node(struct tuple *tuple, struct key_def *key_def) - (void) free { - mh_i64ptr_destroy(int64_hash); + mh_i64ptr_delete(int64_hash); [super free]; } @@ -465,7 +465,7 @@ int64_tuple_to_node(struct tuple *tuple, struct key_def *key_def) if (self == NULL) return NULL; - int64_hash = mh_i64ptr_init(); + int64_hash = mh_i64ptr_new(); return self; } @@ -613,7 +613,7 @@ lstrptr_tuple_to_node(struct tuple *tuple, struct key_def *key_def) - (void) free { - mh_lstrptr_destroy(str_hash); + mh_lstrptr_delete(str_hash); [super free]; } @@ -623,7 +623,7 @@ lstrptr_tuple_to_node(struct tuple *tuple, struct key_def *key_def) if (self == NULL) return NULL; - str_hash = mh_lstrptr_init(); + str_hash = mh_lstrptr_new(); return self; } diff --git a/src/box/request.m b/src/box/request.m index a77cde95b01321d64834efd86f98ff1c8baa67fd..160297825bd41ee30f3f2c56d5d873eb7c8e97b1 100644 --- a/src/box/request.m +++ b/src/box/request.m @@ -572,7 +572,7 @@ update_calc_new_tuple_length(struct rope *rope) struct rope_iter it; struct rope_node *node; - rope_iter_init(&it, rope); + rope_iter_create(&it, rope); for (node = rope_iter_start(&it); node; node = rope_iter_next(&it)) { struct update_field *field = rope_leaf_data(node); u32 field_len = update_field_len(field); @@ -597,7 +597,7 @@ do_update_ops(struct rope *rope, struct tuple *new_tuple) struct rope_iter it; struct rope_node *node; - rope_iter_init(&it, rope); + rope_iter_create(&it, rope); for (node = rope_iter_start(&it); node; node = rope_iter_next(&it)) { struct update_field *field = rope_leaf_data(node); diff --git a/src/box/space.m b/src/box/space.m index d3d0f60a0c507985f114a90fb4f377c121d1f4f2..179ba6510de0f7cccecb62fd85411485d1444b4b 100644 --- a/src/box/space.m +++ b/src/box/space.m @@ -384,7 +384,7 @@ space_config() void space_init(void) { - spaces = mh_i32ptr_init(); + spaces = mh_i32ptr_new(); /* configure regular spaces */ space_config(); diff --git a/src/coio.m b/src/coio.m index d24c67d074f961ee19830cb96bb5952005f41d94..c27da2523f297327880d956aa8fd71e75abfba63 100644 --- a/src/coio.m +++ b/src/coio.m @@ -500,13 +500,13 @@ coio_service_on_accept(struct evio_service *evio_service, struct fiber *f; @try { - iobuf = iobuf_create(iobuf_name); - f = fiber_create(fiber_name, service->handler); + iobuf = iobuf_new(iobuf_name); + f = fiber_new(fiber_name, service->handler); } @catch (tnt_Exception *e) { say_error("can't create a handler fiber, dropping client connection"); evio_close(&coio); if (iobuf) - iobuf_destroy(iobuf); + iobuf_delete(iobuf); @throw; } /* diff --git a/src/coro.m b/src/coro.m index b87f549655b29bc513a902ca329d5b0c9fc31b44..cfaf77ca5cc37351cde4a72b7bcf64d25f448f0c 100644 --- a/src/coro.m +++ b/src/coro.m @@ -37,8 +37,8 @@ #include "third_party/valgrind/memcheck.h" void -tarantool_coro_init(struct tarantool_coro *coro, - void (*f) (void *), void *data) +tarantool_coro_create(struct tarantool_coro *coro, + void (*f) (void *), void *data) { const int page = sysconf(_SC_PAGESIZE); diff --git a/src/fiber.m b/src/fiber.m index c1ca6f49a5724b87151d8ea316d1b8094c5f2940..fc9ee2a088383b7c106c654acc1fe7bc56e1e689 100644 --- a/src/fiber.m +++ b/src/fiber.m @@ -403,7 +403,7 @@ fiber_set_name(struct fiber *fiber, const char *name) * completes. */ struct fiber * -fiber_create(const char *name, void (*f) (va_list)) +fiber_new(const char *name, void (*f) (va_list)) { struct fiber *fiber = NULL; @@ -414,12 +414,12 @@ fiber_create(const char *name, void (*f) (va_list)) fiber = palloc(eter_pool, sizeof(*fiber)); memset(fiber, 0, sizeof(*fiber)); - tarantool_coro_init(&fiber->coro, fiber_loop, NULL); + tarantool_coro_create(&fiber->coro, fiber_loop, NULL); fiber->gc_pool = palloc_create_pool(""); rlist_add_entry(&fibers, fiber, link); - rlist_init(&fiber->state); + rlist_create(&fiber->state); } @@ -500,10 +500,10 @@ fiber_info(struct tbuf *out) void fiber_init(void) { - rlist_init(&fibers); - rlist_init(&ready_fibers); - rlist_init(&zombie_fibers); - fiber_registry = mh_i32ptr_init(); + rlist_create(&fibers); + rlist_create(&ready_fibers); + rlist_create(&zombie_fibers); + fiber_registry = mh_i32ptr_new(); memset(&sched, 0, sizeof(sched)); sched.fid = 1; @@ -527,6 +527,6 @@ fiber_free(void) /* Only clean up if initialized. */ if (fiber_registry) { fiber_destroy_all(); - mh_i32ptr_destroy(fiber_registry); + mh_i32ptr_delete(fiber_registry); } } diff --git a/src/iobuf.m b/src/iobuf.m index f317d572410921087beaf69b5dbddd89442c706c..8a47e2ebfc66e39653743d38aa74660c1bbc3051 100644 --- a/src/iobuf.m +++ b/src/iobuf.m @@ -34,7 +34,7 @@ /** Initialize an input buffer. */ static void -ibuf_init(struct ibuf *ibuf, struct palloc_pool *pool) +ibuf_create(struct ibuf *ibuf, struct palloc_pool *pool) { ibuf->pool = pool; ibuf->capacity = 0; @@ -119,7 +119,7 @@ obuf_alloc_pos(struct obuf *buf, size_t pos, size_t size) * yet -- it may never be needed. */ void -obuf_init(struct obuf *buf, struct palloc_pool *pool) +obuf_create(struct obuf *buf, struct palloc_pool *pool) { buf->pool = pool; buf->pos = 0; @@ -266,15 +266,15 @@ SLIST_HEAD(iobuf_cache, iobuf) iobuf_cache; /** Create an instance of input/output buffer or take one from cache. */ struct iobuf * -iobuf_create(const char *name) +iobuf_new(const char *name) { struct iobuf *iobuf; if (SLIST_EMPTY(&iobuf_cache)) { iobuf = palloc(eter_pool, sizeof(struct iobuf)); struct palloc_pool *pool = palloc_create_pool(""); /* Note: do not allocate memory upfront. */ - ibuf_init(&iobuf->in, pool); - obuf_init(&iobuf->out, pool); + ibuf_create(&iobuf->in, pool); + obuf_create(&iobuf->out, pool); } else { iobuf = SLIST_FIRST(&iobuf_cache); SLIST_REMOVE_HEAD(&iobuf_cache, next); @@ -287,7 +287,7 @@ iobuf_create(const char *name) /** Put an instance back to the iobuf_cache. */ void -iobuf_destroy(struct iobuf *iobuf) +iobuf_delete(struct iobuf *iobuf) { struct palloc_pool *pool = iobuf->in.pool; if (palloc_allocated(pool) < iobuf_max_pool_size()) { @@ -295,8 +295,8 @@ iobuf_destroy(struct iobuf *iobuf) obuf_reset(&iobuf->out); } else { prelease(pool); - ibuf_init(&iobuf->in, pool); - obuf_init(&iobuf->out, pool); + ibuf_create(&iobuf->in, pool); + obuf_create(&iobuf->out, pool); } palloc_set_name(pool, "iobuf_cache"); SLIST_INSERT_HEAD(&iobuf_cache, iobuf, next); diff --git a/src/ipc.m b/src/ipc.m index db588c6d3ce20368e1ad081c9a741a26723cefb6..9274abdd1316aacd530b55859965687f815f5c37 100644 --- a/src/ipc.m +++ b/src/ipc.m @@ -40,6 +40,12 @@ struct ipc_channel { void *item[0]; }; +static void +ipc_channel_create(struct ipc_channel *ch); + +static void +ipc_channel_destroy(struct ipc_channel *ch); + bool ipc_channel_is_empty(struct ipc_channel *ch) { @@ -52,30 +58,38 @@ ipc_channel_is_full(struct ipc_channel *ch) return ch->count >= ch->size; } - struct ipc_channel * -ipc_channel_alloc(unsigned size) +ipc_channel_new(unsigned size) { if (!size) size = 1; struct ipc_channel *res = malloc(sizeof(struct ipc_channel) + sizeof(void *) * size); - if (res) - res->size = size; + if (res == NULL) + return NULL; + res->size = size; + ipc_channel_create(res); return res; } void -ipc_channel_init(struct ipc_channel *ch) +ipc_channel_delete(struct ipc_channel *ch) +{ + ipc_channel_destroy(ch); + free(ch); +} + +static void +ipc_channel_create(struct ipc_channel *ch) { ch->beg = ch->count = 0; - rlist_init(&ch->bcast); - rlist_init(&ch->readers); - rlist_init(&ch->writers); + rlist_create(&ch->bcast); + rlist_create(&ch->readers); + rlist_create(&ch->writers); } -void -ipc_channel_cleanup(struct ipc_channel *ch) +static void +ipc_channel_destroy(struct ipc_channel *ch) { while (!rlist_empty(&ch->writers)) { struct fiber *f = diff --git a/src/iproto.m b/src/iproto.m index e5aabfd7f7c0bfd2e7c9e1b1a3d9a77fd9f7857c..43fcf00221c6287c0c87d180587cd818e971ad63 100644 --- a/src/iproto.m +++ b/src/iproto.m @@ -310,7 +310,7 @@ iproto_queue_schedule(struct ev_async *watcher, struct fiber *f = rlist_shift_entry(&i_queue->fiber_cache, struct fiber, state); if (f == NULL) - f = fiber_create("iproto", i_queue->handler); + f = fiber_new("iproto", i_queue->handler); fiber_call(f, i_queue); } } @@ -330,7 +330,7 @@ iproto_queue_init(struct iproto_queue *i_queue, ev_async_init(&i_queue->watcher, iproto_queue_schedule); i_queue->watcher.data = i_queue; i_queue->handler = handler; - rlist_init(&i_queue->fiber_cache); + rlist_create(&i_queue->fiber_cache); } /** A handler to process all queued requests. */ @@ -436,8 +436,8 @@ iproto_session_create(const char *name, int fd, box_process_func *param) session->handler = param; ev_io_init(&session->input, iproto_session_on_input, fd, EV_READ); ev_io_init(&session->output, iproto_session_on_output, fd, EV_WRITE); - session->iobuf[0] = iobuf_create(name); - session->iobuf[1] = iobuf_create(name); + session->iobuf[0] = iobuf_new(name); + session->iobuf[1] = iobuf_new(name); session->parse_size = 0; session->write_pos = obuf_create_svp(&session->iobuf[0]->out); session->sid = 0; @@ -450,8 +450,8 @@ iproto_session_destroy(struct iproto_session *session) { assert(iproto_session_is_idle(session)); session_destroy(session->sid); /* Never throws. No-op if sid is 0. */ - iobuf_destroy(session->iobuf[0]); - iobuf_destroy(session->iobuf[1]); + iobuf_delete(session->iobuf[0]); + iobuf_delete(session->iobuf[1]); SLIST_INSERT_HEAD(&iproto_session_cache, session, next_in_cache); } diff --git a/src/latch.m b/src/latch.m index c481b47d5f9af1a9580886a9ef50910a15ce06e9..ff08a1ac04d02cfffdb6ee49140ac9a8db479e12 100644 --- a/src/latch.m +++ b/src/latch.m @@ -30,7 +30,7 @@ #include "fiber.h" void -tnt_latch_init(struct tnt_latch *latch) +tnt_latch_create(struct tnt_latch *latch) { latch->locked = false; latch->owner = NULL; diff --git a/src/log_io.m b/src/log_io.m index 56e82266916bea0a5309de949697195b08648e85..38f5026577f56b37875a987099ff6ca773b9f9c0 100644 --- a/src/log_io.m +++ b/src/log_io.m @@ -217,7 +217,7 @@ format_filename(struct log_dir *dir, i64 lsn, enum log_suffix suffix) static struct tbuf * row_reader_v11(FILE *f, struct palloc_pool *pool) { - struct tbuf *m = tbuf_alloc(pool); + struct tbuf *m = tbuf_new(pool); u32 header_crc, data_crc; diff --git a/src/lua/init.m b/src/lua/init.m index 8eca308a1dbd78759009c02bd4fe48dfc6f0e0ee..c2bb9b679518eb5844f87ffdbec584a0e9744215 100644 --- a/src/lua/init.m +++ b/src/lua/init.m @@ -889,7 +889,7 @@ lbox_fiber_create(struct lua_State *L) luaL_error(L, "fiber.create(function): recursion limit" " reached"); - struct fiber *f = fiber_create("lua", box_lua_fiber_run); + struct fiber *f = fiber_new("lua", box_lua_fiber_run); /* Preserve the session in a child fiber. */ fiber_set_sid(f, fiber->sid); /* Initially the fiber is cancellable */ @@ -1249,7 +1249,7 @@ lbox_print(struct lua_State *L) tbuf_printf(out, CRLF); } else { /* Add a message to the server log */ - out = tbuf_alloc(fiber->gc_pool); + out = tbuf_new(fiber->gc_pool); tarantool_lua_printstack(L, out); say_info("%s", tbuf_str(out)); } @@ -1394,7 +1394,7 @@ tarantool_lua_close(struct lua_State *L) static int tarantool_lua_dostring(struct lua_State *L, const char *str) { - struct tbuf *buf = tbuf_alloc(fiber->gc_pool); + struct tbuf *buf = tbuf_new(fiber->gc_pool); tbuf_printf(buf, "%s%s", "return ", str); int r = luaL_loadstring(L, tbuf_str(buf)); if (r) { @@ -1589,7 +1589,7 @@ tarantool_lua_load_init_script(struct lua_State *L) * To work this problem around we must run init script in * a separate fiber. */ - struct fiber *loader = fiber_create(TARANTOOL_LUA_INIT_SCRIPT, + struct fiber *loader = fiber_new(TARANTOOL_LUA_INIT_SCRIPT, load_init_script); fiber_call(loader, L); /* Outside the startup file require() or ffi are not diff --git a/src/lua/lua_ipc.m b/src/lua/lua_ipc.m index 596b3a7d104c7cd1da6e966caf24f32d6f106943..8b10960a5871c418b357d984774405eb00b0fe35 100644 --- a/src/lua/lua_ipc.m +++ b/src/lua/lua_ipc.m @@ -54,10 +54,9 @@ lbox_ipc_channel(struct lua_State *L) if (size < 0) luaL_error(L, "box.channel(size): negative size"); } - struct ipc_channel *ch = ipc_channel_alloc(size); + struct ipc_channel *ch = ipc_channel_new(size); if (!ch) luaL_error(L, "box.channel: Not enough memory"); - ipc_channel_init(ch); void **ptr = lua_newuserdata(L, sizeof(void *)); luaL_getmetatable(L, channel_lib); @@ -83,8 +82,7 @@ lbox_ipc_channel_gc(struct lua_State *L) if (lua_gettop(L) != 1 || !lua_isuserdata(L, 1)) return 0; struct ipc_channel *ch = lbox_check_channel(L, -1); - ipc_channel_cleanup(ch); - free(ch); + ipc_channel_delete(ch); return 0; } diff --git a/src/lua/lua_socket.m b/src/lua/lua_socket.m index b7bdfc82424fa3675cae66bfda57d4e4393013f3..aecd6b5e1f207dbf229b87735ec83d77678130ca 100644 --- a/src/lua/lua_socket.m +++ b/src/lua/lua_socket.m @@ -132,7 +132,7 @@ bio_initbuf(struct bio_socket *s) const char *type = s->socktype == SOCK_STREAM ? "tcp" : "udp"; snprintf(name, sizeof(name), "box.io.%s(%d)", type, s->coio.fd); - s->iob = iobuf_create(name); + s->iob = iobuf_new(name); } static inline int @@ -276,7 +276,7 @@ lbox_socket_close(struct lua_State *L) if (! evio_is_active(&s->coio)) return 0; if (s->iob) { - iobuf_destroy(s->iob); + iobuf_delete(s->iob); s->iob = NULL; } evio_close(&s->coio); diff --git a/src/memcached-grammar.m b/src/memcached-grammar.m index b5da180f3ae20fc144276d2cae4adcf7ee7cc160..d35c36508af2a7e1b69d67be93c2978500dce2d7 100644 --- a/src/memcached-grammar.m +++ b/src/memcached-grammar.m @@ -47,7 +47,7 @@ memcached_dispatch(struct ev_io *coio, struct iobuf *iobuf) int cs; char *p, *pe; char *fstart; - struct tbuf *keys = tbuf_alloc(fiber->gc_pool); + struct tbuf *keys = tbuf_new(fiber->gc_pool); void *key; bool append, show_cas; int incr_sign; @@ -430,7 +430,7 @@ tr58: } else { value = tuple_field(tuple, 3); value_len = load_varint32(&value); - b = tbuf_alloc(fiber->gc_pool); + b = tbuf_new(fiber->gc_pool); if (append) { tbuf_append(b, value, value_len); tbuf_append(b, data, bytes); @@ -490,7 +490,7 @@ tr62: } else { value = tuple_field(tuple, 3); value_len = load_varint32(&value); - b = tbuf_alloc(fiber->gc_pool); + b = tbuf_new(fiber->gc_pool); if (append) { tbuf_append(b, value, value_len); tbuf_append(b, data, bytes); @@ -552,7 +552,7 @@ tr71: } else { value = tuple_field(tuple, 3); value_len = load_varint32(&value); - b = tbuf_alloc(fiber->gc_pool); + b = tbuf_new(fiber->gc_pool); if (append) { tbuf_append(b, value, value_len); tbuf_append(b, data, bytes); @@ -746,7 +746,7 @@ tr118: exptime = m->exptime; flags = m->flags; - b = tbuf_alloc(fiber->gc_pool); + b = tbuf_new(fiber->gc_pool); tbuf_printf(b, "%"PRIu64, value); data = b->data; bytes = b->size; @@ -811,7 +811,7 @@ tr122: exptime = m->exptime; flags = m->flags; - b = tbuf_alloc(fiber->gc_pool); + b = tbuf_new(fiber->gc_pool); tbuf_printf(b, "%"PRIu64, value); data = b->data; bytes = b->size; @@ -878,7 +878,7 @@ tr132: exptime = m->exptime; flags = m->flags; - b = tbuf_alloc(fiber->gc_pool); + b = tbuf_new(fiber->gc_pool); tbuf_printf(b, "%"PRIu64, value); data = b->data; bytes = b->size; @@ -1005,7 +1005,7 @@ tr169: } #line 208 "src/memcached-grammar.rl" { - struct fiber *f = fiber_create("flush_all", flush_all); + struct fiber *f = fiber_new("flush_all", flush_all); fiber_call(f, flush_delay); obuf_dup(out, "OK\r\n", 4); } @@ -1023,7 +1023,7 @@ tr174: } #line 208 "src/memcached-grammar.rl" { - struct fiber *f = fiber_create("flush_all", flush_all); + struct fiber *f = fiber_new("flush_all", flush_all); fiber_call(f, flush_delay); obuf_dup(out, "OK\r\n", 4); } @@ -1041,7 +1041,7 @@ tr185: } #line 208 "src/memcached-grammar.rl" { - struct fiber *f = fiber_create("flush_all", flush_all); + struct fiber *f = fiber_new("flush_all", flush_all); fiber_call(f, flush_delay); obuf_dup(out, "OK\r\n", 4); } diff --git a/src/memcached-grammar.rl b/src/memcached-grammar.rl index 1c73641cb43b193e297ae4b7fa1a2d83ac450bed..64ff89576e183d6b4878e736b0bf461f9fb03440 100644 --- a/src/memcached-grammar.rl +++ b/src/memcached-grammar.rl @@ -38,7 +38,7 @@ memcached_dispatch(struct ev_io *coio, struct iobuf *iobuf) int cs; char *p, *pe; char *fstart; - struct tbuf *keys = tbuf_alloc(fiber->gc_pool); + struct tbuf *keys = tbuf_new(fiber->gc_pool); void *key; bool append, show_cas; int incr_sign; @@ -106,7 +106,7 @@ memcached_dispatch(struct ev_io *coio, struct iobuf *iobuf) } else { value = tuple_field(tuple, 3); value_len = load_varint32(&value); - b = tbuf_alloc(fiber->gc_pool); + b = tbuf_new(fiber->gc_pool); if (append) { tbuf_append(b, value, value_len); tbuf_append(b, data, bytes); @@ -152,7 +152,7 @@ memcached_dispatch(struct ev_io *coio, struct iobuf *iobuf) exptime = m->exptime; flags = m->flags; - b = tbuf_alloc(fiber->gc_pool); + b = tbuf_new(fiber->gc_pool); tbuf_printf(b, "%"PRIu64, value); data = b->data; bytes = b->size; @@ -206,7 +206,7 @@ memcached_dispatch(struct ev_io *coio, struct iobuf *iobuf) } action flush_all { - struct fiber *f = fiber_create("flush_all", flush_all); + struct fiber *f = fiber_new("flush_all", flush_all); fiber_call(f, flush_delay); obuf_dup(out, "OK\r\n", 4); } diff --git a/src/memcached.m b/src/memcached.m index 00669867e543a15af3287800dc5e997617209581..94fe71236049d4ed74f5611103367c31f8ff67ea 100644 --- a/src/memcached.m +++ b/src/memcached.m @@ -88,7 +88,7 @@ store(const void *key, u32 exptime, u32 flags, u32 bytes, const char *data) static u64 cas = 42; struct meta m; - struct tbuf *req = tbuf_alloc(fiber->gc_pool); + struct tbuf *req = tbuf_new(fiber->gc_pool); tbuf_append(req, &cfg.memcached_space, sizeof(u32)); tbuf_append(req, &box_flags, sizeof(box_flags)); @@ -125,7 +125,7 @@ delete(void *key) { u32 key_len = 1; u32 box_flags = 0; - struct tbuf *req = tbuf_alloc(fiber->gc_pool); + struct tbuf *req = tbuf_new(fiber->gc_pool); tbuf_append(req, &cfg.memcached_space, sizeof(u32)); tbuf_append(req, &box_flags, sizeof(box_flags)); @@ -194,7 +194,7 @@ salloc_stat_memcached_cb(const struct slab_cache_stats *cstat, void *cb_ctx) static void print_stats(struct obuf *out) { - struct tbuf *buf = tbuf_alloc(fiber->gc_pool); + struct tbuf *buf = tbuf_new(fiber->gc_pool); struct salloc_stat_memcached_cb_ctx memstats; memstats.bytes_used = memstats.items = 0; @@ -280,7 +280,7 @@ void memcached_get(struct obuf *out, size_t keys_count, struct tbuf *keys, stat_collect(stat_base, MEMC_GET_HIT, 1); if (show_cas) { - struct tbuf *b = tbuf_alloc(fiber->gc_pool); + struct tbuf *b = tbuf_new(fiber->gc_pool); tbuf_printf(b, "VALUE %.*s %"PRIu32" %"PRIu32" %"PRIu64"\r\n", key_len, (char*) key, m->flags, value_len, m->cas); obuf_dup(out, b->data, b->size); stats.bytes_written += b->size; @@ -392,7 +392,7 @@ memcached_handler(va_list ap) fiber_sleep(0.01); stats.curr_connections--; evio_close(&coio); - iobuf_destroy(iobuf); + iobuf_delete(iobuf); } } @@ -535,7 +535,7 @@ restart: if (tuple == NULL) [memcached_index initIterator: memcached_it :ITER_ALL :NULL :0]; - struct tbuf *keys_to_delete = tbuf_alloc(fiber->gc_pool); + struct tbuf *keys_to_delete = tbuf_new(fiber->gc_pool); for (int j = 0; j < cfg.memcached_expire_per_loop; j++) { @@ -566,7 +566,7 @@ void memcached_start_expire() assert(memcached_expire == NULL); @try { - memcached_expire = fiber_create("memcached_expire", + memcached_expire = fiber_new("memcached_expire", memcached_expire_loop); } @catch (tnt_Exception *e) { say_error("can't start the expire fiber"); diff --git a/src/replica.m b/src/replica.m index 60b7a40bff3c8de1f379c1e77f81eac58892ecb1..c0f0dce2e2548fa999f27ed387dd283879663eac 100644 --- a/src/replica.m +++ b/src/replica.m @@ -106,7 +106,7 @@ pull_from_remote(va_list ap) fiber_setcancellable(true); if (! evio_is_active(&coio)) { if (iobuf == NULL) - iobuf = iobuf_create(fiber->name); + iobuf = iobuf_new(fiber->name); remote_connect(&coio, &r->remote->addr, r->confirmed_lsn + 1, &err); warning_said = false; @@ -124,7 +124,7 @@ pull_from_remote(va_list ap) iobuf_gc(iobuf); fiber_gc(); } @catch (FiberCancelException *e) { - iobuf_destroy(iobuf); + iobuf_delete(iobuf); evio_close(&coio); @throw; } @catch (tnt_Exception *e) { @@ -170,7 +170,7 @@ recovery_follow_remote(struct recovery_state *r, const char *addr) snprintf(name, sizeof(name), "replica/%s", addr); @try { - f = fiber_create(name, pull_from_remote); + f = fiber_new(name, pull_from_remote); } @catch (tnt_Exception *e) { return; } diff --git a/src/replication.m b/src/replication.m index d89915a9adfef4cc952cf7b72d63f7484dd90dc5..4792e7c659d75d68979cda3013b0b11708ef338b 100644 --- a/src/replication.m +++ b/src/replication.m @@ -626,7 +626,7 @@ replication_relay_loop(int client_sock) } say_info("starting replication from lsn: %"PRIi64, lsn); - ver = tbuf_alloc(fiber->gc_pool); + ver = tbuf_new(fiber->gc_pool); tbuf_append(ver, &default_version, sizeof(default_version)); replication_relay_send_row((void *)(intptr_t) client_sock, ver); diff --git a/src/rope.c b/src/rope.c index 016bff246c55fb3aeeafa378df79bf07014e0ffc..727d0a6eabf20265ac0dbf237ea1c95f4ce084f5 100644 --- a/src/rope.c +++ b/src/rope.c @@ -570,7 +570,7 @@ void rope_traverse(struct rope *rope, void (*visit_leaf)(void *, size_t)) { struct rope_iter iter; - rope_iter_init(&iter, rope); + rope_iter_create(&iter, rope); struct rope_node *leaf; @@ -586,7 +586,7 @@ void rope_check(struct rope *rope) { struct rope_iter iter; - rope_iter_init(&iter, rope); + rope_iter_create(&iter, rope); struct rope_node *node; diff --git a/src/salloc.m b/src/salloc.m index 1ed9abad96bc256921ce5db06f1c2d118f6d6629..7390ad3e3c32782eaec7c7205e6f1fe1479feb97 100644 --- a/src/salloc.m +++ b/src/salloc.m @@ -170,7 +170,7 @@ salloc_init(size_t size, size_t minimal, double factor) } void -salloc_destroy(void) +salloc_free(void) { if (arena.mmap_base != NULL) munmap(arena.mmap_base, arena.mmap_size); diff --git a/src/session.m b/src/session.m index 78f7a642b95abe9b0a9d781973f38845e2081bfa..0d0ec2e942387682414210fab29bde7076f029dd 100644 --- a/src/session.m +++ b/src/session.m @@ -110,7 +110,7 @@ session_fd(uint32_t sid) void session_init() { - session_registry = mh_i32ptr_init(); + session_registry = mh_i32ptr_new(); if (session_registry == NULL) panic("out of memory"); } @@ -119,5 +119,5 @@ void session_free() { if (session_registry) - mh_i32ptr_destroy(session_registry); + mh_i32ptr_delete(session_registry); } diff --git a/src/tarantool.m b/src/tarantool.m index fc1f955807ccbb6e2bc1ea21448012a669fb1668..b21da0efb7d63862a41a69861856f509ca464518 100644 --- a/src/tarantool.m +++ b/src/tarantool.m @@ -216,7 +216,7 @@ reload_cfg(struct tbuf *out) if (latch == NULL) { latch = palloc(eter_pool, sizeof(*latch)); - tnt_latch_init(latch); + tnt_latch_create(latch); } if (tnt_latch_trylock(latch) == -1) { @@ -737,7 +737,7 @@ main(int argc, char **argv) strcat(cfg_filename_fullpath, cfg_filename); } - cfg_out = tbuf_alloc(eter_pool); + cfg_out = tbuf_new(eter_pool); assert(cfg_out); if (gopt(opt, 'k')) { diff --git a/src/tbuf.m b/src/tbuf.m index 433d81b9a666a90ed935485b4d0efe2df4092e3f..5a801ed7005f9237abbd09f0ad7541656838424c 100644 --- a/src/tbuf.m +++ b/src/tbuf.m @@ -58,18 +58,8 @@ tbuf_assert(const struct tbuf *b) assert(b->size <= b->capacity); } -void -tbuf_init(struct tbuf *e, struct palloc_pool *pool) -{ - e->pool = pool; - e->data = palloc(pool, TBUF_ALLOC_FACTOR); - e->capacity = TBUF_ALLOC_FACTOR; - e->size = 0; - tbuf_assert(e); -} - struct tbuf * -tbuf_alloc(struct palloc_pool *pool) +tbuf_new(struct palloc_pool *pool) { struct tbuf *e = palloc(pool, TBUF_ALLOC_FACTOR); e->size = 0; @@ -105,7 +95,7 @@ tbuf_ensure_resize(struct tbuf *e, size_t required) struct tbuf * tbuf_clone(struct palloc_pool *pool, const struct tbuf *orig) { - struct tbuf *clone = tbuf_alloc(pool); + struct tbuf *clone = tbuf_new(pool); tbuf_assert(orig); tbuf_append(clone, orig->data, orig->size); return clone; diff --git a/test/unit/mhash.c b/test/unit/mhash.c index 47b2f4853796806efbe2eb1ba4c9bd1fe3bb8cef..e2c2ca09ff087dd3182e5ba14ad7ad6e800bd116 100644 --- a/test/unit/mhash.c +++ b/test/unit/mhash.c @@ -36,9 +36,9 @@ static void mhash_int32_id_test() header(); int ret, k; struct mh_i32_t *h; -#define init() ({ mh_i32_init(); }) +#define init() ({ mh_i32_new(); }) #define clear(x) ({ mh_i32_clear((x)); }) -#define destroy(x) ({ mh_i32_destroy((x)); }) +#define destroy(x) ({ mh_i32_delete((x)); }) #define get(x) ({ \ const struct mh_i32_node_t _node = { .key = (x) }; \ mh_i32_get(h, &_node, NULL, NULL); \ @@ -63,9 +63,9 @@ static void mhash_int32_collision_test() header(); int ret, k; struct mh_i32_collision_t *h; -#define init() ({ mh_i32_collision_init(); }) +#define init() ({ mh_i32_collision_new(); }) #define clear(x) ({ mh_i32_collision_clear((x)); }) -#define destroy(x) ({ mh_i32_collision_destroy((x)); }) +#define destroy(x) ({ mh_i32_collision_delete((x)); }) #define get(x) ({ \ const struct mh_i32_collision_node_t _node = { .key = (x) }; \ mh_i32_collision_get(h, &_node, NULL, NULL); \ diff --git a/test/unit/rlist.c b/test/unit/rlist.c index a29d49d526b755ca6b8af48aa0bb6e91585e623c..6619e5be7ef76a72d17f76ef8de91dbcb8efcf7a 100644 --- a/test/unit/rlist.c +++ b/test/unit/rlist.c @@ -93,7 +93,7 @@ main(void) } - rlist_init(&head); + rlist_create(&head); ok(rlist_empty(&head), "list is empty"); for (i = 0; i < ITEMS; i++) { items[i].no = i;