summaryrefslogtreecommitdiff
path: root/extstore.c
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2022-11-01 14:38:27 -0700
committerdormando <dormando@rydia.net>2022-11-01 22:22:55 -0700
commit875371a75cbf1f92350de2d1fa0fae4a35ed572b (patch)
treeed38925e6afd54c4564b330ee12b6aeb8f1c035a /extstore.c
parent5d2da18808d50705f5038f304974d99f75c30f25 (diff)
downloadmemcached-875371a75cbf1f92350de2d1fa0fae4a35ed572b.tar.gz
core: give threads unique names
allow users to differentiate thread functions externally to memcached. Useful for setting priorities or pinning threads to CPU's.
Diffstat (limited to 'extstore.c')
-rw-r--r--extstore.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/extstore.c b/extstore.c
index f32292f..b079465 100644
--- a/extstore.c
+++ b/extstore.c
@@ -1,5 +1,6 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+#include "config.h"
// FIXME: config.h?
#include <stdint.h>
#include <stdbool.h>
@@ -16,7 +17,6 @@
#include <string.h>
#include <assert.h>
#include "extstore.h"
-#include "config.h"
// TODO: better if an init option turns this on/off.
#ifdef EXTSTORE_DEBUG
@@ -112,6 +112,19 @@ struct store_engine {
struct extstore_stats stats;
};
+// FIXME: code is duplicated from thread.c since extstore.c doesn't pull in
+// the memcached ecosystem. worth starting a cross-utility header with static
+// definitions/macros?
+// keeping a minimal func here for now.
+#define THR_NAME_MAXLEN 16
+static void thread_setname(pthread_t thread, const char *name) {
+assert(strlen(name) < THR_NAME_MAXLEN);
+#if defined(__linux__)
+pthread_setname_np(thread, name);
+#endif
+}
+#undef THR_NAME_MAXLEN
+
static _store_wbuf *wbuf_new(size_t size) {
_store_wbuf *b = calloc(1, sizeof(_store_wbuf));
if (b == NULL)
@@ -378,6 +391,7 @@ void *extstore_init(struct extstore_conf_file *fh, struct extstore_conf *cf,
e->io_threads[i].e = e;
// FIXME: error handling
pthread_create(&thread, NULL, extstore_io_thread, &e->io_threads[i]);
+ thread_setname(thread, "mc-ext-io");
}
e->io_threadcount = cf->io_threadcount;
@@ -387,6 +401,7 @@ void *extstore_init(struct extstore_conf_file *fh, struct extstore_conf *cf,
pthread_mutex_init(&e->maint_thread->mutex, NULL);
pthread_cond_init(&e->maint_thread->cond, NULL);
pthread_create(&thread, NULL, extstore_maint_thread, e->maint_thread);
+ thread_setname(thread, "mc-ext-maint");
extstore_run_maint(e);