summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-09-27 16:24:26 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-09-27 16:24:26 +0000
commit247635fe3905e4cc084a167c6db6e53dd7b0554d (patch)
treef04ebede4f19760416493440d945453d791c4ab6
parent30e40ae987f4723deda3949879a6c0cd45fec92a (diff)
Support for prioritized watches
-rw-r--r--common/glib-ectomy.c22
-rw-r--r--common/glib-ectomy.h6
-rw-r--r--common/list.c30
-rw-r--r--common/list.h2
4 files changed, 56 insertions, 4 deletions
diff --git a/common/glib-ectomy.c b/common/glib-ectomy.c
index fe6f524e..f3478edf 100644
--- a/common/glib-ectomy.c
+++ b/common/glib-ectomy.c
@@ -205,6 +205,20 @@ void g_io_remove_watch(guint id)
}
}
+static struct slist *watch_list_add(struct slist *l, struct watch *watch)
+{
+ struct slist *cur;
+
+ for (cur = l; cur != NULL; cur = cur->next) {
+ struct watch *w = cur->data;
+
+ if (w->priority >= watch->priority)
+ break;
+ }
+
+ return slist_insert_before(l, cur, watch);
+}
+
guint g_io_add_watch_full(GIOChannel *channel, gint priority,
GIOCondition condition, GIOFunc func,
gpointer user_data, GDestroyNotify notify)
@@ -228,9 +242,9 @@ guint g_io_add_watch_full(GIOChannel *channel, gint priority,
watch->destroy = notify;
if (context->watch_lock)
- context->proc_watches = slist_prepend(context->proc_watches, watch);
+ context->proc_watches = watch_list_add(context->proc_watches, watch);
else
- context->watches = slist_prepend(context->watches, watch);
+ context->watches = watch_list_add(context->watches, watch);
return watch->id;
}
@@ -385,7 +399,7 @@ void g_main_loop_run(GMainLoop *loop)
if (!*w->revents) {
context->watches = slist_remove(context->watches, w);
- context->proc_watches = slist_append(context->proc_watches, w);
+ context->proc_watches = watch_list_add(context->proc_watches, w);
continue;
}
@@ -403,7 +417,7 @@ void g_main_loop_run(GMainLoop *loop)
continue;
}
- context->proc_watches = slist_append(context->proc_watches, w);
+ context->proc_watches = watch_list_add(context->proc_watches, w);
}
context->watches = context->proc_watches;
diff --git a/common/glib-ectomy.h b/common/glib-ectomy.h
index 4d00870c..411cc25f 100644
--- a/common/glib-ectomy.h
+++ b/common/glib-ectomy.h
@@ -69,6 +69,12 @@ typedef enum {
G_IO_NVAL = POLLNVAL
} GIOCondition;
+#define G_PRIORITY_HIGH -100
+#define G_PRIORITY_DEFAULT 0
+#define G_PRIORITY_HIGH_IDLE 100
+#define G_PRIORITY_DEFAULT_IDLE 200
+#define G_PRIORITY_LOW 300
+
typedef void (*GDestroyNotify) (gpointer data);
typedef gboolean (*GIOFunc) (GIOChannel *source, GIOCondition condition, gpointer data);
diff --git a/common/list.c b/common/list.c
index a887bcdd..579d9574 100644
--- a/common/list.c
+++ b/common/list.c
@@ -70,6 +70,36 @@ struct slist *slist_prepend(struct slist *list, void *data)
return entry;
}
+struct slist *slist_insert_before(struct slist *list, struct slist *sibling, void *data)
+{
+ struct slist *entry, *prev, *cur;
+
+ entry = malloc(sizeof(struct slist));
+ if (!entry)
+ return list;
+
+ entry->data = data;
+ entry->next = NULL;
+
+ if (!list)
+ return entry;
+
+ for (cur = list, prev = NULL; cur != NULL; prev = cur, cur = prev->next) {
+ if (cur == sibling)
+ break;
+ }
+
+ if (!prev) {
+ entry->next = list;
+ return entry;
+ }
+
+ entry->next = prev->next;
+ prev->next = entry;
+
+ return list;
+}
+
struct slist *slist_remove(struct slist *list, void *data)
{
struct slist *l, *next, *prev = NULL, *match = NULL;
diff --git a/common/list.h b/common/list.h
index 1b502110..f6576429 100644
--- a/common/list.h
+++ b/common/list.h
@@ -37,6 +37,8 @@ struct slist *slist_append(struct slist *list, void *data);
struct slist *slist_prepend(struct slist *list, void *data);
+struct slist *slist_insert_before(struct slist *list, struct slist *sibling, void *data);
+
struct slist *slist_remove(struct slist *list, void *data);
struct slist *slist_find(struct slist *list, const void *data,