public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: POSIX message queues: simplify sync object creation Date: Wed, 12 May 2021 09:40:37 +0000 (GMT) [thread overview] Message-ID: <20210512094037.E1DD23835800@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7b8edba6259fd8439fada6a2aaf1ecdef7b509d8 commit 7b8edba6259fd8439fada6a2aaf1ecdef7b509d8 Author: Corinna Vinschen <corinna@vinschen.de> Date: Wed May 12 11:04:44 2021 +0200 Cygwin: POSIX message queues: simplify sync object creation Introduce new inline function mq_ipc_init to create all three required sync objects. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/posix_ipc.cc | 53 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/winsup/cygwin/posix_ipc.cc b/winsup/cygwin/posix_ipc.cc index fdecbca75..6b8c57fa0 100644 --- a/winsup/cygwin/posix_ipc.cc +++ b/winsup/cygwin/posix_ipc.cc @@ -410,6 +410,31 @@ struct mq_attr defattr = { 0, 10, 8192, 0 }; /* Linux defaults. */ extern "C" off_t lseek64 (int, off_t, int); extern "C" void *mmap64 (void *, size_t, int, int, int, off_t); +static inline int +_mq_ipc_init (struct mq_info *mqinfo, const char *name) +{ + int ret; + + /* Initialize mutex & condition variable */ + ret = ipc_mutex_init (&mqinfo->mqi_lock, name); + if (ret) + return ret; + ret = ipc_cond_init (&mqinfo->mqi_waitsend, name, 'S'); + if (ret) + { + ipc_mutex_close (mqinfo->mqi_lock); + return ret; + } + ret = ipc_cond_init (&mqinfo->mqi_waitrecv, name, 'R'); + if (ret) + { + ipc_cond_close (mqinfo->mqi_waitsend); + ipc_mutex_close (mqinfo->mqi_lock); + return ret; + } + return 0; +} + extern "C" mqd_t mq_open (const char *name, int oflag, ...) { @@ -517,19 +542,7 @@ mq_open (const char *name, int oflag, ...) msghdr->msg_next = 0; /* end of free list */ /* Initialize mutex & condition variables */ - i = ipc_mutex_init (&mqinfo->mqi_lock, mqhdr->mqh_uname); - if (i != 0) - { - set_errno (i); - __leave; - } - i = ipc_cond_init (&mqinfo->mqi_waitsend, mqhdr->mqh_uname, 'S'); - if (i != 0) - { - set_errno (i); - __leave; - } - i = ipc_cond_init (&mqinfo->mqi_waitrecv, mqhdr->mqh_uname, 'R'); + i = _mq_ipc_init (mqinfo, mqhdr->mqh_uname); if (i != 0) { set_errno (i); @@ -598,19 +611,7 @@ mq_open (const char *name, int oflag, ...) mqinfo->mqi_flags = nonblock; /* Initialize mutex & condition variable */ - i = ipc_mutex_init (&mqinfo->mqi_lock, mqhdr->mqh_uname); - if (i != 0) - { - set_errno (i); - __leave; - } - i = ipc_cond_init (&mqinfo->mqi_waitsend, mqhdr->mqh_uname, 'S'); - if (i != 0) - { - set_errno (i); - __leave; - } - i = ipc_cond_init (&mqinfo->mqi_waitrecv, mqhdr->mqh_uname, 'R'); + i = _mq_ipc_init (mqinfo, mqhdr->mqh_uname); if (i != 0) { set_errno (i);
reply other threads:[~2021-05-12 9:40 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210512094037.E1DD23835800@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).