diff --git a/core/adapter/syscall/src/hdf_syscall_adapter.c b/core/adapter/syscall/src/hdf_syscall_adapter.c index d389783192f3c666b04d32ab1511409288623237..51de80d903b3182cc7975efd7e7f7f5627b7b7da 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 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,8 +610,18 @@ 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) { + thread->shouldStop = true; + HDF_LOGE("OsalUSleep exited"); + } + if (count == TIMEOUT_US) { + thread->shouldStop = true; + HDF_LOGE("OsalUSleep Timeout"); } HDF_LOGI("poll thread exited"); HdfDevListenerThreadFree(thread);