summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-04-25 12:13:01 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-04-25 12:15:38 +0200
commit13fc5ad29e2fac4437f11fd2eeb648e41569bc90 (patch)
treee5676025105e0d9937126e69efc5fac70b05ea79
parent7f3a56fc5886e2017423783d2cc5230ea7865a94 (diff)
wfdevent: Replace GQueue with a list
Removes last glib dependency.
-rw-r--r--configure.ac2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/wfdevent.c19
-rw-r--r--src/wflist.c70
-rw-r--r--src/wflist.h97
5 files changed, 180 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac
index e1f8c7e..695899d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,7 @@ LT_INIT
PKG_PROG_PKG_CONFIG()
-PKG_CHECK_MODULES(OWFDRM, [libudev libdrm egl glib-2.0])
+PKG_CHECK_MODULES(OWFDRM, [libudev libdrm egl])
PKG_CHECK_MODULES(TEST, [egl gl])
if test "x$GCC" = "xyes"; then
diff --git a/src/Makefile.am b/src/Makefile.am
index 0a9e36f..c3fa526 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,6 +2,7 @@ lib_LTLIBRARIES = libWFD.la
noinst_HEADERS = \
wfhandle.h \
+ wflist.h \
wfdregistry.h \
wfddevice.h \
wfdport.h \
@@ -14,6 +15,7 @@ libWFD_la_LIBADD = $(OWFDRM_LIBS) -lm
libWFD_la_SOURCES = \
wfdapi.c \
wfhandle.c \
+ wflist.c \
wfdregistry.c \
wfddevice.c \
wfdport.c \
diff --git a/src/wfdevent.c b/src/wfdevent.c
index 5d0afc5..e7cb165 100644
--- a/src/wfdevent.c
+++ b/src/wfdevent.c
@@ -29,6 +29,7 @@
#include <WF/wfd.h>
#include <WF/wfdext.h>
+#include "wflist.h"
#include "wfdregistry.h"
#include "wfdevent.h"
#include "wfdport.h"
@@ -42,12 +43,11 @@
#include <sys/time.h>
#include <unistd.h>
-#include <glib.h>
-
-
struct bind_event {
WFDint pipeline_id;
WFDint time;
+
+ struct wf_list link;
};
struct wfd_event {
@@ -67,7 +67,7 @@ struct wfd_event {
WFDboolean attach_state;
int source_bind_event_queue_fd;
- GQueue *bind_event_queue;
+ struct wf_list bind_event_queue;
WFDEventType current_event_type;
};
@@ -76,7 +76,6 @@ void
wfd_event_destroy(struct wfd_device *device,
struct wfd_event *event)
{
- g_queue_free(event->bind_event_queue);
close(event->drm_fd);
udev_monitor_unref(event->udev_monitor);
close(event->epoll_fd);
@@ -178,7 +177,7 @@ wfd_create_event(struct wfd_device *device,
return NULL;
}
- event->bind_event_queue = g_queue_new();
+ wf_list_init(&event->bind_event_queue);
event->device = device;
event->current_event_type = WFD_EVENT_NONE;
@@ -268,8 +267,8 @@ page_flip_handler(int fd, unsigned int frame,
if (queue_entry) {
*queue_entry = bind;
- g_queue_push_tail(global_event->bind_event_queue,
- queue_entry);
+ wf_list_push_tail(&global_event->bind_event_queue,
+ queue_entry, link);
write(global_event->source_bind_event_queue_fd,
&add, sizeof add);
@@ -327,7 +326,9 @@ wfd_event_wait(struct wfd_device *device,
read(event->source_bind_event_queue_fd, &id, sizeof id);
- queue_entry = g_queue_pop_head(event->bind_event_queue);
+ wf_list_pop_head(&event->bind_event_queue,
+ queue_entry, link);
+
event->bind = *queue_entry;
free(queue_entry);
event_type = WFD_EVENT_PIPELINE_BIND_SOURCE_COMPLETE;
diff --git a/src/wflist.c b/src/wflist.c
new file mode 100644
index 0000000..e8981de
--- /dev/null
+++ b/src/wflist.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011 Kristian Høgsberg
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include "wflist.h"
+
+void
+wf_list_init(struct wf_list *list)
+{
+ list->prev = list;
+ list->next = list;
+}
+
+void
+wf_list_insert(struct wf_list *list, struct wf_list *elm)
+{
+ elm->prev = list;
+ elm->next = list->next;
+ list->next = elm;
+ elm->next->prev = elm;
+}
+
+void
+wf_list_remove(struct wf_list *elm)
+{
+ elm->prev->next = elm->next;
+ elm->next->prev = elm->prev;
+}
+
+int
+wf_list_length(struct wf_list *list)
+{
+ struct wf_list *e;
+ int count;
+
+ count = 0;
+ e = list->next;
+ while (e != list) {
+ e = e->next;
+ count++;
+ }
+
+ return count;
+}
+
+int
+wf_list_empty(struct wf_list *list)
+{
+ return list->next == list;
+}
+
diff --git a/src/wflist.h b/src/wflist.h
new file mode 100644
index 0000000..036f383
--- /dev/null
+++ b/src/wflist.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2011 Kristian Høgsberg
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _WF_LIST_H_
+#define _WF_LIST_H_
+
+/**
+ * wf_list - linked list
+ *
+ * The list head is of "struct wf_list" type, and must be initialized
+ * using wf_list_init(). All entries in the list must be of the same
+ * type. The item type must have a "struct wf_list" member. This
+ * member will be initialized by wf_list_insert(). There is no need to
+ * call wf_list_init() on the individual item. To query if the list is
+ * empty in O(1), use wf_list_empty().
+ *
+ * Let's call the list reference "struct wf_list foo_list", the item type as
+ * "item_t", and the item member as "struct wf_list link". The following code
+ *
+ * The following code will initialize a list:
+ *
+ * wf_list_init(foo_list);
+ * wf_list_insert(foo_list, item1); Pushes item1 at the head
+ * wf_list_insert(foo_list, item2); Pushes item2 at the head
+ * wf_list_insert(item2, item3); Pushes item3 after item2
+ *
+ * The list now looks like [item2, item3, item1]
+ *
+ * Will iterate the list in ascending order:
+ *
+ * item_t *item;
+ * wf_list_for_each(item, foo_list, link) {
+ * Do_something_with_item(item);
+ * }
+ */
+struct wf_list {
+ struct wf_list *prev;
+ struct wf_list *next;
+};
+
+void wf_list_init(struct wf_list *list);
+void wf_list_insert(struct wf_list *list, struct wf_list *elm);
+void wf_list_remove(struct wf_list *elm);
+int wf_list_length(struct wf_list *list);
+int wf_list_empty(struct wf_list *list);
+
+#define __container_of(ptr, sample, member) \
+ (void *)((char *)(ptr) - \
+ ((char *)&(sample)->member - (char *)(sample)))
+
+#define wf_list_for_each(pos, head, member) \
+ for (pos = 0, pos = __container_of((head)->next, pos, member); \
+ &pos->member != (head); \
+ pos = __container_of(pos->member.next, pos, member))
+
+#define wf_list_for_each_safe(pos, tmp, head, member) \
+ for (pos = 0, tmp = 0, \
+ pos = __container_of((head)->next, pos, member), \
+ tmp = __container_of((pos)->member.next, tmp, member); \
+ &pos->member != (head); \
+ pos = tmp, \
+ tmp = __container_of(pos->member.next, tmp, member))
+
+#define wf_list_for_each_reverse(pos, head, member) \
+ for (pos = 0, pos = __container_of((head)->prev, pos, member); \
+ &pos->member != (head); \
+ pos = __container_of(pos->member.prev, pos, member))
+
+#define wf_list_push_tail(head, element, member) \
+ wf_list_insert((head)->prev, &(element)->member)
+
+#define wf_list_pop_head(head, result, member) \
+ do { \
+ result = __container_of((head)->next, result, member); \
+ wf_list_remove((head)->next); \
+ } while (0)
+
+#endif /* _WF_LIST_H_ */