From 5a9583cc64058d096329da5a9bef773538da9492 Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Tue, 17 Aug 2021 11:21:58 +0800 Subject: [PATCH] solve the problem of endless loop Signed-off-by: YOUR_NAME --- core/adapter/syscall/src/hdf_syscall_adapter.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/adapter/syscall/src/hdf_syscall_adapter.c b/core/adapter/syscall/src/hdf_syscall_adapter.c index d38978319..2759120dc 100644 --- a/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -28,6 +28,7 @@ #define EVENT_READ_BUFF_MAX (20 * 1024) // 20k #define SYSCALL_INVALID_FD (-1) #define HDF_PFD_GROW_SIZE 4 +#define TIMEOUT_US 100000 // 100ms static bool HaveOnlyOneElement(const struct DListHead *head) { @@ -589,6 +590,7 @@ static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread) switch (thread->status) { case LISTENER_RUNNING: { + int count = 0; uint32_t stopCount = 0; OsalMutexLock(&thread->mutex); thread->adapter = NULL; @@ -608,11 +610,17 @@ static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread) HDF_LOGE("%s:failed to exit listener thread with ioctl, will go async way", __func__); return; } - while (thread->status != LISTENER_EXITED) { + while (thread->status != LISTENER_EXITED && count <= TIMEOUT_US) { OsalUSleep(1); + count++; + } + if (thread->status == LISTENER_EXITED) { + HDF_LOGI("poll thread exited"); + HdfDevListenerThreadFree(thread); + } else { + thread->shouldStop = true; + HDF_LOGE("wait poll thread exit timeout, async exit"); } - HDF_LOGI("poll thread exited"); - HdfDevListenerThreadFree(thread); return; } case LISTENER_STARTED: -- Gitee