Ticket #417: added pjlib API to retrieve the native thread handle from pj_thread_t

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1589 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/include/pj/os.h b/pjlib/include/pj/os.h
index 3529c46..f640df2 100644
--- a/pjlib/include/pj/os.h
+++ b/pjlib/include/pj/os.h
@@ -138,6 +138,19 @@
 
 
 /**
+ * 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.
  *
  * @param thread    The thread handle.
diff --git a/pjlib/src/pj/os_core_symbian.cpp b/pjlib/src/pj/os_core_symbian.cpp
index 8f96ce0..f656cb6 100644
--- a/pjlib/src/pj/os_core_symbian.cpp
+++ b/pjlib/src/pj/os_core_symbian.cpp
@@ -447,6 +447,23 @@
 
 
 /*
+ * 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(..)
  */
 PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,
diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c
index e901036..5a246df 100644
--- a/pjlib/src/pj/os_core_unix.c
+++ b/pjlib/src/pj/os_core_unix.c
@@ -238,6 +238,20 @@
 #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 b9484ff..fcacaf4 100644
--- a/pjlib/src/pj/os_core_win32.c
+++ b/pjlib/src/pj/os_core_win32.c
@@ -245,6 +245,21 @@
 }
 
 /*
+ * 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(..)
  */
 PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name,