Index: pjproject/main/pjlib/src/pj/os_core_unix.c
===================================================================
--- pjproject/main/pjlib/src/pj/os_core_unix.c	(revision 1)
+++ pjproject/main/pjlib/src/pj/os_core_unix.c	(revision 3)
@@ -1,15 +1,3 @@
-/* $Header: /pjproject-0.3/pjlib/src/pj/os_core_unix.c 11    10/29/05 10:27p Bennylp $ */
-/* 
- * $Log: /pjproject-0.3/pjlib/src/pj/os_core_unix.c $ 
- * 
- * 11    10/29/05 10:27p Bennylp
- * Fixed misc warnings.
- * 
- * 10    10/29/05 11:51a Bennylp
- * Version 0.3-pre2.
- * 
- * 9     10/14/05 12:26a Bennylp
- * Finished error code framework, some fixes in ioqueue, etc. Pretty
- * major.
+/* $Id$
  *
  */
@@ -33,4 +21,7 @@
 
 #define __USE_GNU
+//uncomment this to get pthread_mutexattr_settype declaration.
+//unfortunately this causes syntax error in pthread.h! :(
+//#define __USE_UNIX98
 #include <pthread.h>
 
@@ -175,4 +166,5 @@
 #if PJ_HAS_THREADS
     char stack_ptr;
+    pj_status_t rc;
     pj_thread_t *thread = (pj_thread_t *)desc;
     pj_str_t thread_name = pj_str((char*)cstr_thread_name);
@@ -191,5 +183,5 @@
 
     /* Initialize and set the thread entry. */
-    pj_memset(desc, 0, sizeof(pj_thread_desc));
+    pj_memset(desc, 0, sizeof(struct pj_thread_t));
     thread->thread = pthread_self();
 
@@ -199,5 +191,7 @@
 	pj_sprintf(thread->obj_name, "thr%p", (void*)thread->thread);
     
-    pj_thread_local_set(thread_tls_id, thread);
+    rc = pj_thread_local_set(thread_tls_id, thread);
+    if (rc != PJ_SUCCESS)
+	return rc;
 
 #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
@@ -214,5 +208,5 @@
     pj_thread_t *thread = (pj_thread_t*)desc;
     *ptr_thread = thread;
-    return SUCCESS;
+    return PJ_SUCCESS;
 #endif
 }
@@ -231,5 +225,5 @@
 	return rc;
     }
-    return pj_thread_register("thr%p", (pj_uint8_t*)&main_thread, &dummy);
+    return pj_thread_register("thr%p", (long*)&main_thread, &dummy);
 #else
     PJ_LOG(2,(THIS_FILE, "Thread init error. Threading is not enabled!"));
@@ -248,4 +242,5 @@
     pj_thread_t *rec = param;
     void *result;
+    pj_status_t rc;
 
 #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0
@@ -254,5 +249,8 @@
 
     /* Set current thread id. */
-    pj_thread_local_set(thread_tls_id, rec);
+    rc = pj_thread_local_set(thread_tls_id, rec);
+    if (rc != PJ_SUCCESS) {
+	pj_assert(!"Thread TLS ID is not set (pj_init() error?)");
+    }
 
     /* Check if suspension is required. */
@@ -660,5 +658,5 @@
  * pj_thread_local_set()
  */
-PJ_DEF(void) pj_thread_local_set(long index, void *value)
+PJ_DEF(pj_status_t) pj_thread_local_set(long index, void *value)
 {
     //Can't check stack because this function is called in the
@@ -666,8 +664,10 @@
     //PJ_CHECK_STACK();
 #if PJ_HAS_THREADS
-    pthread_setspecific(index, value);
+    int rc=pthread_setspecific(index, value);
+    return rc==0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(rc);
 #else
     pj_assert(index >= 0 && index < MAX_THREADS);
     tls[index] = value;
+    return PJ_SUCCESS;
 #endif
 }
@@ -706,14 +706,32 @@
 {
 #if PJ_HAS_THREADS
-    PJ_UNUSED_ARG(type);
-
-    PJ_CHECK_STACK();
+    pthread_mutexattr_t attr;
+    int rc;
+
+    PJ_CHECK_STACK();
+
+    pthread_mutexattr_init(&attr);
 
     if (type == PJ_MUTEX_SIMPLE) {
-	pthread_mutex_t the_mutex = PTHREAD_MUTEX_INITIALIZER;
-	mutex->mutex = the_mutex;
+#if defined(PJ_LINUX) && PJ_LINUX!=0
+	rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP);
+#else
+	rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
+#endif
     } else {
-	pthread_mutex_t the_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-	mutex->mutex = the_mutex;
+#if defined(PJ_LINUX) && PJ_LINUX!=0
+	rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
+#else
+	rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+#endif
+    }
+    
+    if (rc != 0) {
+	return PJ_RETURN_OS_ERROR(rc);
+    }
+
+    rc = pthread_mutex_init(&mutex->mutex, &attr);
+    if (rc != 0) {
+	return PJ_RETURN_OS_ERROR(rc);
     }
     
