-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Michael,
On 4/23/20 18:42, micha...@apache.org wrote: > This is an automated email from the ASF dual-hosted git > repository. > > michaelo pushed a commit to branch master in repository > https://gitbox.apache.org/repos/asf/tomcat-native.git > > > The following commit(s) were added to refs/heads/master by this > push: new f95f531 Introduce tcn_get_thread_id(void) to reduce code > duplication f95f531 is described below > > commit f95f531e98278cc7555367084b967e3550734559 Author: Michael > Osipov <micha...@apache.org> AuthorDate: Thu Apr 23 18:52:44 2020 > +0200 > > Introduce tcn_get_thread_id(void) to reduce code duplication > > At two spots (ssl.c and thread.c) we need to obtain the native > thread id. This has been done with two different approaches. Move > out to tcn_get_thread(void) which uses the previous > ssl_thread_id(void) implementation while the previous functions > delegate to the new one. apr_os_thread_current(void) is not used > anymore which does internally the same thing as > ssl_thread_id(void) was doing. > > Also add properly #ifdefs for Windows and macOS for function > prototype includes. --- native/include/tcn.h | 1 + > native/src/jnilib.c | 45 > +++++++++++++++++++++++++++++++++++++++ native/src/ssl.c > | 33 +--------------------------- native/src/thread.c > | 3 ++- xdocs/miscellaneous/changelog.xml | 5 ++++- 5 files > changed, 53 insertions(+), 34 deletions(-) > > diff --git a/native/include/tcn.h b/native/include/tcn.h index > 2b2ae59..d2f316b 100644 --- a/native/include/tcn.h +++ > b/native/include/tcn.h @@ -175,6 +175,7 @@ char > *tcn_strdup(JNIEnv *, jstring); char *tcn_pstrdup(JNIEnv > *, jstring, apr_pool_t *); apr_status_t > tcn_load_finfo_class(JNIEnv *, jclass); apr_status_t > tcn_load_ainfo_class(JNIEnv *, jclass); +unsigned long > tcn_get_thread_id(void); > > #define J2S(V) c##V #define J2L(V) p##V diff --git > a/native/src/jnilib.c b/native/src/jnilib.c index dae3ade..e88d4d5 > 100644 --- a/native/src/jnilib.c +++ b/native/src/jnilib.c @@ -23,6 > +23,22 @@ > > #include "tcn_version.h" > > +#ifdef WIN32 +#include <Windows.h> +#endif + +#ifdef DARWIN > +#include <pthread.h> +#endif + +#ifdef __FreeBSD__ +#include > <pthread_np.h> +#endif + +#ifdef __linux__ +#include > <sys/syscall.h> +#endif + #ifdef TCN_DO_STATISTICS extern void > sp_poll_dump_statistics(); extern void > sp_network_dump_statistics(); @@ -481,3 +497,32 @@ jint > tcn_get_java_env(JNIEnv **env) } return JNI_OK; } + +unsigned long > tcn_get_thread_id(void) Why not simple call apr_os_thread_current() instead of writing a new function? Or is the intention to get away from using APR? > +{ + /* 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; I think we might want to put the above #ifdef as the LAST one in the list. I think if we can call pthread_self, we should, even if this other technique will work. > +#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)pthread_self(); +#endif Can we guarantee that pthread_self() will be available "by default" since it's predicate-less, here? I wasn't able to quickly find a reference for how to check for pthreads. Maybe #ifdef(_PTHREAD_H)? - -chris -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/ iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl6jEmQACgkQHPApP6U8 pFjvjw/+NcylTnzG4+0N3NulBBv/2dhZPKJJjeH5vkw519CDXUikcy6ObTKZ58XZ 6PFnG6t7KCWAU87IODWV+qPR1sg4sUyhqWi2eC1djN97KpZFkE0lMhyV+gKelMFM wOmRHB6tow1hI6hHkmssX5udGsPWZvKjJYBCiNCaKto7VwQS8tiSy3S8za2RMFnz UJNmi5iirMNRncuIzUhrpK0n49xNWqSLBYjnk9d1jcVKwSydA0oVz3SgKumscnH+ Exakdk/XvDtwTXQLKaIA9S0OvRbj44bCkiuM4Yrc8s0uF3H3tcRAmpv5ADX4IRjn dU0imx8jEZK/SOHP95TeejNcjAocWUPMvQZ0LTTVhn4Ld4qA+TtD8h0IODMdkt4E E+fb1HfYySlRAgASUNEBUKl57t3uRTyQcC2fmjjvWvc4ZqY8QKFVdnFNWIiSylE+ 3xA1ORoNNU35F4RMnqZFSLkkRvulNew8hl/YBNyxPcANhWBe8BTK5amfdGqsdOed KTwpp6o58FzCKs6GSowkWSRClaqqITmtE8kQOo0+ecqKZclW6OLqExTNcS4a9At3 uaYpT2Tt89Ul9WZ4XdE6X1d1hFN4Mg8vsCaO86rTvOlnJaLs9CKsKX4uRuOmgMGY h9qlkKIM1PRPuzGLLkxs+jWnyPRQX2jTO1N5wcUPjqsbEdoH074= =LLLb -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org