memaslap/ms_stats.c
memaslap/ms_task.c
memaslap/ms_thread.c)
- target_include_directories(memaslap PRIVATE memaslap ${LIBEVENT_INCLUDEDIR})
- target_link_libraries(memaslap PRIVATE libclient_common ${LIBEVENT_LIBRARIES} Threads::Threads)
+ target_include_directories(memaslap PRIVATE memaslap)
+ target_link_libraries(memaslap PRIVATE libclient_common Threads::Threads)
+ if(PKG_CONFIG_FOUND)
+ target_link_libraries(memaslap PRIVATE PkgConfig::LIBEVENT)
+ else()
+ target_include_directories(memaslap PRIVATE ${LIBEVENT_INCLUDEDIR})
+ target_link_libraries(memaslap PRIVATE ${LIBEVENT_LIBRARIES})
+ endif()
if(CMAKE_INSTALL_RPATH)
set_target_properties(${CLIENT} PROPERTIES
INSTALL_RPATH ${CMAKE_INSTALL_RPATH}/../${CMAKE_INSTALL_LIBDIR})
static uint32_t ms_set_thread_cpu_affinity(uint32_t cpu);
static int ms_setup_thread(ms_thread_ctx_t *thread_ctx);
static void *ms_worker_libevent(void *arg);
-static void ms_create_worker(void *(*func)(void *), void *arg);
+static void ms_create_worker(void *(*func)(void *), ms_thread_ctx_t *arg);
/**
* time-sensitive callers can call it by hand with this,
gettimeofday(&ms_thread->startup_time, NULL);
- ms_thread->base = event_init();
+ ms_thread->base = event_base_new();
if (ms_thread->base == NULL) {
if (atomic_add_32_nv(&cnt, 1) == 0) {
fprintf(stderr, "Can't allocate event base.\n");
ms_thread = pthread_getspecific(ms_thread_key);
event_base_loop(ms_thread->base, 0);
+ event_base_free(ms_thread->base);
+ free(ms_thread);
return NULL;
} /* ms_worker_libevent */
* @param func, the callback function
* @param arg, the argument to pass to the callback function
*/
-static void ms_create_worker(void *(*func)(void *), void *arg) {
- pthread_t thread;
+static void ms_create_worker(void *(*func)(void *), ms_thread_ctx_t *arg) {
pthread_attr_t attr;
int ret;
pthread_attr_init(&attr);
- if ((ret = pthread_create(&thread, &attr, func, arg))) {
+ if ((ret = pthread_create(&arg->pth_id, &attr, func, arg))) {
fprintf(stderr, "Can't create thread: %s.\n", strerror(ret));
exit(1);
}
}
/* Create threads after we've done all the epoll setup. */
for (uint32_t i = 0; i < ms_setting.nthreads; i++) {
- ms_create_worker(ms_worker_libevent, (void *) &ms_thread_ctx[i]);
+ ms_create_worker(ms_worker_libevent, &ms_thread_ctx[i]);
}
} /* ms_thread_init */
/* cleanup some resource of threads when all the threads exit */
void ms_thread_cleanup() {
+ for (uint32_t i = 0; i < ms_setting.nthreads; i++) {
+ pthread_join(ms_thread_ctx[i].pth_id, NULL);
+ }
if (ms_thread_ctx) {
free(ms_thread_ctx);
}
VERSION v${LIBMEMCACHED_VERSION})
target_compile_definitions(libmemcached PRIVATE -DBUILDING_LIBMEMCACHED)
target_link_libraries(libmemcached PUBLIC libhashkit Threads::Threads ${LIBSASL_LIBRARIES} ${CMAKE_DL_LIBS} ${Backtrace_LIBRARIES})
+if(PKG_CONFIG_FOUND)
+ target_link_libraries(libmemcached PUBLIC libhashkit PkgConfig::LIBSASL)
+else()
+ target_link_libraries(libmemcached PUBLIC ${LIBSASL_LIBRARIES})
+ target_include_directories(libmemcached PUBLIC ${LIBSASL_INCLUDEDIR})
+endif()
target_include_directories(libmemcached PRIVATE ${Backtrace_INCLUDE_DIR})
target_include_directories(libmemcached PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
${CMAKE_BINARY_DIR})
-target_include_directories(libmemcached PUBLIC ${LIBSASL_INCLUDEDIR})
target_include_directories(libmemcached PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>