From ccce883e3b46aa5a949751723bc7da9e211a7227 Mon Sep 17 00:00:00 2001 From: Segwon Date: Wed, 3 Jan 2018 12:10:20 +0900 Subject: [PATCH] gpio: enhance the interrupted callback thread safty Change-Id: Ib9374b0a62bdf7d8d71604365637d0dfacab69b6 Signed-off-by: Segwon --- include/peripheral_handle.h | 2 +- src/interface/peripheral_interface_gpio.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/peripheral_handle.h b/include/peripheral_handle.h index e07c4f1..18f260d 100644 --- a/include/peripheral_handle.h +++ b/include/peripheral_handle.h @@ -24,7 +24,7 @@ typedef struct _peripheral_gpio_interrupted_cb_info_s { peripheral_gpio_interrupted_cb cb; peripheral_error_e error; void *user_data; - int status; + gint status; } interrupted_cb_info_s; /** diff --git a/src/interface/peripheral_interface_gpio.c b/src/interface/peripheral_interface_gpio.c index 2695a86..90c2a21 100644 --- a/src/interface/peripheral_interface_gpio.c +++ b/src/interface/peripheral_interface_gpio.c @@ -204,7 +204,7 @@ static gpointer __peripheral_interface_gpio_poll(void *data) uint32_t value; - while (gpio->cb_info.status == GPIO_INTERRUPTED_CALLBACK_SET) { + while (g_atomic_int_get(&gpio->cb_info.status) == GPIO_INTERRUPTED_CALLBACK_SET) { poll_state = poll(&poll_fd, 1, 3000); @@ -250,7 +250,7 @@ int peripheral_interface_gpio_set_interrupted_cb(peripheral_gpio_h gpio, periphe gpio->cb_info.cb = callback; gpio->cb_info.user_data = user_data; - gpio->cb_info.status = GPIO_INTERRUPTED_CALLBACK_SET; + g_atomic_int_set(&gpio->cb_info.status, GPIO_INTERRUPTED_CALLBACK_SET); gpio->cb_info.thread = g_thread_new(NULL, __peripheral_interface_gpio_poll, gpio); return PERIPHERAL_ERROR_NONE; @@ -258,7 +258,7 @@ int peripheral_interface_gpio_set_interrupted_cb(peripheral_gpio_h gpio, periphe int peripheral_interface_gpio_unset_interrupted_cb(peripheral_gpio_h gpio) { - gpio->cb_info.status = GPIO_INTERRUPTED_CALLBACK_UNSET; + g_atomic_int_set(&gpio->cb_info.status, GPIO_INTERRUPTED_CALLBACK_UNSET); if (gpio->cb_info.thread != NULL) { g_thread_join(gpio->cb_info.thread); -- 2.34.1