[PATCH] Define internal function mythreadname()
Corinna Vinschen
corinna-cygwin@cygwin.com
Tue Jan 23 10:56:00 GMT 2018
Hi Mark,
On Jan 22 21:21, Mark Geisert wrote:
> This new function returns the name of the calling thread; works for both
> cygthreads and pthreads. All calls to cygthread::name(/*void*/) replaced by
> calls to mythreadname(/*void*/).
> [...]
> diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
> index f3c709a15..71e17a77f 100644
> --- a/winsup/cygwin/thread.cc
> +++ b/winsup/cygwin/thread.cc
> @@ -2682,6 +2682,23 @@ pthread_setname_np (pthread_t thread, const char *name)
> return 0;
> }
>
> +/* Returns running thread's name; works for both cygthreads and pthreads */
> +extern "C" const char *
You can drop the extern "C", the function is used in C++ context only
anyway.
> +mythreadname (void)
> +{
> + const char *result = cygthread::name ();
> +
> + if (strstr (result, "unknown "))
This test is a bit wasteful. What about checking result ==
_my_tls.locals.unknown_thread_name instead?
> + {
> + static char tname[THRNAMELEN];
Ouch. This isn't thread safe. Why don't you just use
_my_tls.locals.unknown_thread_name, just like cygthread::name()?
> +
> + tname[0] = '\0';
> + if (0 == pthread_getname_np (pthread_self (), tname, sizeof (tname)))
> + result = tname;
> + }
> +
> + return result;
> +}
> #undef THRNAMELEN
>
> /* provided for source level compatability.
> diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h
> index 12a9ef26d..60277c601 100644
> --- a/winsup/cygwin/thread.h
> +++ b/winsup/cygwin/thread.h
> @@ -17,6 +17,9 @@ details. */
> /* resource.cc */
> extern size_t get_rlimit_stack (void);
>
> +/* thread.cc */
> +extern "C" const char *mythreadname (void);
^^^^^^^^^^
as above.
> +
> #include <pthread.h>
> #include <limits.h>
> #include "security.h"
> --
> 2.15.1
Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20180123/e39a65c3/attachment.sig>
More information about the Cygwin-patches
mailing list