Bug 64316 - Duplicate code for obtaining native current thread id
Summary: Duplicate code for obtaining native current thread id
Status: RESOLVED FIXED
Alias: None
Product: Tomcat Native
Classification: Unclassified
Component: Library (show other bugs)
Version: 1.2.23
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-06 13:26 UTC by Michael Osipov
Modified: 2020-04-26 09:29 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Osipov 2020-04-06 13:26:08 UTC
We can improve/reduce code by collapsing those two into one internal function:

src/thread.c:
> TCN_IMPLEMENT_CALL(jlong, Thread, current)(TCN_STDARGS)
> {
>     UNREFERENCED_STDARGS;
>     return (jlong)((unsigned long)apr_os_thread_current());
> }

and src/ssl.c:
> static unsigned long ssl_thread_id(void)
> {
>     /* OpenSSL needs this to return an unsigned long.  On OS/390, the pthread
>      * id is a structure twice that big.  Use the TCB pointer instead as a
>      * unique unsigned long.
>      */
> #ifdef __MVS__
>     struct PSA {
>         char unmapped[540];
>         unsigned long PSATOLD;
>     } *psaptr = 0;
> 
>     return psaptr->PSATOLD;
> #elif defined(WIN32)
>     return (unsigned long)GetCurrentThreadId();
> #elif defined(DARWIN)
>     uint64_t tid;
>     pthread_threadid_np(NULL, &tid);
>     return (unsigned long)tid;
> #elif defined(__FreeBSD__)
>     return (unsigned long)pthread_getthreadid_np();
> #elif defined(__linux__)
>     return (unsigned long)syscall(SYS_gettid);
> #else
>     return (unsigned long)(apr_os_thread_current());
> #endif
> }

I think that we can throw away the apr_os_thread_current() because we already have the thread id for Windows and for Unix is it merely:
> APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
> {
>     return pthread_self();
> }

There are implementations for BeOS, Netware and OS/2, but we don't care for them.
Comment 1 Michael Osipov 2020-04-26 09:29:04 UTC
Fixed in:
- master for 1.2.24 onwards