From 90177889b7430454b57e22eded9ccc6f2974f1d3 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 5 Aug 2020 08:42:35 +0200 Subject: [PATCH] treewide: Cleanup access to internal variables Replace direct accesses to sched_active_thread and sched_active_pid with the helper functions thread_getpid() and thread_get_active(). This serves two purposes: 1. It makes accidental writes to those variable from outside core less likely. 2. Casting off the volatile qualifier is now well contained to those two functions --- drivers/kw2xrf/kw2xrf_netdev.c | 2 +- drivers/kw41zrf/kw41zrf_netdev.c | 2 +- examples/riot_and_cpp/main.cpp | 6 ++++-- pkg/lvgl/contrib/lvgl.c | 2 +- pkg/nimble/netif/nimble_netif.c | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/kw2xrf/kw2xrf_netdev.c b/drivers/kw2xrf/kw2xrf_netdev.c index 24bb36774b..44ea7702fb 100644 --- a/drivers/kw2xrf/kw2xrf_netdev.c +++ b/drivers/kw2xrf/kw2xrf_netdev.c @@ -71,7 +71,7 @@ static int _init(netdev_t *netdev) { kw2xrf_t *dev = (kw2xrf_t *)netdev; - dev->thread = (thread_t *)thread_get(thread_getpid()); + dev->thread = thread_get_active(); /* initialize SPI and GPIOs */ if (kw2xrf_init(dev, &_irq_handler)) { diff --git a/drivers/kw41zrf/kw41zrf_netdev.c b/drivers/kw41zrf/kw41zrf_netdev.c index a5e15cb878..4d5a7f39ad 100644 --- a/drivers/kw41zrf/kw41zrf_netdev.c +++ b/drivers/kw41zrf/kw41zrf_netdev.c @@ -86,7 +86,7 @@ static void kw41zrf_irq_handler(void *arg) static int kw41zrf_netdev_init(netdev_t *netdev) { kw41zrf_t *dev = (kw41zrf_t *)netdev; - dev->thread = (thread_t *)thread_get(thread_getpid()); + dev->thread = thread_get_active(); /* initialize hardware */ if (kw41zrf_init(dev, kw41zrf_irq_handler)) { diff --git a/examples/riot_and_cpp/main.cpp b/examples/riot_and_cpp/main.cpp index d228616f92..ed4bb02cee 100644 --- a/examples/riot_and_cpp/main.cpp +++ b/examples/riot_and_cpp/main.cpp @@ -48,7 +48,8 @@ int main() THREAD_CREATE_WOUT_YIELD, threadA_func, NULL, "thread A"); - printf("******** Hello, you're in thread #%" PRIkernel_pid " ********\n", sched_active_pid); + printf("******** Hello, you're in thread #%" PRIkernel_pid " ********\n", + thread_getpid()); printf("We'll test C++ class and methods here!\n"); cpp_class cpp_obj; @@ -83,7 +84,8 @@ void *threadA_func(void *) int day = 13, month = 6, year = 2014; int ret_day; - printf("******** Hello, you're in thread #%" PRIkernel_pid " ********\n", sched_active_pid); + printf("******** Hello, you're in thread #%" PRIkernel_pid " ********\n", + thread_getpid()); printf("We'll test some C functions here!\n"); printf("\n-= hello function =-\n"); diff --git a/pkg/lvgl/contrib/lvgl.c b/pkg/lvgl/contrib/lvgl.c index 6f1f8eb0e3..3ea44fcd77 100644 --- a/pkg/lvgl/contrib/lvgl.c +++ b/pkg/lvgl/contrib/lvgl.c @@ -162,6 +162,6 @@ void lvgl_init(screen_dev_t *screen_dev) void lvgl_wakeup(void) { - thread_t *tcb = (thread_t *)sched_threads[_task_thread_pid]; + thread_t *tcb = thread_get(_task_thread_pid); thread_flags_set(tcb, LVGL_THREAD_FLAG); } diff --git a/pkg/nimble/netif/nimble_netif.c b/pkg/nimble/netif/nimble_netif.c index 4dc5f6b28a..31cad107c8 100644 --- a/pkg/nimble/netif/nimble_netif.c +++ b/pkg/nimble/netif/nimble_netif.c @@ -93,7 +93,7 @@ static void _netif_init(gnrc_netif_t *netif) gnrc_netif_default_init(netif); /* save the threads context pointer, so we can set its flags */ - _netif_thread = (thread_t *)thread_get(thread_getpid()); + _netif_thread = thread_get_active(); #if IS_USED(MODULE_GNRC_NETIF_6LO) /* we disable fragmentation for this device, as the L2CAP layer takes care