From a069ebb3f3214e16c59cedc3fcbf61bbd0d49878 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 10 Sep 2019 21:26:25 +0200 Subject: [PATCH] porting: Remove BLE_NPL_WAIT_FOREVER from NPL API There is already BLE_NPL_TIME_FOREVER which should be used instead. Also due to int promotion using BLE_NPL_WAIT_FOREVER was causing subtle issues on 64bit asrchitectures when used. --- porting/examples/linux/main.c | 4 ++-- porting/examples/linux_blemesh/main.c | 6 +++--- porting/npl/linux/include/nimble/os_types.h | 2 -- porting/npl/linux/src/os_mutex.c | 2 +- porting/npl/linux/src/os_sem.c | 2 +- porting/npl/linux/test/test_npl_eventq.c | 2 +- porting/npl/linux/test/test_npl_sem.c | 4 ++-- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/porting/examples/linux/main.c b/porting/examples/linux/main.c index 7a86e39c0..9aade75aa 100644 --- a/porting/examples/linux/main.c +++ b/porting/examples/linux/main.c @@ -79,12 +79,12 @@ int main(int argc, char *argv[]) ble_store_ram_init(); ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task, - NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_WAIT_FOREVER, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); /* Create task which handles default event queue for host stack. */ ble_npl_task_init(&s_task_host, "ble_host", ble_host_task, - NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_WAIT_FOREVER, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); pthread_exit(&ret); diff --git a/porting/examples/linux_blemesh/main.c b/porting/examples/linux_blemesh/main.c index aaa842f32..7b8cf25d9 100644 --- a/porting/examples/linux_blemesh/main.c +++ b/porting/examples/linux_blemesh/main.c @@ -63,7 +63,7 @@ void *ble_mesh_adv_task(void *param) void mesh_initialized(void) { ble_npl_task_init(&s_task_mesh_adv, "ble_mesh_adv", ble_mesh_adv_task, - NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_WAIT_FOREVER, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); } @@ -82,12 +82,12 @@ int main(void) ble_store_ram_init(); ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task, - NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_WAIT_FOREVER, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); /* Create task which handles default event queue for host stack. */ ble_npl_task_init(&s_task_host, "ble_host", ble_host_task, - NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_WAIT_FOREVER, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); pthread_exit(&ret); diff --git a/porting/npl/linux/include/nimble/os_types.h b/porting/npl/linux/include/nimble/os_types.h index c9ab85687..a5d8bf548 100644 --- a/porting/npl/linux/include/nimble/os_types.h +++ b/porting/npl/linux/include/nimble/os_types.h @@ -26,8 +26,6 @@ #include #include -#define BLE_NPL_WAIT_FOREVER (-1) - /* The highest and lowest task priorities */ #define OS_TASK_PRI_HIGHEST (sched_get_priority_max(SCHED_RR)) #define OS_TASK_PRI_LOWEST (sched_get_priority_min(SCHED_RR)) diff --git a/porting/npl/linux/src/os_mutex.c b/porting/npl/linux/src/os_mutex.c index 43263ef39..c7d6190e8 100644 --- a/porting/npl/linux/src/os_mutex.c +++ b/porting/npl/linux/src/os_mutex.c @@ -60,7 +60,7 @@ ble_npl_mutex_pend(struct ble_npl_mutex *mu, uint32_t timeout) return BLE_NPL_INVALID_PARAM; } - if (timeout == BLE_NPL_WAIT_FOREVER) { + if (timeout == BLE_NPL_TIME_FOREVER) { err = pthread_mutex_lock(&mu->lock); } else { err = clock_gettime(CLOCK_REALTIME, &mu->wait); diff --git a/porting/npl/linux/src/os_sem.c b/porting/npl/linux/src/os_sem.c index 704c856ef..e3434af5a 100644 --- a/porting/npl/linux/src/os_sem.c +++ b/porting/npl/linux/src/os_sem.c @@ -60,7 +60,7 @@ ble_npl_sem_pend(struct ble_npl_sem *sem, uint32_t timeout) return BLE_NPL_INVALID_PARAM; } - if (timeout == BLE_NPL_WAIT_FOREVER) { + if (timeout == BLE_NPL_TIME_FOREVER) { err = sem_wait(&sem->lock); } else { err = clock_gettime(CLOCK_REALTIME, &wait); diff --git a/porting/npl/linux/test/test_npl_eventq.c b/porting/npl/linux/test/test_npl_eventq.c index d85202c3b..f0c362b92 100644 --- a/porting/npl/linux/test/test_npl_eventq.c +++ b/porting/npl/linux/test/test_npl_eventq.c @@ -94,7 +94,7 @@ int test_get_no_wait(void) int test_get(void) { struct ble_npl_event *ev = ble_npl_eventq_get(&s_eventq, - BLE_NPL_WAIT_FOREVER); + BLE_NPL_TIME_FOREVER); VerifyOrQuit(ev == &s_event, "callout: wrong event passed"); diff --git a/porting/npl/linux/test/test_npl_sem.c b/porting/npl/linux/test/test_npl_sem.c index 713b0c8ef..b62f8e2ad 100644 --- a/porting/npl/linux/test/test_npl_sem.c +++ b/porting/npl/linux/test/test_npl_sem.c @@ -126,10 +126,10 @@ init_app_tasks(void) * Initialize tasks 1 and 2 with the OS. */ ble_npl_task_init(&task1, "task1", task1_handler, NULL, TASK1_PRIO, - BLE_NPL_WAIT_FOREVER, task1_stack, TASK1_STACK_SIZE); + BLE_NPL_TIME_FOREVER, task1_stack, TASK1_STACK_SIZE); ble_npl_task_init(&task2, "task2", task2_handler, NULL, TASK2_PRIO, - BLE_NPL_WAIT_FOREVER, task2_stack, TASK2_STACK_SIZE); + BLE_NPL_TIME_FOREVER, task2_stack, TASK2_STACK_SIZE); return 0; }