From 5931dc59c08af2cf1f23518f700e9107effa9e59 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 21 Nov 2007 14:12:01 +0000 Subject: Ticket #417: added pjlib API to retrieve the native thread handle from pj_thread_t git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1589 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/include/pj/os.h | 13 +++++++++++++ pjlib/src/pj/os_core_symbian.cpp | 17 +++++++++++++++++ pjlib/src/pj/os_core_unix.c | 14 ++++++++++++++ pjlib/src/pj/os_core_win32.c | 15 +++++++++++++++ 4 files changed, 59 insertions(+) (limited to 'pjlib') diff --git a/pjlib/include/pj/os.h b/pjlib/include/pj/os.h index 3529c463..f640df21 100644 --- a/pjlib/include/pj/os.h +++ b/pjlib/include/pj/os.h @@ -137,6 +137,19 @@ PJ_DECL(pj_status_t) pj_thread_register ( const char *thread_name, PJ_DECL(pj_bool_t) pj_thread_is_registered(void); +/** + * Return native handle from pj_thread_t for manipulation using native + * OS APIs. + * + * @param thread PJLIB thread descriptor. + * + * @return Native thread handle. For example, when the + * backend thread uses pthread, this function will + * return pointer to pthread_t, and on Windows, + * this function will return HANDLE. + */ +PJ_DECL(void*) pj_thread_get_os_handle(pj_thread_t *thread); + /** * Get thread name. * diff --git a/pjlib/src/pj/os_core_symbian.cpp b/pjlib/src/pj/os_core_symbian.cpp index 8f96ce09..f656cb68 100644 --- a/pjlib/src/pj/os_core_symbian.cpp +++ b/pjlib/src/pj/os_core_symbian.cpp @@ -446,6 +446,23 @@ PJ_DEF(pj_bool_t) pj_symbianos_poll(int priority, int ms_timeout) } +/* + * pj_thread_is_registered() + */ +PJ_DEF(pj_bool_t) pj_thread_is_registered(void) +{ + return PJ_FALSE; +} + +/* + * pj_thread_get_os_handle() + */ +PJ_DEF(void*) pj_thread_get_os_handle(pj_thread_t *thread) +{ + PJ_UNUSED_ARG(thread); + return NULL; +} + /* * pj_thread_register(..) */ diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c index e901036a..5a246df5 100644 --- a/pjlib/src/pj/os_core_unix.c +++ b/pjlib/src/pj/os_core_unix.c @@ -238,6 +238,20 @@ PJ_DEF(pj_bool_t) pj_thread_is_registered(void) #endif } +/* + * Get native thread handle + */ +PJ_DEF(void*) pj_thread_get_os_handle(pj_thread_t *thread) +{ + PJ_ASSERT_RETURN(thread, NULL); + +#if PJ_HAS_THREADS + return &thread->thread; +#else + pj_assert("pj_thread_is_registered() called in non-threading mode!"); + return NULL; +#endif +} /* * pj_thread_register(..) diff --git a/pjlib/src/pj/os_core_win32.c b/pjlib/src/pj/os_core_win32.c index b9484ff5..fcacaf4b 100644 --- a/pjlib/src/pj/os_core_win32.c +++ b/pjlib/src/pj/os_core_win32.c @@ -244,6 +244,21 @@ PJ_DEF(pj_bool_t) pj_thread_is_registered(void) return pj_thread_local_get(thread_tls_id) != 0; } +/* + * Get native thread handle + */ +PJ_DEF(void*) pj_thread_get_os_handle(pj_thread_t *thread) +{ + PJ_ASSERT_RETURN(thread, NULL); + +#if PJ_HAS_THREADS + return thread->hthread; +#else + pj_assert("pj_thread_is_registered() called in non-threading mode!"); + return NULL; +#endif +} + /* * pj_thread_register(..) */ -- cgit v1.2.3