From 612467221af118c1cfdea3640c4fec3fdf965ec3 Mon Sep 17 00:00:00 2001 From: hw_llm Date: Thu, 26 Dec 2024 15:15:32 +0800 Subject: [PATCH] =?UTF-8?q?Description:=20=E4=BF=AE=E5=A4=8Depoll=5Fwait?= =?UTF-8?q?=20=E6=9D=A1=E4=BB=B6=E7=AB=9E=E4=BA=89=E6=BC=8F=E6=B4=9E=20Iss?= =?UTF-8?q?ueNo:=20https://gitee.com/openharmony/kernel=5Fliteos=5Fa/issue?= =?UTF-8?q?s/IBDWNX=3Ffrom=3Dproject-issue=20Feature=20Or=20Bugfix:=20Bugf?= =?UTF-8?q?ix=20Binary=20Source:=20No=20Signed-off-by:=20hw=5Fllm=20=20=EF=BC=88cherry=20picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fs/vfs/epoll/fs_epoll.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fs/vfs/epoll/fs_epoll.c b/fs/vfs/epoll/fs_epoll.c index 9252e80c..230da8b9 100644 --- a/fs/vfs/epoll/fs_epoll.c +++ b/fs/vfs/epoll/fs_epoll.c @@ -297,21 +297,22 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev) int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout) { struct epoll_head *epHead = NULL; - int ret; + int ret = -1; int counter; int i; struct pollfd *pFd = NULL; int pollSize; + (VOID)pthread_mutex_lock(&g_epollMutex); epHead = EpollGetDataBuff(epfd); if (epHead == NULL) { set_errno(EBADF); - return -1; + goto OUT_RELEASE; } if ((maxevents <= 0) || (evs == NULL)) { set_errno(EINVAL); - return -1; + goto OUT_RELEASE; } if (maxevents > epHead->nodeCount) { @@ -323,7 +324,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout pFd = malloc(sizeof(struct pollfd) * pollSize); if (pFd == NULL) { set_errno(EINVAL); - return -1; + goto OUT_RELEASE; } for (i = 0; i < epHead->nodeCount; i++) { @@ -335,7 +336,8 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout ret = poll(pFd, pollSize, timeout); if (ret <= 0) { free(pFd); - return 0; + ret = 0; + goto OUT_RELEASE; } for (i = 0, counter = 0; i < ret && counter < pollSize; counter++) { @@ -347,6 +349,10 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout } free(pFd); - return i; + ret = i; + +OUT_RELEASE: + (VOID)pthread_mutex_unlock(&g_epollMutex); + return ret; } -- Gitee