Detach pthread after using it 77/234277/3
authorKichan Kwon <k_c.kwon@samsung.com>
Mon, 25 May 2020 03:12:37 +0000 (12:12 +0900)
committerKunhoon Baik <knhoon.baik@samsung.com>
Tue, 26 May 2020 00:47:19 +0000 (00:47 +0000)
Change-Id: Id15d3b1943c95c669e2a44962d4cca23d6e55790
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/battery_dump/bm_listeners.c

index 5a05fcc..05bff56 100644 (file)
@@ -60,6 +60,7 @@ static int prev_lock = 0;
 static int prev_battery_level = 0;
 static event_pool events_buf[10];
 static int buff_count = 0;
+static pthread_attr_t attr;
 static pthread_cond_t fill = PTHREAD_COND_INITIALIZER;
 static pthread_cond_t empty = PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t battery_lister_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -1173,7 +1174,7 @@ void __bm_bt_adapter_state_changed_cb(int result, bt_adapter_state_e adapter_sta
        bt_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, bt_event)) {
+       if (pthread_create(&producer, &attr, event_producer, bt_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1202,7 +1203,7 @@ void __bm_bt_device_connection_state_changed_cb(bool connected, bt_device_connec
        bt_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, bt_event)) {
+       if (pthread_create(&producer, &attr, event_producer, bt_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1238,7 +1239,7 @@ static void __bm_bt_device_discovery_state_changed_cb(int result, bt_adapter_dev
        bt_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, bt_event)) {
+       if (pthread_create(&producer, &attr, event_producer, bt_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1268,7 +1269,7 @@ static void __bm_wifi_device_state_callback(wifi_manager_device_state_e state, v
        wifi_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, wifi_event)) {
+       if (pthread_create(&producer, &attr, event_producer, wifi_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1293,7 +1294,7 @@ static void __bm_wifi_scan_changed_callback(wifi_manager_scan_state_e state, voi
        wifi_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, wifi_event)) {
+       if (pthread_create(&producer, &attr, event_producer, wifi_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1322,7 +1323,7 @@ static void __bm_wifi_connection_state_changed_callback(wifi_manager_connection_
        wifi_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, wifi_event)) {
+       if (pthread_create(&producer, &attr, event_producer, wifi_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1356,7 +1357,7 @@ static void __bm_device_display_change(device_callback_e type, void *value, void
        device_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, device_event)) {
+       if (pthread_create(&producer, &attr, event_producer, device_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1417,7 +1418,7 @@ static void __bm_display_brightness_change(keynode_t *key, void* data)
        display_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, display_event)) {
+       if (pthread_create(&producer, &attr, event_producer, display_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1445,7 +1446,7 @@ static void __bm_battery_capacity_change(keynode_t *key, void* data)
        charging_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, charging_event)) {
+       if (pthread_create(&producer, &attr, event_producer, charging_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1473,7 +1474,7 @@ static void __bm_charging_status_change(keynode_t *key, void* data)
        charging_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, charging_event)) {
+       if (pthread_create(&producer, &attr, event_producer, charging_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1506,7 +1507,7 @@ static void __bm_location_change(keynode_t *key, void* data)
        location_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, location_event)) {
+       if (pthread_create(&producer, &attr, event_producer, location_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1585,7 +1586,7 @@ static void _bm_notify_signal_strength(TapiHandle *handle, const char *noti_id,
        signal_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, signal_event)) {
+       if (pthread_create(&producer, &attr, event_producer, signal_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1639,7 +1640,7 @@ static void _bm_notify_modem_power(TapiHandle *handle, const char *noti_id, void
                modem_power_event->app = NULL;
 
                pthread_t producer;
-               if (pthread_create(&producer, NULL, event_producer, modem_power_event)) {
+               if (pthread_create(&producer, &attr, event_producer, modem_power_event)) {
                        _ERR("Failed to pthread_create.");
                        return;
                }
@@ -1679,7 +1680,7 @@ static void create_lock_event(char *lock_type)
        location_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, location_event)) {
+       if (pthread_create(&producer, &attr, event_producer, location_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1754,7 +1755,7 @@ static void __sleep_signal_callback(GDBusConnection *conn,
        sleep_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, sleep_event)) {
+       if (pthread_create(&producer, &attr, event_producer, sleep_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1784,7 +1785,7 @@ static void __wakeup_signal_callback(GDBusConnection *conn,
        wakeup_event->app = NULL;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, wakeup_event)) {
+       if (pthread_create(&producer, &attr, event_producer, wakeup_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -1827,7 +1828,7 @@ static void __app_status_signal_callback(GDBusConnection *conn,
        app_event->app = appid;
 
        pthread_t producer;
-       if (pthread_create(&producer, NULL, event_producer, app_event)) {
+       if (pthread_create(&producer, &attr, event_producer, app_event)) {
                _ERR("Failed to pthread_create.");
                return;
        }
@@ -2162,7 +2163,7 @@ static int bm_initialize_history_data_obj()
        ENTER;
 
        pthread_t consumer;
-       if (pthread_create(&consumer, NULL, event_consumer, NULL)) {
+       if (pthread_create(&consumer, &attr, event_consumer, NULL)) {
                _ERR("Failed to pthread_create.");
                return BATTERY_MONITOR_ERROR_NOT_SUPPORTED;
        }
@@ -2203,6 +2204,15 @@ int bd_initialize_listeners(void)
                return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
        }
 
+       /* Initialize pthread attributes */
+       if (pthread_attr_init(&attr) != 0) {
+               _ERR("pthread_attr_init failed");
+               return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+       }
+
+       if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0)
+               _ERR("pthread_attr_setdetachstate failed");
+
        /*Initialize DBus*/
        if(bm_listener_dbus_init())
                _ERR("bm_listener_dbus_init failed \n");
@@ -2345,6 +2355,10 @@ int bd_deinitialize_listeners()
        if(bm_listener_dbus_deinit())
                _ERR("failed to de-init dbus ");
 
+       /* de-initialize pthread attributes */
+       if (pthread_attr_destroy(&attr) != 0)
+               _ERR("pthread_attr_destroy failed");
+
        g_hash_table_destroy(app_list);
 
        if (data_obj)