#include "message_port_log.h"
#include "message_port.h"
-pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-
int message_port_register_local_port(const char *local_port, message_port_message_cb callback, void *user_data)
{
int local_port_id;
return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
}
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
local_port_id = register_message_port(local_port, false, callback, user_data);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
if (local_port_id > 0)
_LOGD("Register local port ID (%d).", local_port_id);
return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
}
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
trusted_local_port_id = register_message_port(local_port, true, callback, user_data);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
if (trusted_local_port_id > 0)
_LOGD("Register trusted local port ID (%d).", trusted_local_port_id);
return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
}
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
res = unregister_local_port(local_port_id, false);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return res;
}
return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
}
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
res = unregister_local_port(trusted_local_port_id, true);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return res;
}
}
_LOGD("Check remote port (%s):(%s).", remote_app_id, remote_port);
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
ret = check_remote_port(remote_app_id, remote_port, false, exist);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return ret;
}
return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
}
_LOGD("Check trusted remote port (%s):(%s).", remote_app_id, remote_port);
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
ret = check_remote_port(remote_app_id, remote_port, true, exist);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return ret;
}
}
_SECURE_LOGI("Send a message to (%s):(%s).", remote_app_id, remote_port);
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
ret = send_message(remote_app_id, remote_port, NULL, false, false, false, message);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return ret;
}
}
_SECURE_LOGI("Send a trusted message to (%s):(%s).", remote_app_id, remote_port);
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
ret = send_message(remote_app_id, remote_port, NULL, true, false, false, message);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return ret;
}
}
_SECURE_LOGI("Send a message to (%s):(%s) - (%d).", remote_app_id, remote_port, local_port_id);
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
ret = send_bidirectional_message(local_port_id, remote_app_id, remote_port, false, message);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return ret;
}
}
_SECURE_LOGI("Send a trusted message to (%s):(%s) - (%d).", remote_app_id, remote_port, local_port_id);
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
ret = send_bidirectional_message(local_port_id, remote_app_id, remote_port, true, message);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return ret;
}
bundle_raw *data;
} delay_message_info_s;
-extern pthread_mutex_t mutex;
-
/* LCOV_EXCL_START */
static void __free_delay_message_info(delay_message_info_s *message)
{
gpointer data)
{
_LOGI("__socket_disconnect_handler %d", cond);
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
__free_port_info_by_key((port_key_info_s *)data);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return FALSE;
}
if (port_info == NULL)
return G_SOURCE_REMOVE;
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
if (__validate_delay_port_info(delay_info) == false) {
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return G_SOURCE_REMOVE;
}
if (port_info->delayed_message_list == NULL) {
port_info->delayed_message_size = 0;
port_info->delay_src_id = 0;
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return G_SOURCE_REMOVE;
} else {
message = g_list_nth_data(port_info->delayed_message_list, 0);
ret = __send_delayed_message(port_info->send_sock_fd, message);
if (ret == MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE) {
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return G_SOURCE_CONTINUE;
} else if (ret == MESSAGE_PORT_ERROR_IO_ERROR) {
port_info->delay_src_id = 0;
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return G_SOURCE_REMOVE;
}
__free_delay_message_info(message);
}
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
return G_SOURCE_CONTINUE;
}
static GHashTable *__callback_info_hash;
static GHashTable *__sender_appid_hash;
-extern pthread_mutex_t mutex;
-
typedef struct message_port_pkt {
int remote_port_name_len;
char *remote_port_name;
if (key_info == NULL)
return FALSE;
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
if (__validate_callback_info(key_info) == false) {
ret = FALSE;
existed = FALSE;
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
goto out;
}
if (__validate_local_info(key_info) == false) {
ret = FALSE;
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
goto out;
}
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
mi = key_info->callback_info;
}
if (mi && ret == FALSE && existed == TRUE) {
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
__callback_info_free_by_info(mi);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
}
return ret;
goto out;
}
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
if (!is_local_port_registed(remote_port, remote_trusted, &local_reg_id, &mi)) {
_LOGE("Invalid argument : remote_port:(%s) trusted(%d)", remote_port, remote_trusted);
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
goto out;
}
callback_info = __create_callback_info(mi, local_appid);
if (callback_info == NULL) {
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
goto out;
}
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
if (!local_port) {
_LOGE("Invalid argument : local_port");
goto out;
}
- pthread_mutex_lock(&mutex);
+ message_port_lock_mutex();
if (__callback_info_append(callback_info) == false) {
_LOGE("fail to append callback_info");
ret = false;
}
- pthread_mutex_unlock(&mutex);
+ message_port_unlock_mutex();
}
}