summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2015-04-14 10:07:16 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2015-04-16 19:08:07 +0900
commit4db47141d1199639cace3a1baaddff742efd0c78 (patch)
tree0a13c60078a2f08ab5561108f25e6c0eed3cd574
parentac9df0dd712fbf87a5972a8a18b3bc433f457d24 (diff)
downloaddeviced-submit/tizen/20150421.033354.tar.gz
deviced-submit/tizen/20150421.033354.tar.bz2
deviced-submit/tizen/20150421.033354.zip
Device notifier is managed by a list. The list can be changed during other notifier callback function. So do not remove in unregister func. Instead it marks deleted and will be removed on deviced idle time. Change-Id: I7074c2ca99000c10bcfee44047d08de2f15cb7f1 Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
-rw-r--r--src/core/device-idler.c4
-rw-r--r--src/core/device-idler.h2
-rw-r--r--src/core/device-notifier.c40
-rw-r--r--src/power/power-handler.c4
4 files changed, 33 insertions, 17 deletions
diff --git a/src/core/device-idler.c b/src/core/device-idler.c
index 06e2317e..e2af9a06 100644
--- a/src/core/device-idler.c
+++ b/src/core/device-idler.c
@@ -24,7 +24,7 @@
#include "log.h"
struct device_request {
- int (*func)(void *data);
+ void (*func)(void *data);
void *data;
};
@@ -77,7 +77,7 @@ static void process_next_request_in_idle(void)
_E("fail to add request to idler");
}
-int add_idle_request(int (*func)(void *data), void *data)
+int add_idle_request(void (*func)(void *data), void *data)
{
struct device_request *req;
diff --git a/src/core/device-idler.h b/src/core/device-idler.h
index add2ecf2..411e4bbf 100644
--- a/src/core/device-idler.h
+++ b/src/core/device-idler.h
@@ -24,6 +24,6 @@
* To allow for callbacks to be called when the daemon is idle state.
*/
-int add_idle_request(int (*func)(void *data), void *data);
+int add_idle_request(void (*func)(void *data), void *data);
#endif /* __DEVICE_IDLER_H__ */
diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c
index 9c266b9c..57610ecc 100644
--- a/src/core/device-notifier.c
+++ b/src/core/device-notifier.c
@@ -23,11 +23,13 @@
#include "common.h"
struct device_notifier {
+ bool deleted;
enum device_notifier_type status;
int (*func)(void *data);
};
static dd_list *device_notifier_list;
+static Ecore_Idler *idl;
#define FIND_NOTIFIER(a, b, d, e, f) \
DD_LIST_FOREACH(a, b, d) \
@@ -51,7 +53,7 @@ int register_notifier(enum device_notifier_type status, int (*func)(void *data))
return -EINVAL;
}
- notifier = malloc(sizeof(struct device_notifier));
+ notifier = calloc(1, sizeof(struct device_notifier));
if (!notifier) {
_E("Fail to malloc for notifier!");
return -ENOMEM;
@@ -77,25 +79,41 @@ int unregister_notifier(enum device_notifier_type status, int (*func)(void *data
FIND_NOTIFIER(device_notifier_list, n, notifier, status, func) {
_I("[%d, %x]", status, func);
- DD_LIST_REMOVE(device_notifier_list, notifier);
- free(notifier);
+ notifier->deleted = true;
}
return 0;
}
-void device_notify(enum device_notifier_type status, void *data)
+static Eina_Bool delete_unused_notifier_cb(void *data)
{
- dd_list *n, *next;
+ dd_list *n;
+ dd_list *next;
struct device_notifier *notifier;
- int cnt = 0;
DD_LIST_FOREACH_SAFE(device_notifier_list, n, next, notifier) {
- if (status == notifier->status) {
- if (notifier->func) {
+ if (notifier->deleted) {
+ DD_LIST_REMOVE_LIST(device_notifier_list, n);
+ free(notifier);
+ }
+ }
+
+ idl = NULL;
+ return ECORE_CALLBACK_CANCEL;
+}
+
+void device_notify(enum device_notifier_type status, void *data)
+{
+ dd_list *n;
+ struct device_notifier *notifier;
+
+ DD_LIST_FOREACH(device_notifier_list, n, notifier) {
+ if (!notifier->deleted && status == notifier->status) {
+ if (notifier->func)
notifier->func(data);
- cnt++;
- }
}
}
-} \ No newline at end of file
+
+ if (!idl)
+ idl = ecore_idler_add(delete_unused_notifier_cb, NULL);
+}
diff --git a/src/power/power-handler.c b/src/power/power-handler.c
index 3bda4c9d..388e16ed 100644
--- a/src/power/power-handler.c
+++ b/src/power/power-handler.c
@@ -247,7 +247,7 @@ static void poweroff_stop_systemd_service(void)
umount2("/sys/fs/cgroup", MNT_FORCE |MNT_DETACH);
}
-static int poweroff_idler_cb(void *data)
+static void poweroff_idler_cb(void *data)
{
enum poweroff_type val = (int)data;
int ret;
@@ -280,8 +280,6 @@ static int poweroff_idler_cb(void *data)
if (update_pm_setting)
update_pm_setting(SETTING_POWEROFF, val);
-
- return 0;
}
static int power_execute(void *data)