summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWook Song <wook16.song@samsung.com>2017-07-28 08:39:58 +0900
committerWook Song <wook16.song@samsung.com>2017-08-17 16:56:33 +0900
commit076a5044edf52154395a41aff368e3f7af5a817a (patch)
tree4fccb173188fb8649c16e2edca706221c40473f8
parent3029006032a9264036276cf50d28aabdb294716d (diff)
downloadpass-076a5044edf52154395a41aff368e3f7af5a817a.tar.gz
pass-076a5044edf52154395a41aff368e3f7af5a817a.tar.bz2
pass-076a5044edf52154395a41aff368e3f7af5a817a.zip
In list.h, there are a group of macro definitions started with the prefix 'DD_LIST'. Most of these macros are neither meaningful nor necessary since they just wrap the corresponding g_list functions. For this reason, this patch removes those wrapping macros. In addition, the prefix 'DD_LIST' is ambiguous. This patch also changes the prefix 'DD_LIST' to more direct prefix "G_LIST". Change-Id: Iaa1aa4b5ed89e62ab93c0f4569b735a8f807793c Signed-off-by: Wook Song <wook16.song@samsung.com>
-rw-r--r--src/core/device-notifier.c42
-rw-r--r--src/core/devices.c33
-rw-r--r--src/core/edbus-handler.c58
-rw-r--r--src/core/list.h64
-rw-r--r--src/pmqos/pmqos.c62
5 files changed, 118 insertions, 141 deletions
diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c
index 7588281..841fa3a 100644
--- a/src/core/device-notifier.c
+++ b/src/core/device-notifier.c
@@ -16,22 +16,19 @@
* limitations under the License.
*/
+#include <glib.h>
+
#include "shared/log.h"
#include "device-notifier.h"
-#include "list.h"
#include "common.h"
#define DEVICE_NOTIFIER_MAX_COUNT 255
-static dd_list *device_notifier_list;
+static GList *device_notifier_list;
static Ecore_Idler *idl;
static struct device_notifier device_notifiers[DEVICE_NOTIFIER_MAX_COUNT];
-#define FIND_NOTIFIER(a, b, c, d, e, f) \
- DD_LIST_FOREACH(a, b, c) \
- if (d == c->d && e == (c->e) && f == (c->f))
-
static struct device_notifier *get_device_notifier(void) {
static int pos = 0;
@@ -70,7 +67,8 @@ int register_notifier(enum device_notifier_type status,
notifier->func = func;
notifier->user_data = user_data;
- DD_LIST_APPEND(device_notifier_list, notifier);
+ device_notifier_list = g_list_append(device_notifier_list,
+ (gpointer)notifier);
return 0;
}
@@ -78,12 +76,15 @@ int register_notifier(enum device_notifier_type status,
int unregister_notifier(enum device_notifier_type status,
int (*func)(void *data, void *user_data), void *user_data)
{
- dd_list *n;
+ GList *n;
struct device_notifier *notifier;
- FIND_NOTIFIER(device_notifier_list, n, notifier, status, func,
- user_data) {
- notifier->is_used = false;
+ for (n = device_notifier_list; n != NULL; n = n->next) {
+ notifier = n->data;
+ if ((notifier->status == status) &&
+ (notifier->func == func) &&
+ (notifier->user_data == user_data))
+ notifier->is_used = false;
}
return 0;
@@ -91,27 +92,34 @@ int unregister_notifier(enum device_notifier_type status,
static Eina_Bool delete_unused_notifier_cb(void *data)
{
- dd_list *n;
- dd_list *next;
+ GList *n;
+ GList *next;
struct device_notifier *notifier;
- DD_LIST_FOREACH_SAFE(device_notifier_list, n, next, notifier) {
+ n = device_notifier_list;
+ while (n != NULL) {
+ notifier = n->data;
+ next = n->next;
if (!notifier->is_used) {
memset(notifier, 0, sizeof(*notifier));
- DD_LIST_REMOVE_LIST(device_notifier_list, n);
+ device_notifier_list = g_list_delete_link(
+ device_notifier_list, n);
}
+ n = next;
}
idl = NULL;
+
return ECORE_CALLBACK_CANCEL;
}
void device_notify(enum device_notifier_type status, void *data)
{
- dd_list *n;
+ GList *n;
struct device_notifier *notifier;
- DD_LIST_FOREACH(device_notifier_list, n, notifier) {
+ for (n = device_notifier_list; n != NULL; n = n->next) {
+ notifier = n->data;
if (notifier->is_used && status == notifier->status) {
if (notifier->func)
notifier->func(data, notifier->user_data);
diff --git a/src/core/devices.c b/src/core/devices.c
index dbfc475..4316e9c 100644
--- a/src/core/devices.c
+++ b/src/core/devices.c
@@ -16,12 +16,11 @@
* limitations under the License.
*/
-
+#include <glib.h>
#include <stdio.h>
#include "shared/log.h"
-#include "list.h"
#include "common.h"
#include "devices.h"
#include "edbus-handler.h"
@@ -30,27 +29,28 @@ static const struct device_ops default_ops = {
.name = "default-ops",
};
-static dd_list *dev_head;
+static GList *dev_head;
void add_device(const struct device_ops *dev)
{
if (dev->priority == DEVICE_PRIORITY_HIGH)
- DD_LIST_PREPEND(dev_head, dev);
+ dev_head = g_list_prepend(dev_head, (gpointer)dev);
else
- DD_LIST_APPEND(dev_head, dev);
+ dev_head = g_list_append(dev_head, (gpointer)dev);
}
void remove_device(const struct device_ops *dev)
{
- DD_LIST_REMOVE(dev_head, dev);
+ dev_head = g_list_remove(dev_head, (gconstpointer)dev);
}
const struct device_ops *find_device(const char *name)
{
- dd_list *elem;
+ GList *elem;
const struct device_ops *dev;
- DD_LIST_FOREACH(dev_head, elem, dev) {
+ for (elem = dev_head; elem != NULL; elem = elem->next) {
+ dev = elem->data;
if (!strcmp(dev->name, name))
return dev;
}
@@ -66,27 +66,32 @@ int check_default(const struct device_ops *dev)
void devices_init(void *data)
{
- dd_list *elem, *elem_n;
+ GList *elem, *elem_n;
const struct device_ops *dev;
- DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) {
+ elem = dev_head;
+ while (elem != NULL) {
+ dev = elem->data;
+ elem_n = elem->next;
if (dev->probe && dev->probe(data) != 0) {
_E("[%s] probe fail", dev->name);
- DD_LIST_REMOVE(dev_head, dev);
+ dev_head = g_list_remove(dev_head, (gconstpointer)dev);
+ elem = elem_n;
continue;
}
-
if (dev->init)
dev->init(data);
+ elem = elem_n;
}
}
void devices_exit(void *data)
{
- dd_list *elem;
+ GList *elem;
const struct device_ops *dev;
- DD_LIST_FOREACH(dev_head, elem, dev) {
+ for (elem = dev_head; elem != NULL; elem = elem->next) {
+ dev = elem->data;
if (dev->exit)
dev->exit(data);
}
diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c
index 17c4944..4477579 100644
--- a/src/core/edbus-handler.c
+++ b/src/core/edbus-handler.c
@@ -16,13 +16,12 @@
* limitations under the License.
*/
-
#include <assert.h>
+#include <glib.h>
#include "core/edbus-handler.h"
#include "core/common.h"
#include "core/device-notifier.h"
-#include "core/list.h"
#include "shared/log.h"
#define EDBUS_INIT_RETRY_COUNT 5
@@ -44,8 +43,8 @@ static struct edbus_object {
/* Add new object & interface here*/
};
-static dd_list *edbus_owner_list;
-static dd_list *edbus_handler_list;
+static GList *edbus_owner_list;
+static GList *edbus_handler_list;
static int edbus_init_val;
static DBusConnection *conn;
static E_DBus_Connection *edbus_conn;
@@ -178,27 +177,33 @@ pid_t get_edbus_sender_pid(DBusMessage *msg)
static void unregister_edbus_signal_handle(void)
{
- dd_list *tmp, *next;
+ GList *tmp, *next;
struct edbus_list *entry;
- DD_LIST_FOREACH_SAFE(edbus_handler_list, tmp, next, entry) {
- if (!entry->handler)
- continue;
- e_dbus_signal_handler_del(edbus_conn, entry->handler);
- DD_LIST_REMOVE(edbus_handler_list, entry);
- free(entry->signal_name);
- put_edbus_list(entry);
+ tmp = edbus_handler_list;
+ while (tmp != NULL) {
+ entry = tmp->data;
+ next = tmp->next;
+ if (entry->handler) {
+ e_dbus_signal_handler_del(edbus_conn, entry->handler);
+ edbus_handler_list = g_list_remove(edbus_handler_list,
+ (gconstpointer)entry);
+ free(entry->signal_name);
+ put_edbus_list(entry);
+ }
+ tmp = next;
}
}
int register_edbus_signal_handler(const char *path, const char *interface,
const char *name, E_DBus_Signal_Cb cb)
{
- dd_list *tmp;
+ GList *tmp;
struct edbus_list *entry;
E_DBus_Signal_Handler *handler;
- DD_LIST_FOREACH(edbus_handler_list, tmp, entry) {
+ for (tmp = edbus_handler_list; tmp != NULL; tmp = tmp->next) {
+ entry = tmp->data;
if (strncmp(entry->signal_name, name, strlen(name)) == 0)
return -EEXIST;
}
@@ -229,9 +234,10 @@ int register_edbus_signal_handler(const char *path, const char *interface,
}
entry->handler = handler;
- DD_LIST_PREPEND(edbus_handler_list, entry);
+ edbus_handler_list = g_list_prepend(edbus_handler_list,
+ (gpointer)entry);
if (!edbus_handler_list) {
- _E("dd_list_prepend failed");
+ _E("g_list_prepend failed");
e_dbus_signal_handler_del(edbus_conn, handler);
free(entry->signal_name);
put_edbus_list(entry);
@@ -243,17 +249,23 @@ int register_edbus_signal_handler(const char *path, const char *interface,
int unregister_edbus_signal_handler(const char *path, const char *interface,
const char *name)
{
- dd_list *tmp, *next;
+ GList *tmp, *next;
struct edbus_list *entry;
- DD_LIST_FOREACH_SAFE(edbus_handler_list, tmp, next, entry) {
+ tmp = edbus_handler_list;
+ while (tmp != NULL) {
+ entry = tmp->data;
+ next = tmp->next;
if (strncmp(entry->signal_name, name, strlen(name) + 1) == 0) {
e_dbus_signal_handler_del(edbus_conn, entry->handler);
- DD_LIST_REMOVE(edbus_handler_list, entry);
+ edbus_handler_list = g_list_remove(edbus_handler_list,
+ (gpointer)entry);
free(entry->signal_name);
put_edbus_list(entry);
+
return 0;
}
+ tmp = next;
}
return -1;
@@ -367,10 +379,11 @@ static void check_owner_name(void)
char *pa[1];
char exe_name[PATH_MAX];
char *entry;
- dd_list *n;
+ GList *n;
int pid;
- DD_LIST_FOREACH(edbus_owner_list, n, entry) {
+ for (n = edbus_owner_list; n != NULL; n = n->next) {
+ entry = n->data;
pa[0] = entry;
msg = dbus_method_sync_with_reply(E_DBUS_FDO_BUS,
E_DBUS_FDO_PATH,
@@ -424,7 +437,8 @@ static void check_owner_list(void)
while (dbus_message_iter_get_arg_type(&item) == DBUS_TYPE_STRING) {
dbus_message_iter_get_basic(&item, &name);
entry = strndup(name, strlen(name));
- DD_LIST_APPEND(edbus_owner_list, entry);
+ edbus_owner_list = g_list_append(edbus_owner_list,
+ (gpointer)entry);
if (!edbus_owner_list) {
_E("append failed");
free(entry);
diff --git a/src/core/list.h b/src/core/list.h
deleted file mode 100644
index 261ce4f..0000000
--- a/src/core/list.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * PASS
- *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LIST_H__
-#define __LIST_H__
-
-#include <glib.h>
-typedef GList dd_list;
-
-#define DD_LIST_PREPEND(a, b) \
- a = g_list_prepend(a, (gpointer)b)
-#define DD_LIST_APPEND(a, b) \
- a = g_list_append(a, (gpointer)b)
-#define DD_LIST_REMOVE(a, b) \
- a = g_list_remove(a, (gpointer)b)
-#define DD_LIST_REMOVE_LIST(a, b) \
- a = g_list_delete_link(a, b)
-#define DD_LIST_LENGTH(a) \
- g_list_length(a)
-#define DD_LIST_NTH(a, b) \
- g_list_nth_data(a, b)
-#define DD_LIST_FIND(a, b) \
- g_list_find(a, (gpointer)b)
-#define DD_LIST_FREE_LIST(a) \
- g_list_free(a)
-#define DD_LIST_FREE_LIST_FULL(a, free_func) \
- g_list_free_full(a, free_func)
-#define DD_LIST_SORT(a, func) \
- a = g_list_sort(a, func)
-#define DD_LIST_FOREACH(head, elem, node) \
- for (elem = head, node = NULL; \
- elem && ((node = elem->data) != NULL); \
- elem = elem->next, node = NULL)
-#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \
- for (elem = head, elem_next = g_list_next(elem), node = NULL; \
- elem && ((node = elem->data) != NULL); \
- elem = elem_next, elem_next = g_list_next(elem), node = NULL)
-#define DD_LIST_REVERSE_FOREACH(head, elem, node) \
- for (elem = g_list_last(head), node = NULL; \
- elem && ((node = elem->data) != NULL); \
- elem = g_list_previous(elem), node = NULL)
-#define DD_LIST_REVERSE_FOREACH_SAFE(head, elem, elem_next, node) \
- for (elem = g_list_last(head), elem_next = g_list_previous(elem), node = NULL; \
- elem && ((node = elem->data) != NULL); \
- elem = elem_next, elem_next = g_list_previous(elem), node = NULL)
-#define DD_LIST_NEXT(a) \
- g_list_next(a)
-
-#endif
diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c
index 39b6308..1bfaf2e 100644
--- a/src/pmqos/pmqos.c
+++ b/src/pmqos/pmqos.c
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-
+#include <glib.h>
#include <stdio.h>
#include <limits.h>
#include <Ecore.h>
@@ -25,7 +25,6 @@
#include "core/edbus-handler.h"
#include "core/devices.h"
#include "core/common.h"
-#include "core/list.h"
#include "core/device-notifier.h"
#include "shared/log.h"
@@ -44,7 +43,7 @@ struct pmqos_cpu {
int timeout;
};
-static dd_list *pmqos_head;
+static GList *pmqos_head;
static Ecore_Timer *unlock_timer;
static int unlock_max_timeout_ms;
static struct timespec unlock_timer_start_st;
@@ -104,7 +103,7 @@ static int set_pmqos(const char *name, int val)
static void pmqos_unlock_timeout_update(void)
{
- dd_list *elem;
+ GList *elem, *next;
struct pmqos_cpu *cpu;
int delta = 0;
@@ -114,30 +113,37 @@ static void pmqos_unlock_timeout_update(void)
if (delta <= 0)
return;
- DD_LIST_FOREACH(pmqos_head, elem, cpu) {
+ for (elem = pmqos_head; elem != NULL; elem = elem->next) {
+ cpu = elem->data;
cpu->timeout -= delta;
if (cpu->timeout < 0)
cpu->timeout = 0;
if (cpu->timeout > 0)
continue;
+
/* Set cpu unlock */
set_pmqos(cpu->name, false);
- /* Delete previous request */
}
- DD_LIST_FOREACH(pmqos_head, elem, cpu) {
- if (cpu->timeout > 0)
- continue;
- DD_LIST_REMOVE(pmqos_head, cpu);
- free(cpu);
- cpu = NULL;
+ /* Remove all the requests of which timeout are over from the list */
+ elem = pmqos_head;
+ while (elem != NULL) {
+ cpu = elem->data;
+ next = elem->next;
+ if (cpu->timeout <= 0) {
+ pmqos_head = g_list_remove(pmqos_head,
+ (gconstpointer)cpu);
+ free(cpu);
+ cpu = NULL;
+ }
+ elem = next;
}
}
static int pmqos_unlock_timer_start(void)
{
int ret;
- dd_list *elem;
+ GList *elem;
struct pmqos_cpu *cpu;
if (unlock_timer) {
@@ -145,11 +151,12 @@ static int pmqos_unlock_timer_start(void)
unlock_timer = NULL;
}
- ret = DD_LIST_LENGTH(pmqos_head);
+ ret = g_list_length(pmqos_head);
if (ret == 0)
return 0;
- DD_LIST_FOREACH(pmqos_head, elem, cpu) {
+ for (elem = pmqos_head; elem != NULL; elem = elem->next) {
+ cpu = elem->data;
if (cpu->timeout <= 0)
continue;
memcpy(&unlock_timer_owner, cpu, sizeof(struct pmqos_cpu));
@@ -161,19 +168,23 @@ static int pmqos_unlock_timer_start(void)
_E("fail init pmqos unlock %s %d", cpu->name, cpu->timeout);
return -EPERM;
}
+
return 0;
}
static int pmqos_cancel(const char *name)
{
- dd_list *elem;
+ GList *elem;
struct pmqos_cpu *cpu;
/* Find previous request */
- DD_LIST_FOREACH(pmqos_head, elem, cpu) {
+ cpu = NULL;
+ for (elem = pmqos_head; elem != NULL; elem = elem->next) {
+ cpu = elem->data;
if (!strcmp(cpu->name, name))
break;
}
+
/* no cpu */
if (!cpu)
return 0;
@@ -181,7 +192,7 @@ static int pmqos_cancel(const char *name)
/* unlock cpu */
set_pmqos(cpu->name, false);
/* delete cpu */
- DD_LIST_REMOVE(pmqos_head, cpu);
+ pmqos_head = g_list_remove(pmqos_head, (gconstpointer)cpu);
free(cpu);
if (strncmp(unlock_timer_owner.name, name, strlen(name)))
@@ -223,7 +234,7 @@ static int compare_timeout(const void *a, const void *b)
static int pmqos_request(const char *name, int val)
{
- dd_list *elem;
+ GList *elem;
struct pmqos_cpu *cpu;
int found = 0;
int ret;
@@ -234,14 +245,17 @@ static int pmqos_request(const char *name, int val)
unlock_max_timeout_ms);
val = unlock_max_timeout_ms;
}
+
/* find cpu */
- DD_LIST_FOREACH(pmqos_head, elem, cpu) {
+ for (elem = pmqos_head; elem != NULL; elem = elem->next) {
+ cpu = elem->data;
if (!strcmp(cpu->name, name)) {
cpu->timeout = val;
found = 1;
break;
}
}
+
/* add cpu */
if (!found) {
cpu = calloc(1, sizeof(struct pmqos_cpu));
@@ -250,10 +264,10 @@ static int pmqos_request(const char *name, int val)
snprintf(cpu->name, sizeof(cpu->name), "%s", name);
cpu->timeout = val;
- DD_LIST_APPEND(pmqos_head, cpu);
+ pmqos_head = g_list_append(pmqos_head, (gpointer)cpu);
}
/* sort cpu */
- DD_LIST_SORT(pmqos_head, compare_timeout);
+ pmqos_head = g_list_sort(pmqos_head, compare_timeout);
ret = pmqos_unlock_timer_start();
if (ret < 0)
@@ -264,7 +278,7 @@ static int pmqos_request(const char *name, int val)
return 0;
err:
if (!found) {
- DD_LIST_REMOVE(pmqos_head, cpu);
+ pmqos_head = g_list_remove(pmqos_head, (gconstpointer)cpu);
free(cpu);
}
@@ -424,7 +438,7 @@ static void pmqos_free(void)
/* Clean up pmqos_head */
if (pmqos_head) {
- DD_LIST_FREE_LIST_FULL(pmqos_head, free);
+ g_list_free_full(pmqos_head, free);
pmqos_head = NULL;
}