From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EE2BE4696C3 for ; Sat, 11 Apr 2020 19:34:01 +0300 (MSK) Received: by mail-lj1-f196.google.com with SMTP id u15so257099ljd.3 for ; Sat, 11 Apr 2020 09:34:01 -0700 (PDT) Date: Sat, 11 Apr 2020 19:33:58 +0300 From: Cyrill Gorcunov Message-ID: <20200411163358.GU3072@uranus> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Tarantool-patches] [PATCH 1/2] trigger: add trigger_is_set() method List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Serge Petrenko Cc: tarantool-patches@dev.tarantool.org On Sat, Apr 11, 2020 at 03:33:44PM +0300, Serge Petrenko wrote: > --- > src/lib/core/trigger.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/src/lib/core/trigger.h b/src/lib/core/trigger.h > index 7b500dd92..ae477ad70 100644 > --- a/src/lib/core/trigger.h > +++ b/src/lib/core/trigger.h > @@ -95,6 +95,12 @@ trigger_add_unique(struct rlist *list, struct trigger *trigger) > trigger_add(list, trigger); > } > > +static inline int > +trigger_is_set(struct trigger *trigger) > +{ > + return !rlist_empty(&trigger->link); > +} > + Wait. Serge, you know I don;t like it. Can't we rather provide normal static initializer say like --- diff --git a/src/lib/core/trigger.h b/src/lib/core/trigger.h index 7b500dd92..e9c6dd17e 100644 --- a/src/lib/core/trigger.h +++ b/src/lib/core/trigger.h @@ -59,6 +59,14 @@ struct trigger trigger_f0 destroy; }; +#define DECLARE_TRIGGER(__name, __run, __data, __destroy) \ + struct trigger __name = { \ + .link = RLIST_HEAD_INITIALIZER(__name.link), \ + .run = __run, \ + .data = __data, \ + .destroy= __destroy, \ + } + and simply declare the trigger diff --git a/src/box/relay.cc b/src/box/relay.cc index c634348a4..cdc20dc5b 100644 --- a/src/box/relay.cc +++ b/src/box/relay.cc @@ -580,9 +580,7 @@ relay_subscribe_f(va_list ap) * Not needed for anonymous replicas, since they * aren't registered with gc at all. */ - struct trigger on_close_log = { - RLIST_LINK_INITIALIZER, relay_on_close_log_f, relay, NULL - }; + DECLARE_TRIGGER(on_close_log, relay_on_close_log_f, relay, NULL); if (!relay->replica->anon) trigger_add(&r->on_close_log, &on_close_log); so that trigger_clear won't fail without if statement?