Move thread name handling to prof_data module
This commit is contained in:
63
src/prof.c
63
src/prof.c
@@ -133,69 +133,6 @@ prof_alloc_rollback(tsd_t *tsd, prof_tctx_t *tctx) {
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
prof_thread_name_alloc(tsdn_t *tsdn, const char *thread_name) {
|
||||
char *ret;
|
||||
size_t size;
|
||||
|
||||
if (thread_name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size = strlen(thread_name) + 1;
|
||||
if (size == 1) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ret = iallocztm(tsdn, size, sz_size2index(size), false, NULL, true,
|
||||
arena_get(TSDN_NULL, 0, true), true);
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(ret, thread_name, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
prof_thread_name_set_impl(tsd_t *tsd, const char *thread_name) {
|
||||
assert(tsd_reentrancy_level_get(tsd) == 0);
|
||||
|
||||
prof_tdata_t *tdata;
|
||||
unsigned i;
|
||||
char *s;
|
||||
|
||||
tdata = prof_tdata_get(tsd, true);
|
||||
if (tdata == NULL) {
|
||||
return EAGAIN;
|
||||
}
|
||||
|
||||
/* Validate input. */
|
||||
if (thread_name == NULL) {
|
||||
return EFAULT;
|
||||
}
|
||||
for (i = 0; thread_name[i] != '\0'; i++) {
|
||||
char c = thread_name[i];
|
||||
if (!isgraph(c) && !isblank(c)) {
|
||||
return EFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
s = prof_thread_name_alloc(tsd_tsdn(tsd), thread_name);
|
||||
if (s == NULL) {
|
||||
return EAGAIN;
|
||||
}
|
||||
|
||||
if (tdata->thread_name != NULL) {
|
||||
idalloctm(tsd_tsdn(tsd), tdata->thread_name, NULL, NULL, true,
|
||||
true);
|
||||
tdata->thread_name = NULL;
|
||||
}
|
||||
if (strlen(s) > 0) {
|
||||
tdata->thread_name = s;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
prof_sys_thread_name_read_impl(char *buf, size_t limit) {
|
||||
#ifdef JEMALLOC_HAVE_PTHREAD_SETNAME_NP
|
||||
|
@@ -473,6 +473,69 @@ prof_bt_count(void) {
|
||||
return bt_count;
|
||||
}
|
||||
|
||||
char *
|
||||
prof_thread_name_alloc(tsdn_t *tsdn, const char *thread_name) {
|
||||
char *ret;
|
||||
size_t size;
|
||||
|
||||
if (thread_name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size = strlen(thread_name) + 1;
|
||||
if (size == 1) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ret = iallocztm(tsdn, size, sz_size2index(size), false, NULL, true,
|
||||
arena_get(TSDN_NULL, 0, true), true);
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(ret, thread_name, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
prof_thread_name_set_impl(tsd_t *tsd, const char *thread_name) {
|
||||
assert(tsd_reentrancy_level_get(tsd) == 0);
|
||||
|
||||
prof_tdata_t *tdata;
|
||||
unsigned i;
|
||||
char *s;
|
||||
|
||||
tdata = prof_tdata_get(tsd, true);
|
||||
if (tdata == NULL) {
|
||||
return EAGAIN;
|
||||
}
|
||||
|
||||
/* Validate input. */
|
||||
if (thread_name == NULL) {
|
||||
return EFAULT;
|
||||
}
|
||||
for (i = 0; thread_name[i] != '\0'; i++) {
|
||||
char c = thread_name[i];
|
||||
if (!isgraph(c) && !isblank(c)) {
|
||||
return EFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
s = prof_thread_name_alloc(tsd_tsdn(tsd), thread_name);
|
||||
if (s == NULL) {
|
||||
return EAGAIN;
|
||||
}
|
||||
|
||||
if (tdata->thread_name != NULL) {
|
||||
idalloctm(tsd_tsdn(tsd), tdata->thread_name, NULL, NULL, true,
|
||||
true);
|
||||
tdata->thread_name = NULL;
|
||||
}
|
||||
if (strlen(s) > 0) {
|
||||
tdata->thread_name = s;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
prof_dump_check_possible_error(bool err_cond, const char *format, ...) {
|
||||
assert(!prof_dump_error);
|
||||
|
Reference in New Issue
Block a user