From: Segwon Date: Wed, 3 Jan 2018 03:10:20 +0000 (+0900) Subject: gpio: enhance the interrupted callback thread safty X-Git-Tag: submit/tizen/20180103.062104~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ccce883e3b46aa5a949751723bc7da9e211a7227;p=platform%2Fcore%2Fapi%2Fperipheral-io.git gpio: enhance the interrupted callback thread safty Change-Id: Ib9374b0a62bdf7d8d71604365637d0dfacab69b6 Signed-off-by: Segwon --- 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);