From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: kostja@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [PATCH 05/13] gc: fold gc_consumer_new and gc_consumer_delete
Date: Thu, 4 Oct 2018 20:20:07 +0300 [thread overview]
Message-ID: <174ff75d6da63c095fc742a4bf857f66056e4952.1538671546.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1538671546.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1538671546.git.vdavydov.dev@gmail.com>
gc_consumer_new is used in one place while gc_consumer_delete is used in
two places, but it's a one-liner. Let's fold them to make the code flow
more straightforward.
---
src/box/gc.c | 44 ++++++++++++++------------------------------
1 file changed, 14 insertions(+), 30 deletions(-)
diff --git a/src/box/gc.c b/src/box/gc.c
index 7de50e84..449416b5 100644
--- a/src/box/gc.c
+++ b/src/box/gc.c
@@ -71,31 +71,6 @@ gc_consumer_cmp(const struct gc_consumer *a, const struct gc_consumer *b)
rb_gen(MAYBE_UNUSED static inline, gc_tree_, gc_tree_t,
struct gc_consumer, node, gc_consumer_cmp);
-/** Allocate a consumer object. */
-static struct gc_consumer *
-gc_consumer_new(const char *name, const struct vclock *vclock,
- enum gc_consumer_type type)
-{
- struct gc_consumer *consumer = calloc(1, sizeof(*consumer));
- if (consumer == NULL) {
- diag_set(OutOfMemory, sizeof(*consumer),
- "malloc", "struct gc_consumer");
- return NULL;
- }
- snprintf(consumer->name, GC_NAME_MAX, "%s", name);
- vclock_copy(&consumer->vclock, vclock);
- consumer->type = type;
- return consumer;
-}
-
-/** Free a consumer object. */
-static void
-gc_consumer_delete(struct gc_consumer *consumer)
-{
- TRASH(consumer);
- free(consumer);
-}
-
void
gc_init(void)
{
@@ -114,7 +89,7 @@ gc_free(void)
struct gc_consumer *next = gc_tree_next(&gc.consumers,
consumer);
gc_tree_remove(&gc.consumers, consumer);
- gc_consumer_delete(consumer);
+ free(consumer);
consumer = next;
}
}
@@ -213,9 +188,18 @@ struct gc_consumer *
gc_consumer_register(const char *name, const struct vclock *vclock,
enum gc_consumer_type type)
{
- struct gc_consumer *consumer = gc_consumer_new(name, vclock, type);
- if (consumer != NULL)
- gc_tree_insert(&gc.consumers, consumer);
+ struct gc_consumer *consumer = calloc(1, sizeof(*consumer));
+ if (consumer == NULL) {
+ diag_set(OutOfMemory, sizeof(*consumer),
+ "malloc", "struct gc_consumer");
+ return NULL;
+ }
+
+ snprintf(consumer->name, GC_NAME_MAX, "%s", name);
+ vclock_copy(&consumer->vclock, vclock);
+ consumer->type = type;
+
+ gc_tree_insert(&gc.consumers, consumer);
return consumer;
}
@@ -225,7 +209,7 @@ gc_consumer_unregister(struct gc_consumer *consumer)
int64_t signature = vclock_sum(&consumer->vclock);
gc_tree_remove(&gc.consumers, consumer);
- gc_consumer_delete(consumer);
+ free(consumer);
/*
* Rerun garbage collection after removing the consumer
--
2.11.0
next prev parent reply other threads:[~2018-10-04 17:20 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-04 17:20 [PATCH 00/13] box: garbage collection refactoring and fixes Vladimir Davydov
2018-10-04 17:20 ` [PATCH 01/13] vinyl: fix master crash on replica join failure Vladimir Davydov
2018-10-04 21:43 ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 02/13] vinyl: force deletion of runs left from unfinished indexes on restart Vladimir Davydov
2018-10-04 21:44 ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 03/13] gc: make gc_consumer and gc_state structs transparent Vladimir Davydov
2018-10-04 21:47 ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 04/13] gc: use fixed length buffer for storing consumer name Vladimir Davydov
2018-10-04 21:47 ` Konstantin Osipov
2018-10-04 17:20 ` Vladimir Davydov [this message]
2018-10-04 21:50 ` [PATCH 05/13] gc: fold gc_consumer_new and gc_consumer_delete Konstantin Osipov
2018-10-05 8:56 ` Vladimir Davydov
2018-10-04 17:20 ` [PATCH 06/13] gc: format consumer name in gc_consumer_register Vladimir Davydov
2018-10-04 21:50 ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 07/13] gc: rename checkpoint_count to min_checkpoint_count Vladimir Davydov
2018-10-04 21:51 ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 08/13] gc: keep track of available checkpoints Vladimir Davydov
2018-10-04 21:59 ` Konstantin Osipov
2018-10-05 8:50 ` Vladimir Davydov
2018-10-04 17:20 ` [PATCH 09/13] gc: cleanup garbage collection procedure Vladimir Davydov
2018-10-04 22:00 ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 10/13] gc: improve box.info.gc output Vladimir Davydov
2018-10-04 22:01 ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 11/13] gc: separate checkpoint references from wal consumers Vladimir Davydov
2018-10-04 22:05 ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 12/13] gc: call gc_run unconditionally when consumer is advanced Vladimir Davydov
2018-10-04 22:26 ` Konstantin Osipov
2018-10-04 17:20 ` [PATCH 13/13] replication: ref checkpoint needed to join replica Vladimir Davydov
2018-10-04 22:27 ` Konstantin Osipov
2018-10-05 17:03 ` [PATCH 00/13] box: garbage collection refactoring and fixes Vladimir Davydov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=174ff75d6da63c095fc742a4bf857f66056e4952.1538671546.git.vdavydov.dev@gmail.com \
--to=vdavydov.dev@gmail.com \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH 05/13] gc: fold gc_consumer_new and gc_consumer_delete' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox