diff --git a/CMakeLists.txt b/CMakeLists.txt index 534026c..51d9723 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,8 +222,6 @@ endif() include_directories( ${CMAKE_CURRENT_BINARY_DIR}/compat - ${CMAKE_CURRENT_SOURCE_DIR}/htparse - ${CMAKE_CURRENT_SOURCE_DIR}/evthr ${CMAKE_CURRENT_SOURCE_DIR} ${ONIG_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} @@ -246,11 +244,11 @@ if (NOT ${LIBEVENT_OPENSSL_FOUND}) set (EVHTP_DISABLE_SSL ON) endif(NOT ${LIBEVENT_OPENSSL_FOUND}) -set(LIBEVHTP_SOURCES evhtp.c evhtp_numtoa.c htparse/htparse.c) +set(LIBEVHTP_SOURCES evhtp.c evhtp_numtoa.c htparse.c) if (NOT EVHTP_DISABLE_EVTHR) set (LIBEVHTP_EXTERNAL_LIBS ${LIBEVHTP_EXTERNAL_LIBS} pthread) - set (LIBEVHTP_SOURCES ${LIBEVHTP_SOURCES} evthr/evthr.c) + set (LIBEVHTP_SOURCES ${LIBEVHTP_SOURCES} evthr.c) endif(NOT EVHTP_DISABLE_EVTHR) IF (WIN32) @@ -313,11 +311,11 @@ endif() install (TARGETS evhtp DESTINATION ${LIB_INSTALL_DIR}) install (FILES evhtp.h DESTINATION ${INCLUDE_INSTALL_DIR}) -install (FILES htparse/htparse.h DESTINATION ${INCLUDE_INSTALL_DIR}) +install (FILES htparse.h DESTINATION ${INCLUDE_INSTALL_DIR}) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/evhtp-config.h DESTINATION ${INCLUDE_INSTALL_DIR}) if (NOT EVHTP_DISABLE_EVTHR) - install (FILES evthr/evthr.h DESTINATION ${INCLUDE_INSTALL_DIR}) + install (FILES evthr.h DESTINATION ${INCLUDE_INSTALL_DIR}) endif() # oniguruma/onigposix.h diff --git a/build/placeholder b/build/placeholder new file mode 100644 index 0000000..e69de29 diff --git a/evhtp-config.h.in b/evhtp-config.h.in index 808348c..72168cd 100644 --- a/evhtp-config.h.in +++ b/evhtp-config.h.in @@ -5,6 +5,15 @@ extern "C" { #endif +#ifndef EVHTP_EXPORT +# if (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER || defined __clang__ +# define EVHTP_EXPORT __attribute__ ((visibility("default"))) +# else +# define EVHTP_EXPORT +# endif +#endif + + #undef EVHTP_DISABLE_EVTHR #undef EVHTP_DISABLE_REGEX #undef EVHTP_DISABLE_SSL diff --git a/evhtp.h b/evhtp.h index ddc4996..e8f7323 100644 --- a/evhtp.h +++ b/evhtp.h @@ -3,14 +3,6 @@ #include -#ifndef EVHTP_EXPORT -# if (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER || defined __clang__ -# define EVHTP_EXPORT __attribute__ ((visibility("default"))) -# else -# define EVHTP_EXPORT -# endif -#endif - #ifndef EVHTP_DISABLE_EVTHR #include #endif diff --git a/evthr/evthr.c b/evthr.c similarity index 94% rename from evthr/evthr.c rename to evthr.c index 486c469..295a4a9 100644 --- a/evthr/evthr.c +++ b/evthr.c @@ -369,17 +369,3 @@ evthr_pool_start(evthr_pool_t * pool) { return 0; } - -EXPORT_SYMBOL(evthr_new); -EXPORT_SYMBOL(evthr_get_base); -EXPORT_SYMBOL(evthr_set_aux); -EXPORT_SYMBOL(evthr_get_aux); -EXPORT_SYMBOL(evthr_start); -EXPORT_SYMBOL(evthr_stop); -EXPORT_SYMBOL(evthr_defer); -EXPORT_SYMBOL(evthr_free); -EXPORT_SYMBOL(evthr_pool_new); -EXPORT_SYMBOL(evthr_pool_start); -EXPORT_SYMBOL(evthr_pool_stop); -EXPORT_SYMBOL(evthr_pool_defer); -EXPORT_SYMBOL(evthr_pool_free); diff --git a/evthr.h b/evthr.h new file mode 100644 index 0000000..978fbae --- /dev/null +++ b/evthr.h @@ -0,0 +1,56 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE 1 +#endif +#ifndef __EVTHR_H__ +#define __EVTHR_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum evthr_res { + EVTHR_RES_OK = 0, + EVTHR_RES_BACKLOG, + EVTHR_RES_RETRY, + EVTHR_RES_NOCB, + EVTHR_RES_FATAL +}; + +struct evthr_pool; +struct evthr; + +typedef struct event_base evbase_t; +typedef struct event ev_t; + +typedef struct evthr_pool evthr_pool_t; +typedef struct evthr evthr_t; +typedef enum evthr_res evthr_res; + +typedef void (* evthr_cb)(evthr_t * thr, void * cmd_arg, void * shared); +typedef void (* evthr_init_cb)(evthr_t * thr, void * shared); + +EVHTP_EXPORT evthr_t * evthr_new(evthr_init_cb init_cb, void * arg); +EVHTP_EXPORT evbase_t * evthr_get_base(evthr_t * thr); +EVHTP_EXPORT void evthr_set_aux(evthr_t * thr, void * aux); +EVHTP_EXPORT void * evthr_get_aux(evthr_t * thr); +EVHTP_EXPORT int evthr_start(evthr_t * evthr); +EVHTP_EXPORT evthr_res evthr_stop(evthr_t * evthr); +EVHTP_EXPORT evthr_res evthr_defer(evthr_t * evthr, evthr_cb cb, void * arg); +EVHTP_EXPORT void evthr_free(evthr_t * evthr); + +EVHTP_EXPORT evthr_pool_t * evthr_pool_new(int nthreads, evthr_init_cb init_cb, void * shared); +EVHTP_EXPORT int evthr_pool_start(evthr_pool_t * pool); +EVHTP_EXPORT evthr_res evthr_pool_stop(evthr_pool_t * pool); +EVHTP_EXPORT evthr_res evthr_pool_defer(evthr_pool_t * pool, evthr_cb cb, void * arg); +EVHTP_EXPORT void evthr_pool_free(evthr_pool_t * pool); + +#ifdef __cplusplus +} +#endif + +#endif /* __EVTHR_H__ */ + diff --git a/evthr/Makefile b/evthr/Makefile deleted file mode 100644 index 925356e..0000000 --- a/evthr/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -SRC = evthr.c -OUT = libevthr.a -OBJ = $(SRC:.c=.o) -INCLUDES = -I. -CFLAGS += -Wall -Wextra -ggdb -LDFLAGS += -ggdb -CC = gcc - -.SUFFIXES: .c - -default: $(OUT) - -.c.o: - $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@ - -$(OUT): $(OBJ) - ar rcs $(OUT) $(OBJ) - -test: $(OUT) test.c - $(CC) $(INCLUDES) $(CFLAGS) test.c -o test $(OUT) -levent -levent_pthreads -lpthread - -clean: - rm -f $(OBJ) $(OUT) test - diff --git a/evthr/README b/evthr/README deleted file mode 100644 index 5ce37cb..0000000 --- a/evthr/README +++ /dev/null @@ -1,53 +0,0 @@ -Libevthr is an API which manages threads and thread-pools in an event based -manner. This API requires libevent with threading support. - -Libevthr works a bit differently than most thread management systems. Instead of -conditional signalling and some type of pre-thread queue, Libevthr uses a -deferral type mechanism. That is, a thread is always running, abstracted to a -point where you "defer" your function *into* a thread. - -For example you can start up a single thread with a backlog of 10 (a backlog -being the max number of outstanding callbacks to run within the thread), and -execute a function you would like to run inside the thread one or many times. -The act of deferrals is non-blocking. - -Example Code for evthrs: - - evthr_t * thr = evthr_new(10, NULL); - - if (evthr_start(thr) < 0) { - exit(1); - } - - evthr_defer(thr, my_cb_1, NULL); - evthr_defer(thr, my_cb_2, NULL); - evthr_defer(thr, my_cb_3, NULL); - - sleep(n_seconds); - - evthr_stop(thr); - -Libevthr also has the ability to create pools using the same methods that a -single evthr has. For example, if you would like to create 10 threads, each -with a backlog of 5: - - evthr_pool_t * thr_pool = evthr_pool_new(10, 5, NULL); - - if (evthr_pool_start(thr_pool) < 0) { - exit(1); - } - - evthr_pool_defer(thr_pool, my_cb_1, NULL); - evthr_pool_defer(thr_pool, my_cb_2, NULL); - evthr_pool_defer(thr_pool, my_cb_3, NULL); - -Your callback functions which you defer must be of type "evthr_cb", or -"void cb_name(void * arg, void * shared)". In this case, the "arg" variable is -the data you passed as the third argument to either evthr_pool_defer, or -evthr_defer. The "shared" variable is the data that was either the second -variable in evthr_new(), or the third variable in evthr_pool_new(). - -The gist of this is to allow a global dataset, along with deferred specific -data. - -See test.c for a quick example. diff --git a/evthr/evthr.h b/evthr/evthr.h deleted file mode 100644 index 5fa9c94..0000000 --- a/evthr/evthr.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#ifndef __EVTHR_H__ -#define __EVTHR_H__ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -enum evthr_res { - EVTHR_RES_OK = 0, - EVTHR_RES_BACKLOG, - EVTHR_RES_RETRY, - EVTHR_RES_NOCB, - EVTHR_RES_FATAL -}; - -struct evthr_pool; -struct evthr; - -typedef struct event_base evbase_t; -typedef struct event ev_t; - -typedef struct evthr_pool evthr_pool_t; -typedef struct evthr evthr_t; -typedef enum evthr_res evthr_res; - -typedef void (*evthr_cb)(evthr_t * thr, void * cmd_arg, void * shared); -typedef void (*evthr_init_cb)(evthr_t * thr, void * shared); - -evthr_t * evthr_new(evthr_init_cb init_cb, void * arg); -evbase_t * evthr_get_base(evthr_t * thr); -void evthr_set_aux(evthr_t * thr, void * aux); -void * evthr_get_aux(evthr_t * thr); -int evthr_start(evthr_t * evthr); -evthr_res evthr_stop(evthr_t * evthr); -evthr_res evthr_defer(evthr_t * evthr, evthr_cb cb, void * arg); -void evthr_free(evthr_t * evthr); - -evthr_pool_t * evthr_pool_new(int nthreads, evthr_init_cb init_cb, void * shared); -int evthr_pool_start(evthr_pool_t * pool); -evthr_res evthr_pool_stop(evthr_pool_t * pool); -evthr_res evthr_pool_defer(evthr_pool_t * pool, evthr_cb cb, void * arg); -void evthr_pool_free(evthr_pool_t * pool); - -#ifdef __cplusplus -} -#endif - -#endif /* __EVTHR_H__ */ - diff --git a/evthr/test.c b/evthr/test.c deleted file mode 100644 index 8f762df..0000000 --- a/evthr/test.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -static void -_test_cb_1(evthr_t * thr, void * cmdarg, void * shared) { - printf("START _test_cb_1 (%u)\n", (unsigned int)pthread_self()); - sleep(1); - printf("END _test_cb_1 (%u)\n", (unsigned int)pthread_self()); -} - -int -main(int argc, char ** argv) { - evthr_pool_t * pool = NULL; - int i = 0; - - pool = evthr_pool_new(8, NULL, NULL); - - evthr_pool_start(pool); - - while (1) { - if (i++ >= 5) { - break; - } - - printf("Iter %d\n", i); - - printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); - printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); - printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); - printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); - printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); - printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); - - sleep(2); - } - - evthr_pool_stop(pool); - evthr_pool_free(pool); - - pool = evthr_pool_new(2, NULL, NULL); - i = 0; - - evthr_pool_set_max_backlog(pool, 1); - evthr_pool_start(pool); - - while (1) { - if (i++ >= 5) { - break; - } - - printf("Iter %d\n", i); - - printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); - printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); - printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); - } - - evthr_pool_stop(pool); - evthr_pool_free(pool); - - return 0; -} /* main */ - diff --git a/htparse/test.c b/examples/test_htparse.c similarity index 100% rename from htparse/test.c rename to examples/test_htparse.c diff --git a/htparse/htparse.c b/htparse.c similarity index 100% rename from htparse/htparse.c rename to htparse.c diff --git a/htparse/htparse.h b/htparse.h similarity index 100% rename from htparse/htparse.h rename to htparse.h diff --git a/htparse/Makefile b/htparse/Makefile deleted file mode 100644 index 6695458..0000000 --- a/htparse/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -SRC = htparse.c -OUT = libhtparse.a -OBJ = $(SRC:.c=.o) -INCLUDES = -I. -I.. -CFLAGS += -ggdb -LDFLAGS += -CC = gcc - -.SUFFIXES: .c - -default: $(OUT) test - -.c.o: - $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@ - -$(OUT): $(OBJ) - ar rcs $(OUT) $(OBJ) - -test: $(OUT) test.c - $(CC) $(INCLUDES) $(CFLAGS) test.c -o test $(OUT) - -clean: - rm -f $(OBJ) $(OUT) test