From f6ce4e89969e0a863bb784a4c96961171d86f156 Mon Sep 17 00:00:00 2001 From: Emil Renner Berthing Date: Sat, 26 Feb 2011 18:57:50 +0100 Subject: use kqueue on FreeBSD --- Makefile | 10 ++++++++-- config.FreeBSD | 44 ++++++++++++++++++++++++++++++++++++++++++++ config.Linux | 44 ++++++++++++++++++++++++++++++++++++++++++++ config.in | 44 -------------------------------------------- lem.c | 10 ++++++++-- 5 files changed, 104 insertions(+), 48 deletions(-) create mode 100644 config.FreeBSD create mode 100644 config.Linux delete mode 100644 config.in diff --git a/Makefile b/Makefile index 1625863..6084179 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,12 @@ BINDIR = $(PREFIX)/bin LIBDIR = $(PREFIX)/lib/lua/$(LUA_VERSION) INCDIR = $(PREFIX)/include +OS = $(shell uname) + +ifeq ($(OS), Linux) +DL = -ldl +endif + headers = lem.h config.h macros.h lua/luaconf.h lua/lua.h lua/lauxlib.h libev/ev.h programs = lem utils.so scripts = repl.lua lem-repl @@ -39,7 +45,7 @@ LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \ all: $(programs) -config.h: config.in +config.h: config.$(OS) $Mecho ' SED $@' $O$(SED) -e 's|@PREFIX@|$(PREFIX)/|' $< > $@ @@ -61,7 +67,7 @@ event.o: event.c config.h lem: $(CORE_O:%=lua/%) $(LIB_O:%=lua/%) event.o lem.o $Mecho ' LD $@' - $O$(CC) -rdynamic -lm -ldl $(LDFLAGS) $^ -o $@ + $O$(CC) -rdynamic -lm $(DL) $(LDFLAGS) $^ -o $@ utils.so: utils.pic.o $Mecho ' LD $@' diff --git a/config.FreeBSD b/config.FreeBSD new file mode 100644 index 0000000..6ccaf05 --- /dev/null +++ b/config.FreeBSD @@ -0,0 +1,44 @@ +/* + * This file is part of LEM, a Lua Event Machine. + * Copyright 2011 Emil Renner Berthing + * + * LEM is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * LEM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LEM. If not, see . + */ + +#define LUA_USE_LINUX +#define LUA_ROOT "@PREFIX@" + +#define EV_STANDALONE 1 +#define EV_USE_MONOTONIC 1 +#define EV_USE_CLOCK_SYSCALL 0 +#define EV_USE_NANOSLEEP 1 +#define EV_USE_EVENTFD 0 + +#define EV_USE_SELECT 0 +#define EV_USE_POLL 0 +#define EV_USE_EPOLL 0 +#define EV_USE_KQUEUE 1 +#define EV_USE_PORT 0 + +#define EV_MULTIPLICITY 0 + +#define EV_PERIODIC_ENABLE 0 +#define EV_IDLE_ENABLE 1 +#define EV_EMBED_ENABLE 0 +#define EV_STAT_ENABLE 0 +#define EV_FORK_ENABLE 0 +#define EV_ASYNC_ENABLE 0 + +#define EV_MINPRI 0 +#define EV_MAXPRI 0 diff --git a/config.Linux b/config.Linux new file mode 100644 index 0000000..eae65f3 --- /dev/null +++ b/config.Linux @@ -0,0 +1,44 @@ +/* + * This file is part of LEM, a Lua Event Machine. + * Copyright 2011 Emil Renner Berthing + * + * LEM is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * LEM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LEM. If not, see . + */ + +#define LUA_USE_LINUX +#define LUA_ROOT "@PREFIX@" + +#define EV_STANDALONE 1 +#define EV_USE_MONOTONIC 1 +#define EV_USE_CLOCK_SYSCALL 1 +#define EV_USE_NANOSLEEP 1 +#define EV_USE_EVENTFD 1 + +#define EV_USE_SELECT 0 +#define EV_USE_POLL 0 +#define EV_USE_EPOLL 1 +#define EV_USE_KQUEUE 0 +#define EV_USE_PORT 0 + +#define EV_MULTIPLICITY 0 + +#define EV_PERIODIC_ENABLE 0 +#define EV_IDLE_ENABLE 1 +#define EV_EMBED_ENABLE 0 +#define EV_STAT_ENABLE 0 +#define EV_FORK_ENABLE 0 +#define EV_ASYNC_ENABLE 0 + +#define EV_MINPRI 0 +#define EV_MAXPRI 0 diff --git a/config.in b/config.in deleted file mode 100644 index eae65f3..0000000 --- a/config.in +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of LEM, a Lua Event Machine. - * Copyright 2011 Emil Renner Berthing - * - * LEM is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * LEM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LEM. If not, see . - */ - -#define LUA_USE_LINUX -#define LUA_ROOT "@PREFIX@" - -#define EV_STANDALONE 1 -#define EV_USE_MONOTONIC 1 -#define EV_USE_CLOCK_SYSCALL 1 -#define EV_USE_NANOSLEEP 1 -#define EV_USE_EVENTFD 1 - -#define EV_USE_SELECT 0 -#define EV_USE_POLL 0 -#define EV_USE_EPOLL 1 -#define EV_USE_KQUEUE 0 -#define EV_USE_PORT 0 - -#define EV_MULTIPLICITY 0 - -#define EV_PERIODIC_ENABLE 0 -#define EV_IDLE_ENABLE 1 -#define EV_EMBED_ENABLE 0 -#define EV_STAT_ENABLE 0 -#define EV_FORK_ENABLE 0 -#define EV_ASYNC_ENABLE 0 - -#define EV_MINPRI 0 -#define EV_MAXPRI 0 diff --git a/lem.c b/lem.c index f0af489..43bc97b 100644 --- a/lem.c +++ b/lem.c @@ -32,6 +32,12 @@ #include "libev/ev.h" #include "macros.h" +#if EV_USE_KQUEUE +#define LEM_LOOPFLAGS EVBACKEND_KQUEUE +#else +#define LEM_LOOPFLAGS 0 +#endif + #ifdef NDEBUG #define lem_log_error(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__) #else @@ -325,10 +331,10 @@ main(int argc, char *argv[]) } #if EV_MULTIPLICITY - lem_loop = ev_default_loop(0); + lem_loop = ev_default_loop(LEM_LOOPFLAGS); if (lem_loop == NULL) { #else - if (!ev_default_loop(0)) { + if (!ev_default_loop(LEM_LOOPFLAGS)) { #endif lem_log_error("Error initializing event loop"); return EXIT_FAILURE; -- cgit v1.2.1