OPTION(ENABLE_HYPERSCAN "Enable hyperscan for fast regexp processing [default: OFF]" OFF)
OPTION(ENABLE_FANN "Enable fann for neural network plugin [default: OFF]" OFF)
OPTION(ENABLE_PCRE2 "Enable pcre2 instead of pcre [default: OFF]" OFF)
+OPTION(ENABLE_JEMALLOC "Build rspamd with jemalloc allocator [default: OFF]" OFF)
INCLUDE(FindArch.cmake)
TARGET_ARCHITECTURE(ARCH)
ProcessPackage(PCRE LIBRARY pcre INCLUDE pcre.h INCLUDE_SUFFIXES include/pcre
ROOT ${PCRE_ROOT_DIR} MODULES pcre libpcre pcre3 libpcre3)
ENDIF()
+IF(ENABLE_JEMALLOC MATCHES "ON")
+ ProcessPackage(JEMALLOC LIBRARY jemalloc INCLUDE jemalloc.h INCLUDE_SUFFIXES include/jemalloc
+ ROOT ${JEMALLOC_ROOT_DIR} MODULES jemalloc)
+ SET(WITH_JEMALLOC "1")
+ENDIF()
ProcessPackage(GMIME LIBRARY gmime-2.6 gmime-2.4 gmime-2.2 gmime-2 INCLUDE gmime.h INCLUDE_SUFFIXES include/gmime
ROOT ${GMIME_ROOT_DIR} MODULES gmime-2.6 gmime-2.4 gmime-2.0)
ProcessPackage(LIBEVENT LIBRARY event INCLUDE event.h INCLUDE_SUFFIXES include/event
#cmakedefine WITH_GPERF_TOOLS 1
#cmakedefine WITH_HIREDIS 1
#cmakedefine WITH_HYPERSCAN 1
+#cmakedefine WITH_JEMALLOC 1
#cmakedefine WITH_JUDY 1
#cmakedefine WITH_LUA 1
#cmakedefine WITH_PCRE2 1
#include <stdlib.h>
#endif
+#ifdef WITH_JEMALLOC
+#include <jemalloc.h>
+#endif
+
/* stdio */
#ifdef HAVE_STDIO_H
#include <stdio.h>
extern uint64_t ottery_rand_uint64(void);
#define UCL_RANDOM_FUNCTION ottery_rand_uint64()
+/* Disable slab allocator if jemalloc is already in the system */
+#if defined(WITH_JEMALLOC) || defined(__FreeBSD__) || \
+ (defined(__NetBSD__) && __NetBSD_Version__ >= 500000000)
+ #define g_slice_alloc(sz) g_malloc(sz)
+ #define g_slice_alloc0(sz) g_malloc0(sz)
+ #define g_slice_free1(sz, p) g_free(p)
+#endif
+
#endif