If available (__NetBSD__), use pthread_setname_np() to set the

thread name for kthread_create().
This commit is contained in:
pooka 2008-12-17 20:16:28 +00:00
parent 6b7c41cff5
commit c60be09da1
3 changed files with 23 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpuser.h,v 1.3 2008/11/25 20:39:57 pooka Exp $ */
/* $NetBSD: rumpuser.h,v 1.4 2008/12/17 20:16:28 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -84,7 +84,7 @@ int rumpuser_thrinit(void);
int rumpuser_bioinit(rump_biodone_fn);
void rumpuser_thrdestroy(void);
int rumpuser_thread_create(void *(*f)(void *), void *);
int rumpuser_thread_create(void *(*f)(void *), void *, const char *);
void rumpuser_thread_exit(void);
struct rumpuser_mtx;

View File

@ -1,4 +1,4 @@
/* $NetBSD: emul.c,v 1.59 2008/12/14 19:58:29 pooka Exp $ */
/* $NetBSD: emul.c,v 1.60 2008/12/17 20:16:28 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -404,6 +404,9 @@ int
kthread_create(pri_t pri, int flags, struct cpu_info *ci,
void (*func)(void *), void *arg, lwp_t **newlp, const char *fmt, ...)
{
char thrstore[MAXCOMLEN];
const char *thrname = NULL;
va_list ap;
struct kthdesc *k;
struct lwp *l;
int rv;
@ -441,7 +444,13 @@ kthread_create(pri_t pri, int flags, struct cpu_info *ci,
k->arg = arg;
k->mylwp = l = rump_setup_curlwp(0, rump_nextlid(), 0);
k->mpsafe = flags & KTHREAD_MPSAFE;
rv = rumpuser_thread_create(threadbouncer, k);
if (fmt) {
va_start(ap, fmt);
vsnprintf(thrstore, sizeof(thrname), fmt, ap);
va_end(ap);
thrname = thrstore;
}
rv = rumpuser_thread_create(threadbouncer, k, thrname);
if (rv)
return rv;

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpuser_pth.c,v 1.19 2008/11/18 12:39:35 pooka Exp $ */
/* $NetBSD: rumpuser_pth.c,v 1.20 2008/12/17 20:16:28 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@ -143,11 +143,18 @@ rumpuser_thrdestroy()
}
int
rumpuser_thread_create(void *(*f)(void *), void *arg)
rumpuser_thread_create(void *(*f)(void *), void *arg, const char *thrname)
{
pthread_t ptid;
int rv;
return pthread_create(&ptid, NULL, f, arg);
rv = pthread_create(&ptid, NULL, f, arg);
#ifdef __NetBSD__
if (rv == 0 && thrname)
pthread_setname_np(ptid, thrname, NULL);
#endif
return rv;
}
void