From a4c6b179bb120b4a1d70f34fe27f1ead8aa2ce87 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 15 Feb 2021 13:11:27 +0800 Subject: [PATCH] mqueue: Add _MQ_OPEN, _MQ_CLOSE and _MQ_UNLINK macro and replace mq_open, mq_close and mq_unlink with these in libnx Signed-off-by: Xiang Xiao --- include/nuttx/mqueue.h | 6 ++++++ libs/libnx/nxmu/nx_connect.c | 25 +++++++++++++++---------- libs/libnx/nxmu/nx_disconnect.c | 4 ++-- libs/libnx/nxmu/nx_eventhandler.c | 4 ++-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h index c1791ac6378..ac6d96140ad 100644 --- a/include/nuttx/mqueue.h +++ b/include/nuttx/mqueue.h @@ -60,6 +60,9 @@ */ #if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) +# define _MQ_OPEN nxmq_open +# define _MQ_CLOSE(d) nxmq_close(d) +# define _MQ_UNLINK(n) nxmq_unlink(n) # define _MQ_SEND(d,m,l,p) nxmq_send(d,m,l,p) # define _MQ_TIMEDSEND(d,m,l,p,t) nxmq_timedsend(d,m,l,p,t) # define _MQ_RECEIVE(d,m,l,p) nxmq_receive(d,m,l,p) @@ -68,6 +71,9 @@ # define _MQ_SETERRNO(r) set_errno(-(r)) # define _MQ_GETERRVAL(r) (r) #else +# define _MQ_OPEN mq_open +# define _MQ_CLOSE(d) mq_close(d) +# define _MQ_UNLINK(n) mq_unlink(n) # define _MQ_SEND(d,m,l,p) mq_send(d,m,l,p) # define _MQ_TIMEDSEND(d,m,l,p,t) mq_timedsend(d,m,l,p,t) # define _MQ_RECEIVE(d,m,l,p) mq_receive(d,m,l,p) diff --git a/libs/libnx/nxmu/nx_connect.c b/libs/libnx/nxmu/nx_connect.c index 018410d7ef4..2b8f2057ed9 100644 --- a/libs/libnx/nxmu/nx_connect.c +++ b/libs/libnx/nxmu/nx_connect.c @@ -43,11 +43,11 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -139,13 +139,16 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname) attr.mq_flags = 0; #ifdef CONFIG_NX_BLOCKING - conn->crdmq = mq_open(climqname, O_RDONLY|O_CREAT, 0666, &attr); + conn->crdmq = _MQ_OPEN(climqname, O_RDONLY | O_CREAT, 0666, &attr); #else - conn->crdmq = mq_open(climqname, O_RDONLY|O_CREAT|O_NONBLOCK, 0666, &attr); + conn->crdmq = _MQ_OPEN(climqname, O_RDONLY | O_CREAT | O_NONBLOCK, + 0666, &attr); #endif - if (conn->crdmq == (mqd_t)-1) + if (conn->crdmq < 0) { - gerr("ERROR: mq_open(%s) failed: %d\n", climqname, errno); + _NX_SETERRNO(conn->crdmq); + gerr("ERROR: _MQ_OPEN(%s) failed: %d\n", climqname, + _NX_GETERRNO(conn->crdmq)); goto errout_with_conn; } @@ -155,10 +158,12 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname) attr.mq_msgsize = NX_MXSVRMSGLEN; attr.mq_flags = 0; - conn->cwrmq = mq_open(svrmqname, O_WRONLY|O_CREAT, 0666, &attr); - if (conn->cwrmq == (mqd_t)-1) + conn->cwrmq = _MQ_OPEN(svrmqname, O_WRONLY | O_CREAT, 0666, &attr); + if (conn->cwrmq < 0) { - gerr("ERROR: mq_open(%s) failed: %d\n", svrmqname, errno); + _NX_SETERRNO(conn->cwrmq); + gerr("ERROR: _MQ_OPEN(%s) failed: %d\n", svrmqname, + _NX_GETERRNO(conn->crdmq)); goto errout_with_rmq; } @@ -197,9 +202,9 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname) return (NXHANDLE)conn; errout_with_wmq: - mq_close(conn->cwrmq); + _MQ_CLOSE(conn->cwrmq); errout_with_rmq: - mq_close(conn->crdmq); + _MQ_CLOSE(conn->crdmq); errout_with_conn: lib_ufree(conn); errout: diff --git a/libs/libnx/nxmu/nx_disconnect.c b/libs/libnx/nxmu/nx_disconnect.c index ed9441d8415..d934407815e 100644 --- a/libs/libnx/nxmu/nx_disconnect.c +++ b/libs/libnx/nxmu/nx_disconnect.c @@ -40,10 +40,10 @@ #include #include -#include #include #include +#include #include #include @@ -90,6 +90,6 @@ void nx_disconnect(NXHANDLE handle) { snprintf(climqname, sizeof(climqname), NX_CLIENT_MQNAMEFMT, conn->cid); - mq_unlink(climqname); + _MQ_UNLINK(climqname); } } diff --git a/libs/libnx/nxmu/nx_eventhandler.c b/libs/libnx/nxmu/nx_eventhandler.c index 38ddc4706e6..77160ac2259 100644 --- a/libs/libnx/nxmu/nx_eventhandler.c +++ b/libs/libnx/nxmu/nx_eventhandler.c @@ -80,8 +80,8 @@ static inline void nx_disconnected(FAR struct nxmu_conn_s *conn) { /* Close the server and client MQs */ - mq_close(conn->cwrmq); - mq_close(conn->crdmq); + _MQ_CLOSE(conn->cwrmq); + _MQ_CLOSE(conn->crdmq); /* And free the client structure */