gpio: enhance the interrupted callback thread safty 41/165641/1
authorSegwon <segwon.han@samsung.com>
Wed, 3 Jan 2018 03:10:20 +0000 (12:10 +0900)
committerSegwon <segwon.han@samsung.com>
Wed, 3 Jan 2018 03:10:20 +0000 (12:10 +0900)
Change-Id: Ib9374b0a62bdf7d8d71604365637d0dfacab69b6
Signed-off-by: Segwon <segwon.han@samsung.com>
include/peripheral_handle.h
src/interface/peripheral_interface_gpio.c

index e07c4f1..18f260d 100644 (file)
@@ -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;
 
 /**
index 2695a86..90c2a21 100644 (file)
@@ -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);