Added multi-threaded support in wifi-direct CAPI. 42/254142/3
authorNiraj Kumar Goit <niraj.g@samsung.com>
Tue, 23 Feb 2021 14:07:48 +0000 (19:37 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Mon, 1 Mar 2021 07:02:25 +0000 (12:32 +0530)
This patch removes thread-scope variables for sharing handles between
multiple threads.

Change-Id: If106e2d429e6377d7b39eafa794dd5d544a2e60a
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
src/include/wifi-direct-client-proxy.h
src/wifi-direct-client-proxy.c
src/wifi-direct-dbus.c

index b83e2c9e1058a7b73fc7f12baf30ac1d99e14414..94b03fcc3d80bc21f6a6b8dafb3ac791a12d6b47 100644 (file)
                } \
        } while (0)
 
+/**
+ * To lock and unlock mutex
+ */
+#define WFD_LOCK \
+       do { \
+               _wfd_lock(); \
+       } while(0)
+
+#define WFD_UNLOCK \
+       do { \
+               _wfd_unlock(); \
+       } while(0)
+
+void _wfd_lock(void);
+void _wfd_unlock(void);
+
 typedef struct {
        bool is_registered;
        bool is_display_supported;
index 4b6376c71a8836d2494287be9f9c3660851e55fa..da74dc283176775569c31c6cdcbc9ec57b10e7a0 100755 (executable)
@@ -68,7 +68,8 @@
  *  Global Variables
  *****************************************************************************/
 
-static __thread wifi_direct_client_info_s g_client_info = {0, };
+static pthread_mutex_t g_wfd_thread_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+static wifi_direct_client_info_s g_client_info = {0, };
 
 /*****************************************************************************
  *  Local Functions Definition
@@ -132,6 +133,16 @@ static int __wfd_check_service_discovery_feature()
        return WIFI_DIRECT_ERROR_NONE;
 }
 
+void _wfd_lock(void)
+{
+       pthread_mutex_lock(&g_wfd_thread_mutex);
+}
+
+void _wfd_unlock(void)
+{
+       pthread_mutex_unlock(&g_wfd_thread_mutex);
+}
+
 //LCOV_EXCL_START
 void __wfd_vconf_state_changed_cb(keynode_t *key, void *data)
 {
@@ -139,8 +150,10 @@ void __wfd_vconf_state_changed_cb(keynode_t *key, void *data)
        int state = 0;
        int res = 0;
 
+       WFD_LOCK;
        if (!g_client_info.state_cb) {
                WDC_LOGI("g_state_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return; //LCOV_EXCL_LINE
        }
@@ -149,6 +162,7 @@ void __wfd_vconf_state_changed_cb(keynode_t *key, void *data)
        if (res < 0) {
                WDC_LOGE("Failed to get vconf value [%s]\n",
                         VCONFKEY_WIFI_DIRECT_STATE);
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -173,11 +187,13 @@ void __wfd_vconf_state_changed_cb(keynode_t *key, void *data)
                state = WIFI_DIRECT_STATE_DISCONNECTING;
        } else {
                WDC_LOGE("This state cannot be set as wifi_direct vconf state[%d]", state);
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
 
        g_client_info.state_cb(state, g_client_info.user_data_for_cb_state);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return;
@@ -195,14 +211,18 @@ void wifi_direct_process_manage_activation(GDBusConnection *connection,
 {
        __WDC_LOG_FUNC_START__;
        int error_code;
+
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!client->activation_cb) {
                WDC_LOGI("activation_cb is NULL!!");
+               WFD_UNLOCK;
                return; //LCOV_EXCL_LINE
        }
 
        if (!parameters) {
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -213,6 +233,7 @@ void wifi_direct_process_manage_activation(GDBusConnection *connection,
                              WIFI_DIRECT_DEVICE_STATE_ACTIVATED,
                              client->user_data_for_cb_activation);
 
+       WFD_UNLOCK;
        __WDC_LOG_FUNC_END__;
 }
 
@@ -226,15 +247,19 @@ void wifi_direct_process_manage_deactivation(GDBusConnection *connection,
 {
        __WDC_LOG_FUNC_START__;
        int error_code;
+
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!parameters) {
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return; //LCOV_EXCL_LINE
        }
 
        if (!client->activation_cb) {
                WDC_LOGI("activation_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -244,6 +269,7 @@ void wifi_direct_process_manage_deactivation(GDBusConnection *connection,
        client->activation_cb(error_code,
                              WIFI_DIRECT_DEVICE_STATE_DEACTIVATED,
                              client->user_data_for_cb_activation);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -260,15 +286,19 @@ void wifi_direct_process_manage_connection(GDBusConnection *connection,
        int error_code;
        wifi_direct_connection_state_e connection_state;
        const gchar *peer_mac_address = NULL;
+
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!parameters) {
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
 
        if (!client->connection_cb) {
                WDC_LOGI("connection_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -280,6 +310,7 @@ void wifi_direct_process_manage_connection(GDBusConnection *connection,
                              connection_state,
                              peer_mac_address,
                              client->user_data_for_cb_connection);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -296,15 +327,19 @@ void wifi_direct_process_manage_disconnection(GDBusConnection *connection,
        int error_code;
        wifi_direct_connection_state_e connection_state;
        const gchar *peer_mac_address = NULL;
+
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!parameters) {
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
 
        if (!client->connection_cb) {
                WDC_LOGI("connection_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -316,6 +351,7 @@ void wifi_direct_process_manage_disconnection(GDBusConnection *connection,
                              connection_state,
                              peer_mac_address,
                              client->user_data_for_cb_connection);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -336,10 +372,12 @@ void wifi_direct_process_manage_disconnection_ind(GDBusConnection *connection,
        const gchar *peer_dev_name = NULL;
        wifi_direct_connection_state_cb_data_s data_s;
 
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!parameters) {
                __WDC_LOG_FUNC_END__;
+               WFD_UNLOCK;
                return;
        }
 
@@ -364,6 +402,7 @@ void wifi_direct_process_manage_disconnection_ind(GDBusConnection *connection,
                                        client->user_data_for_cb_peer_data_connection);
        }
 
+       WFD_UNLOCK;
        __WDC_LOG_FUNC_END__;
 }
 //LCOV_EXCL_STOP
@@ -383,9 +422,12 @@ void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection,
        const gchar *peer_mac_address = NULL;
        const gchar *assigned_ip_address = NULL;
        int ret = 0;
+
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!parameters) {
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -395,6 +437,7 @@ void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection,
 
        if (!client->ip_assigned_cb) {
                WDC_LOGI("ip_assigned_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -421,6 +464,8 @@ void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection,
                        client->user_data_for_cb_ip_assigned);
 
        g_variant_unref(reply);
+       WFD_UNLOCK;
+
        __WDC_LOG_FUNC_END__;
 }
 
@@ -433,10 +478,12 @@ void wifi_direct_process_manage_listen_started(GDBusConnection *connection,
                                               gpointer user_data)
 {
        __WDC_LOG_FUNC_START__;
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!client->discover_cb) {
                WDC_LOGI("discover_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -444,6 +491,7 @@ void wifi_direct_process_manage_listen_started(GDBusConnection *connection,
        client->discover_cb(WIFI_DIRECT_ERROR_NONE,
                            WIFI_DIRECT_ONLY_LISTEN_STARTED,
                            client->user_data_for_cb_discover);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -457,10 +505,12 @@ void wifi_direct_process_manage_discovery_started(GDBusConnection *connection,
                                                  gpointer user_data)
 {
        __WDC_LOG_FUNC_START__;
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!client->discover_cb) {
                WDC_LOGI("discover_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -468,6 +518,7 @@ void wifi_direct_process_manage_discovery_started(GDBusConnection *connection,
        client->discover_cb(WIFI_DIRECT_ERROR_NONE,
                            WIFI_DIRECT_DISCOVERY_STARTED,
                            client->user_data_for_cb_discover);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -481,10 +532,12 @@ void wifi_direct_process_manage_discovery_finished(GDBusConnection *connection,
                                                   gpointer user_data)
 {
        __WDC_LOG_FUNC_START__;
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!client->discover_cb) {
                WDC_LOGI("discover_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -492,6 +545,7 @@ void wifi_direct_process_manage_discovery_finished(GDBusConnection *connection,
        client->discover_cb(WIFI_DIRECT_ERROR_NONE,
                            WIFI_DIRECT_DISCOVERY_FINISHED,
                            client->user_data_for_cb_discover);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -506,9 +560,11 @@ void wifi_direct_process_manage_peer_found(GDBusConnection *connection,
 {
        __WDC_LOG_FUNC_START__;
        const gchar *peer_mac_address = NULL;
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!parameters) {
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -526,6 +582,7 @@ void wifi_direct_process_manage_peer_found(GDBusConnection *connection,
 
        if (!client->discover_cb) {
                WDC_LOGI("discover_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -533,6 +590,7 @@ void wifi_direct_process_manage_peer_found(GDBusConnection *connection,
        client->discover_cb(WIFI_DIRECT_ERROR_NONE,
                            WIFI_DIRECT_DISCOVERY_FOUND,
                            client->user_data_for_cb_discover);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -547,9 +605,11 @@ void wifi_direct_process_manage_peer_lost(GDBusConnection *connection,
 {
        __WDC_LOG_FUNC_START__;
        const gchar *peer_mac_address = NULL;
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!parameters) {
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -567,6 +627,7 @@ void wifi_direct_process_manage_peer_lost(GDBusConnection *connection,
 
        if (!client->discover_cb) {
                WDC_LOGI("discover_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -574,6 +635,7 @@ void wifi_direct_process_manage_peer_lost(GDBusConnection *connection,
        client->discover_cb(WIFI_DIRECT_ERROR_NONE,
                            WIFI_DIRECT_DISCOVERY_LOST,
                            client->user_data_for_cb_discover);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -588,10 +650,12 @@ void wifi_direct_process_group_created(GDBusConnection *connection,
                                       gpointer user_data)
 {
        __WDC_LOG_FUNC_START__;
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!client->connection_cb) {
                WDC_LOGI("connection_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -600,6 +664,7 @@ void wifi_direct_process_group_created(GDBusConnection *connection,
                              WIFI_DIRECT_GROUP_CREATED,
                              "",
                              client->user_data_for_cb_connection);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -613,10 +678,12 @@ void wifi_direct_process_group_destroyed(GDBusConnection *connection,
                                         gpointer user_data)
 {
        __WDC_LOG_FUNC_START__;
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!client->connection_cb) {
                WDC_LOGI("connection_cb is NULL!!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -625,6 +692,7 @@ void wifi_direct_process_group_destroyed(GDBusConnection *connection,
                              WIFI_DIRECT_GROUP_DESTROYED,
                              "",
                              client->user_data_for_cb_connection);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -640,16 +708,19 @@ void wifi_direct_process_service_discovery_started(GDBusConnection *connection,
                                                   gpointer user_data)
 {
        __WDC_LOG_FUNC_START__;
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!client->is_service_discovery_supported) {
                WDC_LOGI("service discovery is not supported\n");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
 
        if (!client->service_cb) {
                WDC_LOGI("service_cb is NULL!!\n");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -660,6 +731,7 @@ void wifi_direct_process_service_discovery_started(GDBusConnection *connection,
                           "",
                           "",
                           client->user_data_for_cb_service);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -676,15 +748,19 @@ void wifi_direct_process_service_discovery_found(GDBusConnection *connection,
        wifi_direct_service_type_e service_type;
        const gchar* response_data = NULL;
        const gchar* peer_mac_address = NULL;
+
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!client->is_service_discovery_supported) {
                WDC_LOGI("service discovery is not supported\n");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
 
        if (!parameters) {
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -694,6 +770,7 @@ void wifi_direct_process_service_discovery_found(GDBusConnection *connection,
 
        if (!client->service_cb) {
                WDC_LOGI("service_cb is NULL!!\n");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -704,6 +781,7 @@ void wifi_direct_process_service_discovery_found(GDBusConnection *connection,
                           (void *) response_data,
                           peer_mac_address,
                           client->user_data_for_cb_service);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -717,16 +795,19 @@ void wifi_direct_process_service_discovery_finished(GDBusConnection *connection,
                                                    gpointer user_data)
 {
        __WDC_LOG_FUNC_START__;
+       WFD_LOCK;
        wifi_direct_client_info_s *client = __wfd_get_control();
 
        if (!client->is_service_discovery_supported) {
                WDC_LOGI("service discovery is not supported\n");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
 
        if (!client->service_cb) {
                WDC_LOGI("service_cb is NULL!!\n");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return;
        }
@@ -737,6 +818,7 @@ void wifi_direct_process_service_discovery_finished(GDBusConnection *connection,
                           "",
                           "",
                           client->user_data_for_cb_service);
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 }
@@ -838,8 +920,10 @@ static void __wfd_client_extract_discovered_peer_info(GVariantIter *iter,
                        info->secondary_device_type = g_variant_get_uint16(var);
 
                } else if (!g_strcmp0(key, "IsWfdDevice")) {
+                       WFD_LOCK;
                        if (g_client_info.is_display_supported)
                                info->is_miracast_device = g_variant_get_boolean(var);
+                       WFD_UNLOCK;
                } else {
                        ;/* Do Nothing */
                }
