Ignore:
Timestamp:
Dec 10, 2015 1:58:38 AM (8 years ago)
Author:
riza
Message:

Re #1900: Initial implementation with pjsua cli/telnet sample app.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/uwp/pjlib/src/pj/os_core_win32.c

    r4537 r5210  
    3939#endif 
    4040 
     41#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     42#   include "../../../third_party/threademulation/include/ThreadEmulation.h" 
     43#endif 
     44 
    4145/* Activate mutex related logging if PJ_DEBUG_MUTEX is set, otherwise 
    4246 * use default level 6 logging. 
     
    298302PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread) 
    299303{ 
     304#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     305    PJ_UNUSED_ARG(thread); 
     306    return -1; 
     307#else 
    300308    return GetThreadPriority(thread->hthread); 
     309#endif 
    301310} 
    302311 
     
    313322                     PJ_EINVAL); 
    314323 
     324#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     325    if (SetThreadPriorityRT(thread->hthread, prio) == FALSE) 
     326#else 
    315327    if (SetThreadPriority(thread->hthread, prio) == FALSE) 
     328#endif 
    316329        return PJ_RETURN_OS_ERROR(GetLastError()); 
    317330 
     
    474487    pj_thread_t *rec; 
    475488 
     489#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     490    PJ_UNUSED_ARG(stack_size); 
     491#endif 
     492 
    476493    PJ_CHECK_STACK(); 
    477494    PJ_ASSERT_RETURN(pool && proc && thread_ptr, PJ_EINVAL); 
     
    507524    rec->proc = proc; 
    508525    rec->arg = arg; 
    509     rec->hthread = CreateThread(NULL, stack_size,  
    510                                 thread_main, rec, 
    511                                 dwflags, &rec->idthread); 
     526 
     527#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     528    rec->hthread = CreateThreadRT(NULL, 0, 
     529                                  thread_main, rec, 
     530                                  dwflags, NULL); 
     531#else 
     532    rec->hthread = CreateThread(NULL, stack_size, 
     533                                thread_main, rec, 
     534                                dwflags, &rec->idthread); 
     535#endif 
     536 
    512537    if (rec->hthread == NULL) 
    513538        return PJ_RETURN_OS_ERROR(GetLastError()); 
     
    541566    PJ_ASSERT_RETURN(p, PJ_EINVAL); 
    542567 
     568#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     569    if (ResumeThreadRT(rec->hthread) == (DWORD)-1) 
     570#else 
    543571    if (ResumeThread(rec->hthread) == (DWORD)-1) 
     572#endif     
    544573        return PJ_RETURN_OS_ERROR(GetLastError()); 
    545574    else 
     
    585614    PJ_LOG(6, (pj_thread_this()->obj_name, "Joining thread %s", p->obj_name)); 
    586615 
     616#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     617    rc = WaitForSingleObjectEx(rec->hthread, INFINITE, FALSE); 
     618#else 
    587619    rc = WaitForSingleObject(rec->hthread, INFINITE); 
     620#endif     
    588621 
    589622    if (rc==WAIT_OBJECT_0) 
     
    617650{ 
    618651    PJ_CHECK_STACK(); 
     652 
     653#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     654    SleepRT(msec); 
     655#else 
    619656    Sleep(msec); 
     657#endif 
     658 
    620659    return PJ_SUCCESS; 
    621660} 
     
    811850    //PJ_CHECK_STACK(); 
    812851 
     852#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     853    *index = TlsAllocRT(); 
     854#else 
    813855    *index = TlsAlloc(); 
     856#endif 
    814857 
    815858    if (*index == TLS_OUT_OF_INDEXES) 
     
    825868{ 
    826869    PJ_CHECK_STACK(); 
     870#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     871    TlsFreeRT(index); 
     872#else 
    827873    TlsFree(index); 
     874#endif     
    828875} 
    829876 
     
    838885    //beginning before main thread is initialized. 
    839886    //PJ_CHECK_STACK(); 
     887 
     888#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     889    rc = TlsSetValueRT(index, value); 
     890#else 
    840891    rc = TlsSetValue(index, value); 
     892#endif 
     893     
    841894    return rc!=0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(GetLastError()); 
    842895} 
     
    850903    //by PJ_CHECK_STACK() itself!!! 
    851904    //PJ_CHECK_STACK(); 
     905#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     906    return TlsGetValueRT(index); 
     907#else 
    852908    return TlsGetValue(index); 
     909#endif 
    853910} 
    854911 
     
    859916    PJ_CHECK_STACK(); 
    860917 
    861 #if PJ_WIN32_WINNT >= 0x0400 
     918#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     919    InitializeCriticalSectionEx(&mutex->crit, 0, 0); 
     920#elif PJ_WIN32_WINNT >= 0x0400 
    862921    InitializeCriticalSection(&mutex->crit); 
    863922#else 
     
    11131172 
    11141173    sem = pj_pool_alloc(pool, sizeof(*sem));     
     1174 
     1175#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     1176    /** SEMAPHORE_ALL_ACCESS **/ 
     1177    sem->hSemaphore = CreateSemaphoreEx(NULL, initial, max, NULL, 0, 
     1178                                        SEMAPHORE_ALL_ACCESS); 
     1179#else 
    11151180    sem->hSemaphore = CreateSemaphore(NULL, initial, max, NULL); 
     1181#endif 
     1182     
    11161183    if (!sem->hSemaphore) 
    11171184        return PJ_RETURN_OS_ERROR(GetLastError()); 
     
    11431210    LOG_MUTEX((sem->obj_name, "Semaphore: thread %s is waiting",  
    11441211                              pj_thread_this()->obj_name)); 
    1145  
     1212     
     1213#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     1214    result = WaitForSingleObjectEx(sem->hSemaphore, timeout, FALSE); 
     1215#else 
    11461216    result = WaitForSingleObject(sem->hSemaphore, timeout); 
     1217#endif 
     1218 
    11471219    if (result == WAIT_OBJECT_0) { 
    11481220        LOG_MUTEX((sem->obj_name, "Semaphore acquired by thread %s",  
     
    12411313        return PJ_ENOMEM; 
    12421314 
    1243     event->hEvent = CreateEvent(NULL, manual_reset?TRUE:FALSE,  
    1244                                 initial?TRUE:FALSE, NULL); 
     1315#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     1316    event->hEvent = CreateEventEx(NULL, NULL, 
     1317                                 (manual_reset? 0x1:0x0) | (initial? 0x2:0x0), 
     1318                                 EVENT_ALL_ACCESS); 
     1319#else 
     1320    event->hEvent = CreateEvent(NULL, manual_reset ? TRUE : FALSE, 
     1321                                initial ? TRUE : FALSE, NULL); 
     1322#endif 
    12451323 
    12461324    if (!event->hEvent) 
     
    12741352                                pj_thread_this()->obj_name)); 
    12751353 
     1354#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     1355    result = WaitForSingleObjectEx(event->hEvent, timeout, FALSE); 
     1356#else 
    12761357    result = WaitForSingleObject(event->hEvent, timeout); 
     1358#endif 
     1359 
    12771360    if (result == WAIT_OBJECT_0) { 
    12781361        PJ_LOG(6, (event->obj_name, "Event: thread %s is released",  
     
    13321415PJ_DEF(pj_status_t) pj_event_pulse(pj_event_t *event) 
    13331416{ 
     1417#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     1418    PJ_UNUSED_ARG(event); 
     1419    pj_assert(!"pj_event_pulse() not supported!"); 
     1420    return PJ_ENOTSUP; 
     1421#else 
    13341422    PJ_CHECK_STACK(); 
    13351423    PJ_ASSERT_RETURN(event, PJ_EINVAL); 
     
    13381426 
    13391427    if (PulseEvent(event->hEvent)) 
    1340         return PJ_SUCCESS; 
     1428        return PJ_SUCCESS; 
    13411429    else 
    1342         return PJ_RETURN_OS_ERROR(GetLastError()); 
     1430        return PJ_RETURN_OS_ERROR(GetLastError()); 
     1431#endif 
    13431432} 
    13441433 
Note: See TracChangeset for help on using the changeset viewer.