This is the mail archive of the cygwin-patches mailing list for the Cygwin project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
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
Attachment:
signature.asc
Description: PGP signature
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |