mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
Add pthread_get_name_np(3).
The function retrieves the thread name previously set by pthread_set_name_np(3). The name is cached in the process memory. Requested by: Willem Jan Withagen <wjw@digiware.nl> Man page update: Yuri Pankov <yuripv@yuripv.net> Reviewed by: ian (previous version) Discussed with: arichardson, bjk (man page) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D16702
This commit is contained in:
parent
d9cf291382
commit
4627d47bc8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=337983
|
@ -49,6 +49,7 @@ int pthread_attr_setcreatesuspend_np(pthread_attr_t *);
|
||||||
int pthread_attr_get_np(pthread_t, pthread_attr_t *);
|
int pthread_attr_get_np(pthread_t, pthread_attr_t *);
|
||||||
int pthread_attr_getaffinity_np(const pthread_attr_t *, size_t, cpuset_t *);
|
int pthread_attr_getaffinity_np(const pthread_attr_t *, size_t, cpuset_t *);
|
||||||
int pthread_attr_setaffinity_np(pthread_attr_t *, size_t, const cpuset_t *);
|
int pthread_attr_setaffinity_np(pthread_attr_t *, size_t, const cpuset_t *);
|
||||||
|
void pthread_get_name_np(pthread_t, char *, size_t);
|
||||||
int pthread_getaffinity_np(pthread_t, size_t, cpuset_t *);
|
int pthread_getaffinity_np(pthread_t, size_t, cpuset_t *);
|
||||||
int pthread_getthreadid_np(void);
|
int pthread_getthreadid_np(void);
|
||||||
int pthread_main_np(void);
|
int pthread_main_np(void);
|
||||||
|
|
|
@ -134,6 +134,7 @@
|
||||||
#define pthread_detach _pthread_detach
|
#define pthread_detach _pthread_detach
|
||||||
#define pthread_equal _pthread_equal
|
#define pthread_equal _pthread_equal
|
||||||
#define pthread_exit _pthread_exit
|
#define pthread_exit _pthread_exit
|
||||||
|
#define pthread_get_name_np _pthread_get_name_np
|
||||||
#define pthread_getaffinity_np _pthread_getaffinity_np
|
#define pthread_getaffinity_np _pthread_getaffinity_np
|
||||||
#define pthread_getconcurrency _pthread_getconcurrency
|
#define pthread_getconcurrency _pthread_getconcurrency
|
||||||
#define pthread_getcpuclockid _pthread_getcpuclockid
|
#define pthread_getcpuclockid _pthread_getcpuclockid
|
||||||
|
|
|
@ -115,6 +115,7 @@
|
||||||
#undef pthread_detach
|
#undef pthread_detach
|
||||||
#undef pthread_equal
|
#undef pthread_equal
|
||||||
#undef pthread_exit
|
#undef pthread_exit
|
||||||
|
#undef pthread_get_name_np
|
||||||
#undef pthread_getaffinity_np
|
#undef pthread_getaffinity_np
|
||||||
#undef pthread_getconcurrency
|
#undef pthread_getconcurrency
|
||||||
#undef pthread_getcpuclockid
|
#undef pthread_getcpuclockid
|
||||||
|
|
|
@ -321,3 +321,7 @@ FBSD_1.4 {
|
||||||
pthread_mutexattr_getrobust;
|
pthread_mutexattr_getrobust;
|
||||||
pthread_mutexattr_setrobust;
|
pthread_mutexattr_setrobust;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FBSD_1.5 {
|
||||||
|
pthread_get_name_np;
|
||||||
|
};
|
||||||
|
|
|
@ -280,6 +280,9 @@ exit_thread(void)
|
||||||
{
|
{
|
||||||
struct pthread *curthread = _get_curthread();
|
struct pthread *curthread = _get_curthread();
|
||||||
|
|
||||||
|
free(curthread->name);
|
||||||
|
curthread->name = NULL;
|
||||||
|
|
||||||
/* Check if there is thread specific data: */
|
/* Check if there is thread specific data: */
|
||||||
if (curthread->specific != NULL) {
|
if (curthread->specific != NULL) {
|
||||||
/* Run the thread-specific data destructors: */
|
/* Run the thread-specific data destructors: */
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*
|
*
|
||||||
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
|
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
|
||||||
|
* Copyright (c) 2018 The FreeBSD Foundation
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
* Portions of this software were developed by Konstantin Belousov
|
||||||
|
* under sponsorship from the FreeBSD Foundation.
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
|
@ -43,27 +47,65 @@ __FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
__weak_reference(_pthread_set_name_np, pthread_set_name_np);
|
__weak_reference(_pthread_set_name_np, pthread_set_name_np);
|
||||||
|
|
||||||
|
static void
|
||||||
|
thr_set_name_np(struct pthread *thread, const char *name)
|
||||||
|
{
|
||||||
|
|
||||||
|
free(thread->name);
|
||||||
|
thread->name = strdup(name);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the thread name for debug. */
|
/* Set the thread name for debug. */
|
||||||
void
|
void
|
||||||
_pthread_set_name_np(pthread_t thread, const char *name)
|
_pthread_set_name_np(pthread_t thread, const char *name)
|
||||||
{
|
{
|
||||||
struct pthread *curthread = _get_curthread();
|
struct pthread *curthread;
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
|
curthread = _get_curthread();
|
||||||
if (curthread == thread) {
|
if (curthread == thread) {
|
||||||
if (thr_set_name(thread->tid, name))
|
THR_THREAD_LOCK(curthread, thread);
|
||||||
ret = errno;
|
thr_set_name(thread->tid, name);
|
||||||
|
thr_set_name_np(thread, name);
|
||||||
|
THR_THREAD_UNLOCK(curthread, thread);
|
||||||
} else {
|
} else {
|
||||||
if ((ret=_thr_find_thread(curthread, thread, 0)) == 0) {
|
if (_thr_find_thread(curthread, thread, 0) == 0) {
|
||||||
if (thread->state != PS_DEAD) {
|
if (thread->state != PS_DEAD) {
|
||||||
if (thr_set_name(thread->tid, name))
|
thr_set_name(thread->tid, name);
|
||||||
ret = errno;
|
thr_set_name_np(thread, name);
|
||||||
}
|
}
|
||||||
THR_THREAD_UNLOCK(curthread, thread);
|
THR_THREAD_UNLOCK(curthread, thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if 0
|
}
|
||||||
/* XXX should return error code. */
|
|
||||||
return (ret);
|
static void
|
||||||
#endif
|
thr_get_name_np(struct pthread *thread, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (thread->name != NULL)
|
||||||
|
strlcpy(buf, thread->name, len);
|
||||||
|
else if (len > 0)
|
||||||
|
buf[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
__weak_reference(_pthread_get_name_np, pthread_get_name_np);
|
||||||
|
|
||||||
|
void
|
||||||
|
_pthread_get_name_np(pthread_t thread, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
struct pthread *curthread;
|
||||||
|
|
||||||
|
curthread = _get_curthread();
|
||||||
|
if (curthread == thread) {
|
||||||
|
THR_THREAD_LOCK(curthread, thread);
|
||||||
|
thr_get_name_np(thread, buf, len);
|
||||||
|
THR_THREAD_UNLOCK(curthread, thread);
|
||||||
|
} else {
|
||||||
|
if (_thr_find_thread(curthread, thread, 0) == 0) {
|
||||||
|
if (thread->state != PS_DEAD)
|
||||||
|
thr_get_name_np(thread, buf, len);
|
||||||
|
THR_THREAD_UNLOCK(curthread, thread);
|
||||||
|
} else if (len > 0)
|
||||||
|
buf[0] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -572,6 +572,8 @@ struct pthread {
|
||||||
/* Sleep queue */
|
/* Sleep queue */
|
||||||
struct sleepqueue *sleepqueue;
|
struct sleepqueue *sleepqueue;
|
||||||
|
|
||||||
|
/* pthread_set/get_name_np */
|
||||||
|
char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define THR_SHOULD_GC(thrd) \
|
#define THR_SHOULD_GC(thrd) \
|
||||||
|
|
|
@ -334,6 +334,7 @@ PTHREAD_MLINKS+=pthread_rwlock_rdlock.3 pthread_rwlock_tryrdlock.3
|
||||||
PTHREAD_MLINKS+=pthread_rwlock_wrlock.3 pthread_rwlock_trywrlock.3
|
PTHREAD_MLINKS+=pthread_rwlock_wrlock.3 pthread_rwlock_trywrlock.3
|
||||||
PTHREAD_MLINKS+=pthread_schedparam.3 pthread_getschedparam.3 \
|
PTHREAD_MLINKS+=pthread_schedparam.3 pthread_getschedparam.3 \
|
||||||
pthread_schedparam.3 pthread_setschedparam.3
|
pthread_schedparam.3 pthread_setschedparam.3
|
||||||
|
PTHREAD_MLINKS+=pthread_set_name_np.3 pthread_get_name_np.3
|
||||||
PTHREAD_MLINKS+=pthread_spin_init.3 pthread_spin_destroy.3 \
|
PTHREAD_MLINKS+=pthread_spin_init.3 pthread_spin_destroy.3 \
|
||||||
pthread_spin_lock.3 pthread_spin_trylock.3 \
|
pthread_spin_lock.3 pthread_spin_trylock.3 \
|
||||||
pthread_spin_lock.3 pthread_spin_unlock.3
|
pthread_spin_lock.3 pthread_spin_unlock.3
|
||||||
|
|
|
@ -24,17 +24,20 @@
|
||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd December 2, 2016
|
.Dd August 12, 2018
|
||||||
.Dt PTHREAD_SET_NAME_NP 3
|
.Dt PTHREAD_SET_NAME_NP 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
.Nm pthread_get_name_np ,
|
||||||
.Nm pthread_set_name_np
|
.Nm pthread_set_name_np
|
||||||
.Nd set the thread name
|
.Nd set and retrieve the thread name
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.Lb libpthread
|
.Lb libpthread
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In pthread_np.h
|
.In pthread_np.h
|
||||||
.Ft void
|
.Ft void
|
||||||
|
.Fn pthread_get_name_np "pthread_t thread" "char *name" "size_t len"
|
||||||
|
.Ft void
|
||||||
.Fn pthread_set_name_np "pthread_t thread" "const char *name"
|
.Fn pthread_set_name_np "pthread_t thread" "const char *name"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
|
@ -43,11 +46,32 @@ function applies a copy of the given
|
||||||
.Fa name
|
.Fa name
|
||||||
to the given
|
to the given
|
||||||
.Fa thread .
|
.Fa thread .
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn pthread_get_name_np
|
||||||
|
function retrieves the
|
||||||
|
.Fa name
|
||||||
|
associated with
|
||||||
|
.Fa thread .
|
||||||
|
If
|
||||||
|
.Fn pthread_set_name_np
|
||||||
|
was not previously called for
|
||||||
|
.Fa thread ,
|
||||||
|
the buffer pointed to by
|
||||||
|
.Fa name
|
||||||
|
will be empty.
|
||||||
.Sh ERRORS
|
.Sh ERRORS
|
||||||
Because of the debugging nature of this function, all errors that may
|
Because of the debugging nature of these functions, all errors that may
|
||||||
appear inside are silently ignored.
|
appear inside are silently ignored.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr thr_set_name 2
|
.Xr thr_set_name 2
|
||||||
|
.Sh STANDARDS
|
||||||
|
.Fn pthread_set_name_np
|
||||||
|
and
|
||||||
|
.Fn pthread_get_name_np
|
||||||
|
are non-standard extensions.
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
This manual page was written by
|
This manual page was written by
|
||||||
.An Alexey Zelkin Aq Mt phantom@FreeBSD.org .
|
.An Alexey Zelkin Aq Mt phantom@FreeBSD.org
|
||||||
|
and
|
||||||
|
An Yuri Pankov Aq Mt yuripv@yuripv.net .
|
||||||
|
|
Loading…
Reference in a new issue