From 38ff6190166e08321e53e974b92d25de3678917b Mon Sep 17 00:00:00 2001 From: linford-wu Date: Tue, 30 Jul 2024 16:16:15 +0800 Subject: [PATCH] library: Fix mica instance startup failure issue Fix the probability that the MCS startup instance program will prompt a response timeout error Signed-off-by: linford-wu --- library/remoteproc/baremetal_rproc.c | 8 -------- mica/micad/socket_listener.c | 6 +++++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/library/remoteproc/baremetal_rproc.c b/library/remoteproc/baremetal_rproc.c index c2c551b..92df65a 100644 --- a/library/remoteproc/baremetal_rproc.c +++ b/library/remoteproc/baremetal_rproc.c @@ -50,8 +50,6 @@ static int pipe_fd[2]; #define SHM_POOL_SIZE 0x20000 static atomic_bool notifier; -static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static void rproc_notify_all(void) { @@ -77,9 +75,6 @@ static void *rproc_wait_event(void *arg) }; notifier = true; - pthread_mutex_lock(&mutex); - pthread_cond_broadcast(&cond); - pthread_mutex_unlock(&mutex); while (notifier) { ret = poll(fds, 2, -1); @@ -122,9 +117,6 @@ static int rproc_register_notifier(void) goto err; } - pthread_mutex_lock(&mutex); - pthread_cond_wait(&cond, &mutex); - pthread_mutex_unlock(&mutex); return 0; err: close(pipe_fd[PIPE_READ_END]); diff --git a/mica/micad/socket_listener.c b/mica/micad/socket_listener.c index 496fea8..23aadd0 100644 --- a/mica/micad/socket_listener.c +++ b/mica/micad/socket_listener.c @@ -37,6 +37,7 @@ typedef int (*listener_cb)(int epoll_fd, void *data); static METAL_DECLARE_LIST(listener_list); static atomic_bool listening; +static atomic_bool created; static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -434,6 +435,7 @@ static void *wait_create_msg(void *arg) listening = true; pthread_mutex_lock(&mutex); + created = true; pthread_cond_broadcast(&cond); pthread_mutex_unlock(&mutex); @@ -460,6 +462,7 @@ static void *wait_create_msg(void *arg) out: pthread_mutex_lock(&mutex); + created = true; pthread_cond_broadcast(&cond); pthread_mutex_unlock(&mutex); return NULL; @@ -503,7 +506,8 @@ int register_socket_listener(void) } pthread_mutex_lock(&mutex); - pthread_cond_wait(&cond, &mutex); + while (!created) + pthread_cond_wait(&cond, &mutex); pthread_mutex_unlock(&mutex); ret = listening ? 0 : -1; -- Gitee