Index: pjproject/branches/projects/uwp/pjlib/src/pj/os_core_win32.c
===================================================================
--- pjproject/branches/projects/uwp/pjlib/src/pj/os_core_win32.c	(revision 5208)
+++ pjproject/branches/projects/uwp/pjlib/src/pj/os_core_win32.c	(revision 5210)
@@ -39,4 +39,8 @@
 #endif
 
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+#   include "../../../third_party/threademulation/include/ThreadEmulation.h"
+#endif
+
 /* Activate mutex related logging if PJ_DEBUG_MUTEX is set, otherwise
  * use default level 6 logging.
@@ -298,5 +302,10 @@
 PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread)
 {
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    PJ_UNUSED_ARG(thread);
+    return -1;
+#else
     return GetThreadPriority(thread->hthread);
+#endif
 }
 
@@ -313,5 +322,9 @@
 		     PJ_EINVAL);
 
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    if (SetThreadPriorityRT(thread->hthread, prio) == FALSE)
+#else
     if (SetThreadPriority(thread->hthread, prio) == FALSE)
+#endif
 	return PJ_RETURN_OS_ERROR(GetLastError());
 
@@ -474,4 +487,8 @@
     pj_thread_t *rec;
 
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    PJ_UNUSED_ARG(stack_size);
+#endif
+
     PJ_CHECK_STACK();
     PJ_ASSERT_RETURN(pool && proc && thread_ptr, PJ_EINVAL);
@@ -507,7 +524,15 @@
     rec->proc = proc;
     rec->arg = arg;
-    rec->hthread = CreateThread(NULL, stack_size, 
-				thread_main, rec,
-				dwflags, &rec->idthread);
+
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    rec->hthread = CreateThreadRT(NULL, 0,
+				  thread_main, rec,
+				  dwflags, NULL);
+#else
+    rec->hthread = CreateThread(NULL, stack_size,
+			        thread_main, rec,
+			        dwflags, &rec->idthread);
+#endif
+
     if (rec->hthread == NULL)
 	return PJ_RETURN_OS_ERROR(GetLastError());
@@ -541,5 +566,9 @@
     PJ_ASSERT_RETURN(p, PJ_EINVAL);
 
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    if (ResumeThreadRT(rec->hthread) == (DWORD)-1)
+#else
     if (ResumeThread(rec->hthread) == (DWORD)-1)
+#endif    
         return PJ_RETURN_OS_ERROR(GetLastError());
     else
@@ -585,5 +614,9 @@
     PJ_LOG(6, (pj_thread_this()->obj_name, "Joining thread %s", p->obj_name));
 
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    rc = WaitForSingleObjectEx(rec->hthread, INFINITE, FALSE);
+#else
     rc = WaitForSingleObject(rec->hthread, INFINITE);
+#endif    
 
     if (rc==WAIT_OBJECT_0)
@@ -617,5 +650,11 @@
 {
     PJ_CHECK_STACK();
+
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    SleepRT(msec);
+#else
     Sleep(msec);
+#endif
+
     return PJ_SUCCESS;
 }
@@ -811,5 +850,9 @@
     //PJ_CHECK_STACK();
 
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    *index = TlsAllocRT();
+#else
     *index = TlsAlloc();
+#endif
 
     if (*index == TLS_OUT_OF_INDEXES)
@@ -825,5 +868,9 @@
 {
     PJ_CHECK_STACK();
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    TlsFreeRT(index);
+#else
     TlsFree(index);
+#endif    
 }
 
@@ -838,5 +885,11 @@
     //beginning before main thread is initialized.
     //PJ_CHECK_STACK();
+
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    rc = TlsSetValueRT(index, value);
+#else
     rc = TlsSetValue(index, value);
+#endif
+    
     return rc!=0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(GetLastError());
 }
@@ -850,5 +903,9 @@
     //by PJ_CHECK_STACK() itself!!!
     //PJ_CHECK_STACK();
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    return TlsGetValueRT(index);
+#else
     return TlsGetValue(index);
+#endif
 }
 
@@ -859,5 +916,7 @@
     PJ_CHECK_STACK();
 
-#if PJ_WIN32_WINNT >= 0x0400
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    InitializeCriticalSectionEx(&mutex->crit, 0, 0);
+#elif PJ_WIN32_WINNT >= 0x0400
     InitializeCriticalSection(&mutex->crit);
 #else
@@ -1113,5 +1172,13 @@
 
     sem = pj_pool_alloc(pool, sizeof(*sem));    
+
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    /** SEMAPHORE_ALL_ACCESS **/
+    sem->hSemaphore = CreateSemaphoreEx(NULL, initial, max, NULL, 0,
+					SEMAPHORE_ALL_ACCESS);
+#else
     sem->hSemaphore = CreateSemaphore(NULL, initial, max, NULL);
+#endif
+    
     if (!sem->hSemaphore)
 	return PJ_RETURN_OS_ERROR(GetLastError());
@@ -1143,6 +1210,11 @@
     LOG_MUTEX((sem->obj_name, "Semaphore: thread %s is waiting", 
 			      pj_thread_this()->obj_name));
-
+    
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    result = WaitForSingleObjectEx(sem->hSemaphore, timeout, FALSE);
+#else
     result = WaitForSingleObject(sem->hSemaphore, timeout);
+#endif
+
     if (result == WAIT_OBJECT_0) {
 	LOG_MUTEX((sem->obj_name, "Semaphore acquired by thread %s", 
@@ -1241,6 +1313,12 @@
         return PJ_ENOMEM;
 
-    event->hEvent = CreateEvent(NULL, manual_reset?TRUE:FALSE, 
-				initial?TRUE:FALSE, NULL);
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    event->hEvent = CreateEventEx(NULL, NULL,
+				 (manual_reset? 0x1:0x0) | (initial? 0x2:0x0),
+				 EVENT_ALL_ACCESS);
+#else
+    event->hEvent = CreateEvent(NULL, manual_reset ? TRUE : FALSE,
+			        initial ? TRUE : FALSE, NULL);
+#endif
 
     if (!event->hEvent)
@@ -1274,5 +1352,10 @@
 			        pj_thread_this()->obj_name));
 
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    result = WaitForSingleObjectEx(event->hEvent, timeout, FALSE);
+#else
     result = WaitForSingleObject(event->hEvent, timeout);
+#endif
+
     if (result == WAIT_OBJECT_0) {
 	PJ_LOG(6, (event->obj_name, "Event: thread %s is released", 
@@ -1332,4 +1415,9 @@
 PJ_DEF(pj_status_t) pj_event_pulse(pj_event_t *event)
 {
+#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
+    PJ_UNUSED_ARG(event);
+    pj_assert(!"pj_event_pulse() not supported!");
+    return PJ_ENOTSUP;
+#else
     PJ_CHECK_STACK();
     PJ_ASSERT_RETURN(event, PJ_EINVAL);
@@ -1338,7 +1426,8 @@
 
     if (PulseEvent(event->hEvent))
-        return PJ_SUCCESS;
+	return PJ_SUCCESS;
     else
-        return PJ_RETURN_OS_ERROR(GetLastError());
+	return PJ_RETURN_OS_ERROR(GetLastError());
+#endif
 }
 