@@ -858,16 +942,17 @@ EXPORT_API int wifi_direct_initialize(void)
        GVariant *reply = NULL;
        int res = 0;
 
+       WFD_LOCK;
        if (g_client_info.is_registered == TRUE) {
                WDC_LOGW("Warning!!! Already registered\nUpdate user data and callback!");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return WIFI_DIRECT_ERROR_ALREADY_INITIALIZED;
        }
 
-       CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
-
        if (wifi_direct_dbus_init() == FALSE) {
                WDC_LOGW("Failed to initialize dbus");
+               WFD_UNLOCK;
                __WDC_LOG_FUNC_END__;
                return WIFI_DIRECT_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
@@ -877,6 +962,7 @@ EXPORT_API int wifi_direct_initialize(void)
        res = __net_wifidirect_gerror_to_enum(error);
        if (res != WIFI_DIRECT_ERROR_NONE) {
                WDC_LOGE("Failed to Add Active Client");
+               WFD_UNLOCK;
                return res;
        }
 
@@ -914,6 +1000,7 @@ EXPORT_API int wifi_direct_initialize(void)
 
        g_client_info.service_cb = NULL;
        g_client_info.user_data_for_cb_service = NULL;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -929,6 +1016,7 @@ EXPORT_API int wifi_direct_deinitialize(void)
 
        wifi_direct_dbus_deinit();
 
+       WFD_LOCK;
        g_client_info.activation_cb = NULL;
        g_client_info.user_data_for_cb_activation = NULL;
 
@@ -948,6 +1036,7 @@ EXPORT_API int wifi_direct_deinitialize(void)
        g_client_info.user_data_for_cb_service = NULL;
 
        g_client_info.is_registered = FALSE;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -969,8 +1058,10 @@ EXPORT_API int wifi_direct_set_device_state_changed_cb(wifi_direct_device_state_
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.activation_cb = cb;
        g_client_info.user_data_for_cb_activation = user_data;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -985,8 +1076,10 @@ EXPORT_API int wifi_direct_unset_device_state_changed_cb(void)
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.activation_cb = NULL;
        g_client_info.user_data_for_cb_activation = NULL;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1008,8 +1101,10 @@ EXPORT_API int wifi_direct_set_discovery_state_changed_cb(wifi_direct_discovery_
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.discover_cb = cb;
        g_client_info.user_data_for_cb_discover = user_data;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1024,8 +1119,10 @@ EXPORT_API int wifi_direct_unset_discovery_state_changed_cb(void)
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.discover_cb = NULL;
        g_client_info.user_data_for_cb_discover = NULL;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1046,8 +1143,10 @@ EXPORT_API int wifi_direct_set_peer_found_cb(wifi_direct_peer_found_cb cb,
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.peer_found_cb = cb;
        g_client_info.user_data_for_cb_peer_found = user_data;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1062,8 +1161,10 @@ EXPORT_API int wifi_direct_unset_peer_found_cb(void)
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.peer_found_cb = NULL;
        g_client_info.user_data_for_cb_peer_found = NULL;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1084,8 +1185,10 @@ EXPORT_API int wifi_direct_set_service_state_changed_cb(wifi_direct_service_stat
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.service_cb = cb;
        g_client_info.user_data_for_cb_service = user_data;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 
@@ -1101,8 +1204,10 @@ EXPORT_API int wifi_direct_unset_service_state_changed_cb(void)
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.service_cb = NULL;
        g_client_info.user_data_for_cb_service = NULL;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
 
@@ -1124,8 +1229,10 @@ EXPORT_API int wifi_direct_set_connection_state_changed_cb(wifi_direct_connectio
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.connection_cb = cb;
        g_client_info.user_data_for_cb_connection = user_data;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1140,8 +1247,10 @@ EXPORT_API int wifi_direct_unset_connection_state_changed_cb(void)
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.connection_cb = NULL;
        g_client_info.user_data_for_cb_connection = NULL;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1161,8 +1270,10 @@ EXPORT_API int wifi_direct_set_peer_info_connection_state_changed_cb(wifi_direct
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.peer_data_connection_cb = cb;
        g_client_info.user_data_for_cb_peer_data_connection = user_data;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1176,8 +1287,10 @@ EXPORT_API int wifi_direct_unset_peer_info_connection_state_changed_cb(void)
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.peer_data_connection_cb = NULL;
        g_client_info.user_data_for_cb_peer_data_connection = NULL;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1198,8 +1311,10 @@ EXPORT_API int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.ip_assigned_cb = cb;
        g_client_info.user_data_for_cb_ip_assigned = user_data;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1213,8 +1328,10 @@ EXPORT_API int wifi_direct_unset_client_ip_address_assigned_cb(void)
 
        CHECK_INITIALIZED();
 
+       WFD_LOCK;
        g_client_info.ip_assigned_cb = NULL;
        g_client_info.user_data_for_cb_ip_assigned = NULL;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1241,8 +1358,10 @@ EXPORT_API int wifi_direct_set_state_changed_cb(wifi_direct_state_changed_cb cb,
                return WIFI_DIRECT_ERROR_OPERATION_FAILED;
        }
 
+       WFD_LOCK;
        g_client_info.state_cb = cb;
        g_client_info.user_data_for_cb_state = user_data;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1263,8 +1382,10 @@ EXPORT_API int wifi_direct_unset_state_changed_cb(void)
                return WIFI_DIRECT_ERROR_OPERATION_FAILED;
        }
 
+       WFD_LOCK;
        g_client_info.state_cb = NULL;
        g_client_info.user_data_for_cb_state = NULL;
+       WFD_UNLOCK;
 
        __WDC_LOG_FUNC_END__;
        return WIFI_DIRECT_ERROR_NONE;
@@ -1888,8 +2009,10 @@ EXPORT_API int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb
 
                        } else if (!g_strcmp0(key, "IsWfdDevice")) {
 
+                               WFD_LOCK;
                                if (g_client_info.is_display_supported)
                                        peer_list->is_miracast_device = g_variant_get_boolean(var);
+                               WFD_UNLOCK;
                        } else if (!g_strcmp0(key, "IsP2P")) {
                                peer_list->p2p_supported = g_variant_get_boolean(var);
 
@@ -3725,8 +3848,10 @@ EXPORT_API int wifi_direct_get_peer_info(char* mac_address, wifi_direct_discover
                        peer->secondary_device_type = g_variant_get_uint16(var);
 
                } else if (!g_strcmp0(key, "IsWfdDevice")) {
+                       WFD_LOCK;
                        if (g_client_info.is_display_supported)
                                peer->is_miracast_device = g_variant_get_boolean(var);
+                       WFD_UNLOCK;
                } else {
                        ;/* Do Nothing */
                }
index 0f1ee4cd990c61e662cc9dfad68cb294a9c5632d..8daa988efb5ab6735aba3d1c575164954c09a748 100755 (executable)
@@ -35,7 +35,7 @@ typedef struct {
 } gdbus_connection_data;
 
 static int ref_count = 0;
-static __thread gdbus_connection_data gdbus_conn = {NULL, 0};
+static gdbus_connection_data gdbus_conn = {NULL, 0};
 
 typedef struct {
        int sub_id;
@@ -163,8 +163,10 @@ GVariant *wifi_direct_dbus_method_call_sync_debug(const char* interface_name,
 {
        GVariant *reply = NULL;
 
+       WFD_LOCK;
        if (gdbus_conn.connection == NULL) {
                WDC_LOGE("GDBusconnection is NULL"); //LCOV_EXCL_LINE
+               WFD_UNLOCK;
                return reply; //LCOV_EXCL_LINE
        }
 
@@ -184,6 +186,7 @@ GVariant *wifi_direct_dbus_method_call_sync_debug(const char* interface_name,
                                            NULL, /* cancellable */
                                            error); /* error */
        DBUS_DEBUG_VARIANT(reply);
+       WFD_UNLOCK;
        return reply;
 }
 
@@ -192,8 +195,10 @@ gboolean wifi_direct_dbus_init(void)
        GError *Error = NULL;
        int i = 0;
 
+       WFD_LOCK;
        if (gdbus_conn.connection != NULL) {
                WDC_LOGI("GDbusConnection already initialized");
+               WFD_UNLOCK;
                return TRUE;
        }
 
@@ -201,6 +206,7 @@ gboolean wifi_direct_dbus_init(void)
        if (gdbus_conn.connection == NULL) {
                WDC_LOGE("Failed to get connection, Error[%s]", Error->message);
                g_error_free(Error); //LCOV_EXCL_LINE
+               WFD_UNLOCK;
                return FALSE; //LCOV_EXCL_LINE
        }
 
@@ -222,6 +228,7 @@ gboolean wifi_direct_dbus_init(void)
        }
        ref_count++;
 
+       WFD_UNLOCK;
        return TRUE;
 }
 
@@ -230,8 +237,11 @@ void wifi_direct_dbus_deinit(void)
        __WDC_LOG_FUNC_START__;
        int i = 0;
 
-       if (gdbus_conn.connection == NULL)
+       WFD_LOCK;
+       if (gdbus_conn.connection == NULL) {
+               WFD_UNLOCK;
                return;
+       }
 
        ref_count--;
        if(ref_count == 0) {
@@ -245,6 +255,8 @@ void wifi_direct_dbus_deinit(void)
        /* unref gdbus connection */
        g_object_unref(gdbus_conn.connection);
        gdbus_conn.connection = NULL;
+       WFD_UNLOCK;
+
        __WDC_LOG_FUNC_END__;
 }