diff options
-rw-r--r-- | src/util/u_queue.c | 32 | ||||
-rw-r--r-- | src/util/u_queue.h | 2 |
2 files changed, 31 insertions, 3 deletions
diff --git a/src/util/u_queue.c b/src/util/u_queue.c index da513fd9cc5..72ce1fc00a6 100644 --- a/src/util/u_queue.c +++ b/src/util/u_queue.c @@ -31,6 +31,7 @@ #include "util/os_time.h" #include "util/u_string.h" #include "util/u_thread.h" +#include "process.h" static void util_queue_killall_and_wait(struct util_queue *queue); @@ -240,7 +241,8 @@ util_queue_thread_func(void *input) if (queue->name) { char name[16]; - util_snprintf(name, sizeof(name), "%s:%i", queue->name, thread_index); + util_snprintf(name, sizeof(name), "%s%i", queue->name, thread_index); + puts(name); u_thread_setname(name); } @@ -299,8 +301,34 @@ util_queue_init(struct util_queue *queue, { unsigned i; + /* Form the thread name from process_name and name, limited to 13 + * characters. Characters 14-15 are reserved for the thread number. + * Character 16 should be 0. Final form: "process:name12" + * + * If name is too long, it's truncated. If any space is left, the process + * name fills it. + */ + const char *process_name = util_get_process_name(); + int process_len = process_name ? strlen(process_name) : 0; + int name_len = strlen(name); + const int max_chars = sizeof(queue->name) - 1; + + name_len = MIN2(name_len, max_chars); + + /* See if there is any space left for the process name, reserve 1 for + * the colon. */ + process_len = MIN2(process_len, max_chars - name_len - 1); + process_len = MAX2(process_len, 0); + memset(queue, 0, sizeof(*queue)); - queue->name = name; + + if (process_len) { + snprintf(queue->name, sizeof(queue->name), "%.*s:%s", + process_len, process_name, name); + } else { + snprintf(queue->name, sizeof(queue->name), "%s", name); + } + queue->flags = flags; queue->num_threads = num_threads; queue->max_jobs = max_jobs; diff --git a/src/util/u_queue.h b/src/util/u_queue.h index d702c4bce8d..714d9243f00 100644 --- a/src/util/u_queue.h +++ b/src/util/u_queue.h @@ -199,7 +199,7 @@ struct util_queue_job { /* Put this into your context. */ struct util_queue { - const char *name; + char name[14]; /* 13 characters = the thread name without the index */ mtx_t finish_lock; /* only for util_queue_finish */ mtx_t lock; cnd_t has_queued_cond; |