* [PATCH] hurd fcntl: remove duplicate do...while in LOCKED macro
@ 2023-01-04 10:30 wangshuo_1994
2023-01-04 11:56 ` Samuel Thibault
0 siblings, 1 reply; 2+ messages in thread
From: wangshuo_1994 @ 2023-01-04 10:30 UTC (permalink / raw)
To: libc-alpha, samuel.thibault; +Cc: abushwang
From: abushwang <wangshuo_1994@foxmail.com>
commit e1a467d introduces do...while for LOCKED macro. However, there is
already while(0) in LOCKED macro according to HURD_CRITICAL_END in hurd/hurd/signal.h:
#define HURD_CRITICAL_BEGIN \
{ void *__hurd_critical__ = _hurd_critical_section_lock ()
#define HURD_CRITICAL_END \
_hurd_critical_section_unlock (__hurd_critical__); } while (0)
It is robust enough.
Signed-off-by: abushwang <wangshuo_1994@foxmail.com>
---
sysdeps/mach/hurd/fcntl.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c
index 48608493a1..ea35e9b977 100644
--- a/sysdeps/mach/hurd/fcntl.c
+++ b/sysdeps/mach/hurd/fcntl.c
@@ -109,7 +109,7 @@ __libc_fcntl (int fd, int cmd, ...)
/* Set RESULT by evaluating EXPR with the descriptor locked.
Check for an empty descriptor and return EBADF. */
-#define LOCKED(expr) do { \
+#define LOCKED(expr) \
HURD_CRITICAL_BEGIN; \
__spin_lock (&d->port.lock); \
if (d->port.port == MACH_PORT_NULL) \
@@ -117,8 +117,7 @@ __libc_fcntl (int fd, int cmd, ...)
else \
result = (expr); \
__spin_unlock (&d->port.lock); \
- HURD_CRITICAL_END; \
-} while(0)
+ HURD_CRITICAL_END;
case F_GETFD: /* Get descriptor flags. */
LOCKED (d->flags);
--
2.37.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] hurd fcntl: remove duplicate do...while in LOCKED macro
2023-01-04 10:30 [PATCH] hurd fcntl: remove duplicate do...while in LOCKED macro wangshuo_1994
@ 2023-01-04 11:56 ` Samuel Thibault
0 siblings, 0 replies; 2+ messages in thread
From: Samuel Thibault @ 2023-01-04 11:56 UTC (permalink / raw)
To: wangshuo_1994; +Cc: libc-alpha
wangshuo_1994@foxmail.com, le mer. 04 janv. 2023 18:30:57 +0800, a ecrit:
> From: abushwang <wangshuo_1994@foxmail.com>
>
> commit e1a467d introduces do...while for LOCKED macro. However, there is
> already while(0) in LOCKED macro according to HURD_CRITICAL_END in hurd/hurd/signal.h:
>
> #define HURD_CRITICAL_BEGIN \
> { void *__hurd_critical__ = _hurd_critical_section_lock ()
> #define HURD_CRITICAL_END \
> _hurd_critical_section_unlock (__hurd_critical__); } while (0)
>
> It is robust enough.
That's true, but that's a bit hidden, and might someday go away.
The original purpose of my change was to avoid exposing a double ';' to
static analyzers who then frown upon it.
The do { } while(0) shouldn't be harmful anyway, so I prefer to keep it.
Samuel
> Signed-off-by: abushwang <wangshuo_1994@foxmail.com>
> ---
> sysdeps/mach/hurd/fcntl.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c
> index 48608493a1..ea35e9b977 100644
> --- a/sysdeps/mach/hurd/fcntl.c
> +++ b/sysdeps/mach/hurd/fcntl.c
> @@ -109,7 +109,7 @@ __libc_fcntl (int fd, int cmd, ...)
>
> /* Set RESULT by evaluating EXPR with the descriptor locked.
> Check for an empty descriptor and return EBADF. */
> -#define LOCKED(expr) do { \
> +#define LOCKED(expr) \
> HURD_CRITICAL_BEGIN; \
> __spin_lock (&d->port.lock); \
> if (d->port.port == MACH_PORT_NULL) \
> @@ -117,8 +117,7 @@ __libc_fcntl (int fd, int cmd, ...)
> else \
> result = (expr); \
> __spin_unlock (&d->port.lock); \
> - HURD_CRITICAL_END; \
> -} while(0)
> + HURD_CRITICAL_END;
>
> case F_GETFD: /* Get descriptor flags. */
> LOCKED (d->flags);
> --
> 2.37.3
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-04 11:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-04 10:30 [PATCH] hurd fcntl: remove duplicate do...while in LOCKED macro wangshuo_1994
2023-01-04 11:56 ` Samuel Thibault
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).