On Tue, Jun 28, 2022 at 8:06 PM Ivan Zhakov <i...@visualsvn.com> wrote: > > On Tue, 28 Jun 2022 at 14:45, Yann Ylavic <ylavic....@gmail.com> wrote: > > > > On Tue, Jun 28, 2022 at 1:13 AM <i...@apache.org> wrote: > > > > > > Author: ivan > > > Date: Mon Jun 27 23:13:52 2022 > > > New Revision: 1902297 > > > > > > URL: http://svn.apache.org/viewvc?rev=1902297&view=rev > > > Log: > > > On 'thread-name' branch: Add apr_thread_name_get() and > > > apr_thread_name_set() > > > API to get/set thread name. > > > > > [] > > > --- apr/apr/branches/thread-name/threadproc/unix/thread.c (original) > > > +++ apr/apr/branches/thread-name/threadproc/unix/thread.c Mon Jun 27 > > > 23:13:52 2022 > > [] > > > @@ -277,6 +282,48 @@ APR_DECLARE(apr_thread_t *) apr_thread_c > > > #endif > > > } > > > > > > +APR_DECLARE(apr_status_t) apr_thread_name_set(const char *name, > > > + apr_thread_t *thread, > > > + apr_pool_t *pool) > > > +{ > > > + pthread_t td; > > > + > > > + size_t name_len; > > > + if (!name) { > > > + return APR_BADARG; > > > + } > > > + > > > + if (thread) { > > > + td = *thread->td; > > > + } > > > + else { > > > + td = pthread_self(); > > > + } > > > + > > > + name_len = strlen(name); > > > + if (name_len >= TASK_COMM_LEN) { > > > + name = name + name_len - TASK_COMM_LEN + 1; > > > + } > > > + > > > + return pthread_setname_np(td, name); > > > > We probably need to check for HAVE_PTHREAD_SETNAME_NP since it's _np > > (non-portable). > Thanks for the suggestion! > > I'm not so familiar with autoconf stuff (that's why I created branch): > can I just check for HAVE_PTHREAD_SETNAME_NP or do I need some > autoconf magic to set it?
Maybe something like the attached patch, and then check for HAVE_PTHREAD_GETNAME_SETNAME_NP for both functions (which pair anyway). Regards; Yann.
Index: configure.in =================================================================== --- configure.in (revision 1902267) +++ configure.in (working copy) @@ -2401,11 +2401,16 @@ APR_CHECK_DEFINE(SEM_UNDO, sys/sem.h) APR_CHECK_DEFINE_FILES(POLLIN, poll.h sys/poll.h) if test "$threads" = "1"; then + AC_CHECK_HEADERS([pthread.h]) APR_CHECK_DEFINE(PTHREAD_PROCESS_SHARED, pthread.h) - AC_CHECK_FUNCS(pthread_mutex_timedlock pthread_mutexattr_setpshared) + AC_CHECK_FUNCS(pthread_mutex_timedlock pthread_mutexattr_setpshared dnl + pthread_getname_np pthread_setname_np) APR_IFALLYES(header:pthread.h func:pthread_mutex_timedlock, have_pthread_mutex_timedlock="1", have_pthread_mutex_timedlock="0") AC_SUBST(have_pthread_mutex_timedlock) + APR_IFALLYES(header:pthread.h func:pthread_getname_np func:pthread_setname_np, + have_pthread_getname_setname_np="1", have_pthread_getname_setname_np="0") + AC_SUBST(have_pthread_getname_setname_np) # Some systems have setpshared and define PROCESS_SHARED, but don't # really support PROCESS_SHARED locks. So, we must validate that we # can go through the steps without receiving some sort of system error.