From 2b06142232a88f1e5d92f88b8938e88c4f7e3518 Mon Sep 17 00:00:00 2001 From: chao an Date: Wed, 25 Oct 2023 11:23:17 +0800 Subject: [PATCH] kernel: replace all sem_* to nxsem_*: in kernel space syscall cannot be called from kernel space Signed-off-by: chao an --- arch/arm/src/nrf91/nrf91_modem_os.c | 21 ++++++++++--------- arch/xtensa/src/esp32s3/esp32s3_ble_adapter.c | 2 +- drivers/syslog/ramlog.c | 2 +- drivers/virtio/virtio-gpu.c | 9 ++++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/arch/arm/src/nrf91/nrf91_modem_os.c b/arch/arm/src/nrf91/nrf91_modem_os.c index dad289f25d..1389a0f297 100644 --- a/arch/arm/src/nrf91/nrf91_modem_os.c +++ b/arch/arm/src/nrf91/nrf91_modem_os.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -119,7 +120,7 @@ void nrf_waiting_free(struct nrf91_modem_os_waiting_s *w) { nxmutex_lock(&g_nrf91_modem_os.waiting_lock); - sem_destroy(&w->sem); + nxsem_destroy(&w->sem); w->context = 0; w->waiting = false; @@ -176,7 +177,7 @@ void nrf_modem_os_shutdown(void) waiting = &g_nrf91_modem_os.waiting[i]; if (waiting->waiting == true) { - sem_post(&waiting->sem); + nxsem_post(&waiting->sem); } } @@ -298,7 +299,7 @@ int32_t nrf_modem_os_timedwait(uint32_t context, int32_t *timeout) { /* Wait for event */ - sem_wait(&waiting->sem); + nxsem_wait(&waiting->sem); ret = OK; } else @@ -308,7 +309,7 @@ int32_t nrf_modem_os_timedwait(uint32_t context, int32_t *timeout) abstime.tv_sec = *timeout / 1000; abstime.tv_nsec = (*timeout % 1000) * 1000000; - sem_timedwait(&waiting->sem, &abstime); + nxsem_timedwait(&waiting->sem, &abstime); } /* Free a waiting slot */ @@ -368,7 +369,7 @@ void nrf_modem_os_event_notify(uint32_t context) { if (waiting->context == context || context == 0) { - sem_post(&waiting->sem); + nxsem_post(&waiting->sem); } } } @@ -433,7 +434,7 @@ int nrf_modem_os_sem_init(void **sem, unsigned int initial_count, UNUSED(limit); DEBUGASSERT(g_nrf91_modem_os.sem_cntr < NRF_MODEM_OS_NUM_SEM_REQUIRED); - ret = sem_init(modemsem, 0, initial_count); + ret = nxsem_init(modemsem, 0, initial_count); g_nrf91_modem_os.sem_cntr++; *sem = (void *)modemsem; @@ -451,7 +452,7 @@ int nrf_modem_os_sem_init(void **sem, unsigned int initial_count, void nrf_modem_os_sem_give(void *sem) { - sem_post((sem_t *)sem); + nxsem_post((sem_t *)sem); } /**************************************************************************** @@ -469,7 +470,7 @@ int nrf_modem_os_sem_take(void *sem, int timeout) if (timeout == -1) { - ret = sem_wait(s); + ret = nxsem_wait(s); } else { @@ -478,7 +479,7 @@ int nrf_modem_os_sem_take(void *sem, int timeout) abstime.tv_sec = timeout / 1000; abstime.tv_nsec = (timeout % 1000) * 1000000; - ret = sem_timedwait(s, &abstime); + ret = nxsem_timedwait(s, &abstime); } return ret; @@ -496,7 +497,7 @@ unsigned int nrf_modem_os_sem_count_get(void *sem) { int sval = 0; - sem_getvalue((sem_t *)sem, &sval); + nxsem_get_value((sem_t *)sem, &sval); return sval; } diff --git a/arch/xtensa/src/esp32s3/esp32s3_ble_adapter.c b/arch/xtensa/src/esp32s3/esp32s3_ble_adapter.c index 24ce6cc182..a80a1da389 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_ble_adapter.c +++ b/arch/xtensa/src/esp32s3/esp32s3_ble_adapter.c @@ -935,7 +935,7 @@ static void *semphr_create_wrapper(uint32_t max, uint32_t init) static void semphr_delete_wrapper(void *semphr) { struct bt_sem_s *bt_sem = (struct bt_sem_s *)semphr; - sem_destroy(&bt_sem->sem); + nxsem_destroy(&bt_sem->sem); kmm_free(bt_sem); } diff --git a/drivers/syslog/ramlog.c b/drivers/syslog/ramlog.c index bb0ecddee3..bac15c5be8 100644 --- a/drivers/syslog/ramlog.c +++ b/drivers/syslog/ramlog.c @@ -179,7 +179,7 @@ static int ramlog_readnotify(FAR struct ramlog_dev_s *priv) { int semcount = 0; - sem_getvalue(&priv->rl_waitsem, &semcount); + nxsem_get_value(&priv->rl_waitsem, &semcount); if (semcount >= 0) { break; diff --git a/drivers/virtio/virtio-gpu.c b/drivers/virtio/virtio-gpu.c index 3c75cd0b22..2e912919bc 100644 --- a/drivers/virtio/virtio-gpu.c +++ b/drivers/virtio/virtio-gpu.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -145,17 +146,17 @@ static int virtio_gpu_send_cmd(FAR struct virtqueue *vq, sem_t sem; struct virtio_gpu_cookie_s cookie; - sem_init(&sem, 0, 0); + nxsem_init(&sem, 0, 0); cookie.blocking = true; cookie.p = &sem; ret = virtqueue_add_buffer(vq, buf_list, readable, writable, &cookie); if (ret >= 0) { virtqueue_kick(vq); - sem_wait(&sem); + nxsem_wait(&sem); } - sem_destroy(&sem); + nxsem_destroy(&sem); } else { @@ -200,7 +201,7 @@ static void virtio_gpu_done(FAR struct virtqueue *vq) { if (cookie->blocking) { - sem_post((FAR sem_t *)cookie->p); + nxsem_post((FAR sem_t *)cookie->p); } else {