pthread: add setname/getname glibc extensions

Adding the ability to set and get pthread names by defining
some non-standard extension functions that were first
introduced by Glibc.

Similar to zephyr thread naming, these allow for thread
tracking and debugging even when using the more portable
posix API.

Though Glibc was the originator, the current POSIX functions
have return codes based on Oracle's adopted spec, so these
functions follow suit.  The Oracle and Glibc function
prototypes match.

Signed-off-by: Nicholas Lowell <nlowell@lexmark.com>
This commit is contained in:
Nicholas Lowell 2020-02-14 15:12:03 -05:00 committed by Johan Hedberg
commit 17b19eb810
4 changed files with 114 additions and 0 deletions

View file

@ -522,6 +522,41 @@ int pthread_key_delete(pthread_key_t key);
int pthread_setspecific(pthread_key_t key, const void *value);
void *pthread_getspecific(pthread_key_t key);
/* Glibc / Oracle Extension Functions */
/**
* @brief Set name of POSIX thread.
*
* Non-portable, extension function that conforms with most
* other definitions of this function.
*
* @param thread POSIX thread to set name
* @param name Name string
* @retval 0 Success
* @retval ESRCH Thread does not exist
* @retval EINVAL Name buffer is NULL
* @retval Negative value if kernel function error
*
*/
int pthread_setname_np(pthread_t thread, const char *name);
/**
* @brief Get name of POSIX thread and store in name buffer
* that is of size len.
*
* Non-portable, extension function that conforms with most
* other definitions of this function.
*
* @param thread POSIX thread to obtain name information
* @param name Destination buffer
* @param len Destination buffer size
* @retval 0 Success
* @retval ESRCH Thread does not exist
* @retval EINVAL Name buffer is NULL
* @retval Negative value if kernel function error
*/
int pthread_getname_np(pthread_t thread, char *name, size_t len);
#ifdef __cplusplus
}
#endif