summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2020-11-30 00:47:36 +0000
committerHwankyu Jhun <h.jhun@samsung.com>2020-11-30 01:51:07 +0000
commitea132817f9ba95e10ef1430b756b057e4802f836 (patch)
treebdb9ecd16842f455370964674597bbcf0de691d9
parenta6ad5c37123e064d6d1a982b083623cf7de93cad (diff)
downloadminicontrol-ea132817f9ba95e10ef1430b756b057e4802f836.tar.gz
minicontrol-ea132817f9ba95e10ef1430b756b057e4802f836.tar.bz2
minicontrol-ea132817f9ba95e10ef1430b756b057e4802f836.zip
Consider thread-safe issue
The EFL API is not thread-safety. If an application uses the minicontrol -provider API, it makes a problem about thread-safe issue. After this patch is applied, the minicontro provider uses glist and mutex instead of evas_object_data_set() and evas_object_data_get(). Change-Id: I0ca420d9721493cc3aee0a6b3a961da795900a29 Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r--src/minicontrol-provider.c89
1 files changed, 77 insertions, 12 deletions
diff --git a/src/minicontrol-provider.c b/src/minicontrol-provider.c
index ba44006..f72f076 100644
--- a/src/minicontrol-provider.c
+++ b/src/minicontrol-provider.c
@@ -14,8 +14,10 @@
* limitations under the License.
*/
-#include <Elementary.h>
#include <Ecore_Evas.h>
+#include <Elementary.h>
+#include <glib.h>
+#include <pthread.h>
#include "minicontrol-error.h"
#include "minicontrol-type.h"
@@ -27,7 +29,6 @@
#define MINICTRL_PRIORITY_SUFFIX_TOP "__minicontrol_top"
#define MINICTRL_PRIORITY_SUFFIX_LOW "__minicontrol_low"
-#define MINICTRL_DATA_KEY "__minictrl_data_internal"
enum {
MINICTRL_STATE_READY = 0,
@@ -42,8 +43,12 @@ struct _minicontrol_provider {
minictrl_sig_handle *event_sh;
minicontrol_event_cb event_callback;
time_t create_time;
+ GRecMutex mutex;
};
+static GList *__list;
+static pthread_mutex_t __mutex = PTHREAD_MUTEX_INITIALIZER;
+
static void _minictrl_win_del_cb(void *data, Evas *e, Evas_Object *obj,
void *event_info);
static void _minictrl_win_hide_cb(void *data, Evas *e, Evas_Object *obj,
@@ -53,11 +58,51 @@ static void _minictrl_win_show_cb(void *data, Evas *e, Evas_Object *obj,
static void _minictrl_win_resize_cb(void *data, Evas *e, Evas_Object *obj,
void *event_info);
+static void __minicontrol_provider_list_add(struct _minicontrol_provider *pd)
+{
+ pthread_mutex_lock(&__mutex);
+ __list = g_list_append(__list, pd);
+ pthread_mutex_unlock(&__mutex);
+}
+
+static void __minicontrol_provider_list_remove(struct _minicontrol_provider *pd)
+{
+ pthread_mutex_lock(&__mutex);
+ __list = g_list_remove(__list, pd);
+ pthread_mutex_unlock(&__mutex);
+}
+
+static struct _minicontrol_provider *__minicontrol_provider_list_find(
+ Evas_Object *obj)
+{
+ struct _minicontrol_provider *pd;
+ GList *iter;
+
+ pthread_mutex_lock(&__mutex);
+ iter = __list;
+ while (iter) {
+ pd = (struct _minicontrol_provider *)iter->data;
+ if (pd->obj == obj) {
+ pthread_mutex_unlock(&__mutex);
+ return pd;
+ }
+
+ iter = g_list_next(iter);
+ }
+
+ pthread_mutex_unlock(&__mutex);
+ return NULL;
+}
+
static void __minicontrol_provider_free(struct _minicontrol_provider *pd)
{
if (pd == NULL)
return;
+ g_rec_mutex_lock(&pd->mutex);
+ g_rec_mutex_unlock(&pd->mutex);
+ g_rec_mutex_clear(&pd->mutex);
+
if (pd->name)
free(pd->name);
@@ -81,11 +126,13 @@ static void _running_req_cb(void *data, GVariant *parameters)
return;
}
+ g_rec_mutex_lock(&pd->mutex);
if (pd->state == MINICTRL_STATE_RUNNING) {
evas_object_geometry_get(pd->obj, NULL, NULL, &w, &h);
_minictrl_provider_message_send(MINICONTROL_EVENT_START,
pd->name, w, h, 0, pd->create_time);
}
+ g_rec_mutex_unlock(&pd->mutex);
}
static void _sig_to_provider_handler_cb(void *data, GVariant *parameters)
@@ -107,6 +154,7 @@ static void _sig_to_provider_handler_cb(void *data, GVariant *parameters)
g_variant_get(parameters, "(&si&su)", &minicontrol_name, &event,
&serialized_arg, &serialized_arg_length);
+ g_rec_mutex_lock(&pd->mutex);
INFO("minicontrol_name[%s] event[%d] pd->name[%s]",
minicontrol_name, event, pd->name);
@@ -129,6 +177,7 @@ static void _sig_to_provider_handler_cb(void *data, GVariant *parameters)
if (event_arg_bundle)
bundle_free(event_arg_bundle);
}
+ g_rec_mutex_unlock(&pd->mutex);
}
static char *_minictrl_create_name(const char *name)
@@ -215,7 +264,6 @@ EXPORT_API Evas_Object *minicontrol_create_window(const char *name,
pd->obj = win;
pd->create_time = time(NULL);
- evas_object_data_set(win, MINICTRL_DATA_KEY, pd);
elm_win_autodel_set(win, EINA_TRUE);
evas_object_event_callback_add(win, EVAS_CALLBACK_DEL,
@@ -233,6 +281,9 @@ EXPORT_API Evas_Object *minicontrol_create_window(const char *name,
MINICTRL_DBUS_SIG_TO_PROVIDER,
_sig_to_provider_handler_cb, pd);
pd->event_callback = event_callback;
+ g_rec_mutex_init(&pd->mutex);
+
+ __minicontrol_provider_list_add(pd);
WARN("new minicontrol created - win(%p), name(%s)", win, pd->name);
set_last_result(MINICONTROL_ERROR_NONE);
@@ -253,7 +304,7 @@ EXPORT_API int minicontrol_send_event(Evas_Object *minicontrol,
}
WARN("minicontrol(%p)", minicontrol);
- pd = evas_object_data_get(minicontrol, MINICTRL_DATA_KEY);
+ pd = __minicontrol_provider_list_find(minicontrol);
if (!pd) {
/* LCOV_EXCL_START */
ERR("pd is NULL, invaild parameter");
@@ -261,9 +312,11 @@ EXPORT_API int minicontrol_send_event(Evas_Object *minicontrol,
/* LCOV_EXCL_STOP */
}
+ g_rec_mutex_lock(&pd->mutex);
if (!pd->name) {
/* LCOV_EXCL_START */
ERR("pd name is NULL, invaild parameter");
+ g_rec_mutex_unlock(&pd->mutex);
return MINICONTROL_ERROR_INVALID_PARAMETER;
/* LCOV_EXCL_STOP */
}
@@ -272,6 +325,7 @@ EXPORT_API int minicontrol_send_event(Evas_Object *minicontrol,
ret = _minictrl_send_event(MINICTRL_DBUS_SIG_TO_VIEWER,
pd->name, event, event_arg);
}
+ g_rec_mutex_unlock(&pd->mutex);
return ret;
}
@@ -288,7 +342,7 @@ static int minicontrol_win_start(Evas_Object *minicontrol)
return MINICONTROL_ERROR_INVALID_PARAMETER;
}
- pd = evas_object_data_get(minicontrol, MINICTRL_DATA_KEY);
+ pd = __minicontrol_provider_list_find(minicontrol);
if (!pd) {
/* LCOV_EXCL_START */
ERR("pd is NULL, invaild parameter");
@@ -296,9 +350,11 @@ static int minicontrol_win_start(Evas_Object *minicontrol)
/* LCOV_EXCL_STOP */
}
+ g_rec_mutex_lock(&pd->mutex);
if (!pd->name) {
/* LCOV_EXCL_START */
ERR("pd name is NULL, invaild parameter");
+ g_rec_mutex_unlock(&pd->mutex);
return MINICONTROL_ERROR_INVALID_PARAMETER;
/* LCOV_EXCL_STOP */
}
@@ -310,6 +366,7 @@ static int minicontrol_win_start(Evas_Object *minicontrol)
ret = _minictrl_provider_message_send(MINICONTROL_EVENT_START,
pd->name, w, h, 0, pd->create_time);
}
+ g_rec_mutex_unlock(&pd->mutex);
return ret;
}
@@ -326,7 +383,7 @@ static int minicontrol_win_stop(Evas_Object *minicontrol)
/* LCOV_EXCL_STOP */
}
- pd = evas_object_data_get(minicontrol, MINICTRL_DATA_KEY);
+ pd = __minicontrol_provider_list_find(minicontrol);
if (!pd) {
/* LCOV_EXCL_START */
ERR("pd is NULL, invaild parameter");
@@ -334,9 +391,11 @@ static int minicontrol_win_stop(Evas_Object *minicontrol)
/* LCOV_EXCL_STOP */
}
+ g_rec_mutex_lock(&pd->mutex);
if (!pd->name) {
/* LCOV_EXCL_START */
ERR("pd name is NULL, invaild parameter");
+ g_rec_mutex_unlock(&pd->mutex);
return MINICONTROL_ERROR_INVALID_PARAMETER;
/* LCOV_EXCL_STOP */
}
@@ -347,6 +406,7 @@ static int minicontrol_win_stop(Evas_Object *minicontrol)
ret = _minictrl_provider_message_send(MINICONTROL_EVENT_STOP,
pd->name, 0, 0, 0, 0);
}
+ g_rec_mutex_unlock(&pd->mutex);
return ret;
}
@@ -359,10 +419,9 @@ static void _minictrl_win_del_cb(void *data, Evas *e, Evas_Object *obj,
WARN("minicontrol(%p)", obj);
minicontrol_win_stop(obj);
- pd = evas_object_data_get(obj, MINICTRL_DATA_KEY);
+ pd = __minicontrol_provider_list_find(obj);
+ __minicontrol_provider_list_remove(pd);
__minicontrol_provider_free(pd);
-
- evas_object_data_set(obj, MINICTRL_DATA_KEY, NULL);
}
static void _minictrl_win_hide_cb(void *data, Evas *e,
@@ -391,11 +450,13 @@ static void _minictrl_win_resize_cb(void *data, Evas *e,
return;
}
+ g_rec_mutex_lock(&pd->mutex);
if (pd->state == MINICTRL_STATE_RUNNING) {
evas_object_geometry_get(obj, NULL, NULL, &w, &h);
_minictrl_provider_message_send(MINICONTROL_EVENT_RESIZE,
pd->name, w, h, 0, 0);
}
+ g_rec_mutex_unlock(&pd->mutex);
}
/* LCOV_EXCL_START */
@@ -449,8 +510,6 @@ EXPORT_API Evas_Object *minicontrol_win_add(const char *name)
pd->state = MINICTRL_STATE_READY;
pd->obj = win;
- evas_object_data_set(win, MINICTRL_DATA_KEY, pd);
-
elm_win_autodel_set(win, EINA_TRUE);
evas_object_event_callback_add(win, EVAS_CALLBACK_DEL,
@@ -464,6 +523,8 @@ EXPORT_API Evas_Object *minicontrol_win_add(const char *name)
pd->running_sh = _minictrl_dbus_sig_handle_attach(
MINICTRL_DBUS_SIG_RUNNING_REQ, _running_req_cb, pd);
+ g_rec_mutex_init(&pd->mutex);
+ __minicontrol_provider_list_add(pd);
WARN("new minicontrol created - win(%p), name(%s)", win, pd->name);
return win;
@@ -485,14 +546,16 @@ EXPORT_API int minicontrol_request(Evas_Object *minicontrol,
}
WARN("minicontrol(%p)", minicontrol);
- pd = evas_object_data_get(minicontrol, MINICTRL_DATA_KEY);
+ pd = __minicontrol_provider_list_find(minicontrol);
if (!pd) {
ERR("pd is NULL, invaild parameter");
return MINICONTROL_ERROR_INVALID_PARAMETER;
}
+ g_rec_mutex_lock(&pd->mutex);
if (!pd->name) {
ERR("pd name is NULL, invaild parameter");
+ g_rec_mutex_unlock(&pd->mutex);
return MINICONTROL_ERROR_INVALID_PARAMETER;
}
@@ -512,12 +575,14 @@ EXPORT_API int minicontrol_request(Evas_Object *minicontrol,
break;
default:
ERR("Not supported request[%d]", request);
+ g_rec_mutex_unlock(&pd->mutex);
return MINICONTROL_ERROR_NOT_SUPPORTED;
}
_minictrl_send_event(MINICTRL_DBUS_SIG_TO_VIEWER, pd->name,
event, NULL);
}
+ g_rec_mutex_unlock(&pd->mutex);
return MINICONTROL_ERROR_NONE;
}