From 7c49927911badda7907703568cadbcb2f1b7ef9d Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 12 Jan 2017 09:26:08 +0100 Subject: posix: Add pthread_getname_np(), ... Add pthread_getname_np() and pthread_setname_np(). Update #2858. --- cpukit/posix/Makefile.am | 2 ++ cpukit/posix/src/pthreadgetnamenp.c | 44 +++++++++++++++++++++++++++++++++++++ cpukit/posix/src/pthreadsetnamenp.c | 38 ++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 cpukit/posix/src/pthreadgetnamenp.c create mode 100644 cpukit/posix/src/pthreadsetnamenp.c (limited to 'cpukit/posix') diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am index d9a3437b13..9cc10438da 100644 --- a/cpukit/posix/Makefile.am +++ b/cpukit/posix/Makefile.am @@ -65,6 +65,8 @@ endif libposix_a_SOURCES += src/fork.c src/vfork.c libposix_a_SOURCES += src/wait.c src/waitpid.c +libposix_a_SOURCES += src/pthreadgetnamenp.c +libposix_a_SOURCES += src/pthreadsetnamenp.c if HAS_PTHREADS libposix_a_SOURCES += src/pthreadatfork.c diff --git a/cpukit/posix/src/pthreadgetnamenp.c b/cpukit/posix/src/pthreadgetnamenp.c new file mode 100644 index 0000000000..e753823976 --- /dev/null +++ b/cpukit/posix/src/pthreadgetnamenp.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 embedded brains GmbH. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#define _GNU_SOURCE +#include +#include +#include + +#include + +int pthread_getname_np( pthread_t thread, char *name, size_t len ) +{ + Thread_Control *the_thread; + ISR_lock_Context lock_context; + size_t actual_len; + + _Objects_Allocator_lock(); + the_thread = _Thread_Get( thread, &lock_context ); + + if ( the_thread == NULL ) { + _Objects_Allocator_unlock(); + strlcpy(name, "", len); + return ESRCH; + } + + _ISR_lock_ISR_enable( &lock_context ); + actual_len = _Thread_Get_name( the_thread, name, len ); + _Objects_Allocator_unlock(); + + if ( actual_len >= len ) { + return ERANGE; + } + + return 0; +} diff --git a/cpukit/posix/src/pthreadsetnamenp.c b/cpukit/posix/src/pthreadsetnamenp.c new file mode 100644 index 0000000000..cb0e47ce94 --- /dev/null +++ b/cpukit/posix/src/pthreadsetnamenp.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017 embedded brains GmbH. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#define _GNU_SOURCE +#include +#include + +#include +#include + +int pthread_setname_np( pthread_t thread, const char *name ) +{ + Thread_Control *the_thread; + ISR_lock_Context lock_context; + Status_Control status; + + _Objects_Allocator_lock(); + the_thread = _Thread_Get( thread, &lock_context ); + + if ( the_thread == NULL ) { + _Objects_Allocator_unlock(); + return ESRCH; + } + + _ISR_lock_ISR_enable( &lock_context ); + status = _Thread_Set_name( the_thread, name ); + _Objects_Allocator_unlock(); + return _POSIX_Get_error( status ); +} -- cgit v1.2.3