mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-19 10:49:31 +00:00
Refactor, replace BSD queue.h LIST_ macros with homegrown version
This patch replaces the BSD doubly linked list implementation with a simplified homegrown version. This not only reduces the dependency on an external "library", but also greatly simplifies licensing and gives us a clean name space that does not intrude on users who want to use their own version of queue.h in their application that also includes the libuEv header file. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
ebe3888d6f
commit
e6b99da0f5
7 files changed
+49
-675
No files matched your search
+35
-4
@@ -27,7 +27,38 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/epoll.h>
|
||||
#include "queue.h" /* OpenBSD queue.h > old GLIBC version */
|
||||
|
||||
/*
|
||||
* List functions.
|
||||
*/
|
||||
#define _UEV_FOREACH(node, list) \
|
||||
for (typeof (node) next, node = list; \
|
||||
node && (next = node->next, 1); \
|
||||
node = next)
|
||||
|
||||
#define _UEV_INSERT(node, list) do { \
|
||||
typeof (node) next; \
|
||||
next = list; \
|
||||
list = node; \
|
||||
if (next) \
|
||||
next->prev = node; \
|
||||
node->next = next; \
|
||||
node->prev = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define _UEV_REMOVE(node, list) do { \
|
||||
typeof (node) prev, next; \
|
||||
prev = node->prev; \
|
||||
next = node->next; \
|
||||
if (prev) \
|
||||
prev->next = next; \
|
||||
if (next) \
|
||||
next->prev = prev; \
|
||||
node->prev = NULL; \
|
||||
node->next = NULL; \
|
||||
if (list == node) \
|
||||
list = next; \
|
||||
} while (0)
|
||||
|
||||
/* I/O, timer, or signal watcher */
|
||||
typedef enum {
|
||||
@@ -44,8 +75,8 @@ typedef enum {
|
||||
/* Main libuEv context type */
|
||||
typedef struct {
|
||||
int running;
|
||||
int fd; /* For epoll() */
|
||||
LIST_HEAD(,uev) watchers;
|
||||
int fd; /* For epoll() */
|
||||
struct uev *watchers;
|
||||
uint32_t workaround; /* For workarounds, e.g. redirected stdin */
|
||||
} uev_ctx_t;
|
||||
|
||||
@@ -54,7 +85,7 @@ struct uev;
|
||||
|
||||
/* This is used to hide all private data members in uev_t */
|
||||
#define uev_private_t \
|
||||
LIST_ENTRY(uev) link; /* For queue.h linked list */ \
|
||||
struct uev *next, *prev; \
|
||||
\
|
||||
int active; \
|
||||
int events; \
|
||||
|
||||
Reference in new issue
Block a user