From 671c452ef469ab935a7fdd96d194b440eaeaa52e Mon Sep 17 00:00:00 2001 From: Roman Tsisyk <roman@tsisyk.com> Date: Mon, 17 Feb 2014 16:41:28 +0400 Subject: [PATCH] 158-box.ipc.close: minor changes (code style) --- doc/user/stored-procedures.xml | 31 ++++++++++++------------------- include/ipc.h | 4 +--- src/ipc.cc | 22 +++++++--------------- src/lua/lua_ipc.cc | 12 ++---------- 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/doc/user/stored-procedures.xml b/doc/user/stored-procedures.xml index 6383e00e2e..bcc90d1035 100644 --- a/doc/user/stored-procedures.xml +++ b/doc/user/stored-procedures.xml @@ -2249,10 +2249,10 @@ for instructions about defining triggers for connect and disconnect events <term><emphasis role="lua">channel:close()</emphasis></term> <listitem> <simpara> - Close channel. All waiters at the channel will be - woke up. - All following operation <code>channel:put()</code> - or <code>channel:get()</code> will do nothing. + Close the channel. All waiters in the channel will be + woken up. All following <code>channel:put()</code> + or <code>channel:get()</code> operations will return + an error (nil). </simpara> </listitem> </varlistentry> @@ -2290,12 +2290,10 @@ for instructions about defining triggers for connect and disconnect events <term><emphasis role="lua">channel:broadcast(message, timeout)</emphasis></term> <listitem> <simpara> - If the channel is empty, <code>channel:broadcast()</code> is - equivalent to + If the channel is empty, <code>channel:broadcast()</code> is equivalent to <code>channel:put()</code>. - Otherwise, <code>channel:broadcast()</code> sends - the message to all readers of the - channel. + Otherwise, <code>channel.broadcast()</code> sends the message to all readers of the + channel. </simpara> </listitem> </varlistentry> @@ -2303,8 +2301,7 @@ for instructions about defining triggers for connect and disconnect events <term><emphasis role="lua">channel:is_empty()</emphasis></term> <listitem> <simpara> - Return true if the specified channel is empty - (has no messages). + Return true if the specified channel is empty (has no messages). </simpara> </listitem> </varlistentry> @@ -2312,8 +2309,7 @@ for instructions about defining triggers for connect and disconnect events <term><emphasis role="lua">channel:is_full()</emphasis></term> <listitem> <simpara> - Return true if the specified channel is full - (has no room for a new message). + Return true if the specified channel is full (has no room for a new message). </simpara> </listitem> </varlistentry> @@ -2321,8 +2317,7 @@ for instructions about defining triggers for connect and disconnect events <term><emphasis role="lua">channel:has_readers()</emphasis></term> <listitem> <simpara> - Return true if the specified channel is empty and - has readers waiting + Return true if the specified channel is empty and has readers waiting for a message (because they have issued <code>channel:get()</code> and then blocked). @@ -2334,10 +2329,8 @@ for instructions about defining triggers for connect and disconnect events <term><emphasis role="lua">channel:has_writers()</emphasis></term> <listitem> <simpara> - Return true if the specified channel is full - and has writers waiting - (because they have issued <code>channel:put()</code> - and then blocked + Return true if the specified channel is full and has writers waiting + (because they have issued <code>channel:put()</code> and then blocked due to lack of room). Otherwise return false. </simpara> </listitem> diff --git a/include/ipc.h b/include/ipc.h index a9eec10cbc..90ea5c3784 100644 --- a/include/ipc.h +++ b/include/ipc.h @@ -150,7 +150,6 @@ ipc_channel_put_timeout(struct ipc_channel *ch, void *data, void * ipc_channel_get_timeout(struct ipc_channel *ch, ev_tstamp timeout); - /** * @brief return true if channel has reader fibers that wait data * @param channel @@ -165,9 +164,8 @@ ipc_channel_has_readers(struct ipc_channel *ch); bool ipc_channel_has_writers(struct ipc_channel *ch); - /** - * @brief close the channel. Wake up readers and writers (if they are exists) + * @brief close the channel. Wake up readers and writers (if they exist) */ void ipc_channel_close(struct ipc_channel *ch); diff --git a/src/ipc.cc b/src/ipc.cc index c0b4ebcb73..493a5dd12e 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -114,7 +114,6 @@ ipc_channel_get_timeout(struct ipc_channel *ch, ev_tstamp timeout) if (ch->closed) return NULL; - struct fiber *f; bool first_try = true; ev_tstamp started = ev_now(); @@ -138,7 +137,7 @@ ipc_channel_get_timeout(struct ipc_channel *ch, ev_tstamp timeout) fiber_testcancel(); fiber_setcancellable(cancellable); res = ch->bcast_msg; - goto EXIT; + goto exit; } fiber_testcancel(); @@ -147,14 +146,13 @@ ipc_channel_get_timeout(struct ipc_channel *ch, ev_tstamp timeout) timeout -= ev_now() - started; if (timeout <= 0) { res = NULL; - goto EXIT; + goto exit; } if (ch->closed) { res = NULL; - goto EXIT; + goto exit; } - } res = ch->item[ch->beg]; @@ -168,8 +166,7 @@ ipc_channel_get_timeout(struct ipc_channel *ch, ev_tstamp timeout) fiber_wakeup(f); } - -EXIT: +exit: if (ch->closed && ch->close) { fiber_wakeup(ch->close); ch->close = NULL; @@ -184,7 +181,6 @@ ipc_channel_get(struct ipc_channel *ch) return ipc_channel_get_timeout(ch, TIMEOUT_INFINITY); } - static void ipc_channel_close_waiter(struct ipc_channel *ch, struct fiber *f) { @@ -236,7 +232,6 @@ ipc_channel_put_timeout(struct ipc_channel *ch, void *data, return -1; } - bool first_try = true; int res; unsigned i; @@ -263,13 +258,13 @@ ipc_channel_put_timeout(struct ipc_channel *ch, void *data, if (timeout <= 0) { errno = ETIMEDOUT; res = -1; - goto EXIT; + goto exit; } if (ch->closed) { errno = EBADF; res = -1; - goto EXIT; + goto exit; } } @@ -287,7 +282,7 @@ ipc_channel_put_timeout(struct ipc_channel *ch, void *data, fiber_wakeup(f); } res = 0; -EXIT: +exit: if (ch->closed && ch->close) { int save_errno = errno; fiber_wakeup(ch->close); @@ -358,7 +353,6 @@ ipc_channel_broadcast(struct ipc_channel *ch, void *data) break; } - if (ch->closed && ch->close) { fiber_wakeup(ch->close); ch->close = NULL; @@ -366,5 +360,3 @@ ipc_channel_broadcast(struct ipc_channel *ch, void *data) return cnt; } - - diff --git a/src/lua/lua_ipc.cc b/src/lua/lua_ipc.cc index 296b24db65..486f6a41b2 100644 --- a/src/lua/lua_ipc.cc +++ b/src/lua/lua_ipc.cc @@ -39,13 +39,8 @@ extern "C" { #include "ipc.h" #include "lua/init.h" - - - - static const char channel_lib[] = "box.ipc.channel"; - #define BROADCAST_MASK (((size_t)1) << (CHAR_BIT * sizeof(size_t) - 1)) /******************** channel ***************************/ @@ -141,12 +136,11 @@ lbox_ipc_channel_put(struct lua_State *L) lua_pushvalue(L, 2); size_t vref = luaL_ref(L, LUA_REGISTRYINDEX); - int retval; if (ipc_channel_put_timeout(ch, (void *)vref, timeout) == 0) { retval = 1; } else { - /* put timeout */ + /* timed out or closed */ luaL_unref(L, LUA_REGISTRYINDEX, vref); retval = 0; } @@ -179,8 +173,8 @@ lbox_ipc_channel_get(struct lua_State *L) size_t vref = (size_t)ipc_channel_get_timeout(ch, timeout); - if (!vref) { + /* timed out or closed */ lua_pushnil(L); return 1; } @@ -282,7 +276,6 @@ tarantool_lua_ipc_init(struct lua_State *L) {NULL, NULL} }; - lua_getfield(L, LUA_GLOBALSINDEX, "box"); lua_pushstring(L, "ipc"); @@ -291,4 +284,3 @@ tarantool_lua_ipc_init(struct lua_State *L) lua_settable(L, -3); lua_pop(L, 1); } - -- GitLab