Index: pjproject/branches/projects/winphone/pjlib/src/pj/os_core_win32.c
===================================================================
--- pjproject/branches/projects/winphone/pjlib/src/pj/os_core_win32.c	(revision 4618)
+++ pjproject/branches/projects/winphone/pjlib/src/pj/os_core_win32.c	(revision 4777)
@@ -39,6 +39,6 @@
 #endif
 
-#if PJ_WIN32_WINPHONE
-#   include "../../third_party/threademulation/include/ThreadEmulation.h"
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+#   include "../../../third_party/threademulation/include/ThreadEmulation.h"
 #endif
 
@@ -306,5 +306,5 @@
 PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread)
 {
-#if PJ_WIN32_WINPHONE
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
     PJ_UNUSED_ARG(thread);
     return -1;
@@ -326,5 +326,9 @@
 		     PJ_EINVAL);
 
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+    if (SetThreadPriorityRT(thread->hthread, prio) == FALSE)
+#else
     if (SetThreadPriority(thread->hthread, prio) == FALSE)
+#endif
 	return PJ_RETURN_OS_ERROR(GetLastError());
 
@@ -487,4 +491,8 @@
     pj_thread_t *rec;
 
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+    PJ_UNUSED_ARG(stack_size);
+#endif
+
     PJ_CHECK_STACK();
     PJ_ASSERT_RETURN(pool && proc && thread_ptr, PJ_EINVAL);
@@ -521,8 +529,8 @@
     rec->arg = arg;
 
-#ifdef PJ_WIN32_WINPHONE
-    rec->hthread = CreateThread(NULL, stack_size, 
-				thread_main, rec,
-				dwflags, NULL);
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+    rec->hthread = CreateThreadRT(NULL, 0, 
+				  thread_main, rec,
+				  dwflags, NULL);
 #else
     rec->hthread = CreateThread(NULL, stack_size, 
@@ -562,5 +570,9 @@
     PJ_ASSERT_RETURN(p, PJ_EINVAL);
 
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+    if (ResumeThreadRT(rec->hthread) == (DWORD)-1)
+#else
     if (ResumeThread(rec->hthread) == (DWORD)-1)
+#endif
         return PJ_RETURN_OS_ERROR(GetLastError());
     else
@@ -606,5 +618,5 @@
     PJ_LOG(6, (pj_thread_this()->obj_name, "Joining thread %s", p->obj_name));
 
-#if PJ_WIN32_WINPHONE
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
     rc = WaitForSingleObjectEx(rec->hthread, INFINITE, FALSE);
 #else
@@ -642,5 +654,9 @@
 {
     PJ_CHECK_STACK();
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+    SleepRT(msec);
+#else
     Sleep(msec);
+#endif
     return PJ_SUCCESS;
 }
@@ -836,5 +852,9 @@
     //PJ_CHECK_STACK();
 
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+    *index = TlsAllocRT();
+#else
     *index = TlsAlloc();
+#endif
 
     if (*index == TLS_OUT_OF_INDEXES)
@@ -850,5 +870,9 @@
 {
     PJ_CHECK_STACK();
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+    TlsFreeRT(index);
+#else
     TlsFree(index);
+#endif
 }
 
@@ -863,5 +887,9 @@
     //beginning before main thread is initialized.
     //PJ_CHECK_STACK();
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+    rc = TlsSetValueRT(index, value);
+#else
     rc = TlsSetValue(index, value);
+#endif
     return rc!=0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(GetLastError());
 }
@@ -875,5 +903,9 @@
     //by PJ_CHECK_STACK() itself!!!
     //PJ_CHECK_STACK();
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
+    return TlsGetValueRT(index);
+#else
     return TlsGetValue(index);
+#endif
 }
 
@@ -884,5 +916,5 @@
     PJ_CHECK_STACK();
 
-#if PJ_WIN32_WINPHONE
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
     InitializeCriticalSectionEx(&mutex->crit, 0, 0);
 #elif PJ_WIN32_WINNT >= 0x0400
@@ -1140,5 +1172,5 @@
 
     sem = pj_pool_alloc(pool, sizeof(*sem)); 
-#if PJ_WIN32_WINPHONE
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
     /** SEMAPHORE_ALL_ACCESS **/
     sem->hSemaphore = CreateSemaphoreEx(NULL, initial, max, NULL, 0, 
@@ -1177,5 +1209,5 @@
 			      pj_thread_this()->obj_name));
 
-#if PJ_WIN32_WINPHONE
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
     result = WaitForSingleObjectEx(sem->hSemaphore, timeout, FALSE);
 #else
@@ -1279,5 +1311,5 @@
         return PJ_ENOMEM;
 
-#if PJ_WIN32_WINPHONE
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
     event->hEvent = CreateEventEx(NULL, NULL, 
 				  (manual_reset?0x1:0x0)|(initial?0x2:0x0), 
@@ -1318,5 +1350,5 @@
 			        pj_thread_this()->obj_name));
 
-#if PJ_WIN32_WINPHONE
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
     result = WaitForSingleObjectEx(event->hEvent, timeout, FALSE);
 #else
@@ -1380,5 +1412,5 @@
 PJ_DEF(pj_status_t) pj_event_pulse(pj_event_t *event)
 {
-#ifdef PJ_WIN32_WINPHONE
+#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
     PJ_UNUSED_ARG(event);
     pj_assert(!"pj_event_pulse() not supported!");
