Ignore:
Timestamp:
Oct 16, 2013 8:04:59 AM (11 years ago)
Author:
riza
Message:

Re #1704: Initial implementation with cli/telnet mode pjsua

File:
1 edited

Legend:

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

    r4537 r4618  
    3939#endif 
    4040 
     41#if PJ_WIN32_WINPHONE 
     42#   include "../../third_party/threademulation/include/ThreadEmulation.h" 
     43#endif 
     44 
     45#if PJ_WIN32_WINNT >= 0x0602 
     46#  include <synchapi.h> 
     47#endif 
     48 
    4149/* Activate mutex related logging if PJ_DEBUG_MUTEX is set, otherwise 
    4250 * use default level 6 logging. 
     
    298306PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread) 
    299307{ 
     308#if PJ_WIN32_WINPHONE 
     309    PJ_UNUSED_ARG(thread); 
     310    return -1; 
     311#else 
    300312    return GetThreadPriority(thread->hthread); 
     313#endif 
    301314} 
    302315 
     
    507520    rec->proc = proc; 
    508521    rec->arg = arg; 
     522 
     523#ifdef PJ_WIN32_WINPHONE 
     524    rec->hthread = CreateThread(NULL, stack_size,  
     525                                thread_main, rec, 
     526                                dwflags, NULL); 
     527#else 
    509528    rec->hthread = CreateThread(NULL, stack_size,  
    510529                                thread_main, rec, 
    511530                                dwflags, &rec->idthread); 
     531#endif 
     532 
    512533    if (rec->hthread == NULL) 
    513534        return PJ_RETURN_OS_ERROR(GetLastError()); 
     
    552573PJ_DEF(pj_thread_t*) pj_thread_this(void) 
    553574{ 
    554     pj_thread_t *rec = pj_thread_local_get(thread_tls_id); 
     575    pj_thread_t *rec = (pj_thread_t *)pj_thread_local_get(thread_tls_id); 
    555576 
    556577    if (rec == NULL) { 
     
    585606    PJ_LOG(6, (pj_thread_this()->obj_name, "Joining thread %s", p->obj_name)); 
    586607 
     608#if PJ_WIN32_WINPHONE 
     609    rc = WaitForSingleObjectEx(rec->hthread, INFINITE, FALSE); 
     610#else 
    587611    rc = WaitForSingleObject(rec->hthread, INFINITE); 
     612#endif 
    588613 
    589614    if (rc==WAIT_OBJECT_0) 
     
    859884    PJ_CHECK_STACK(); 
    860885 
    861 #if PJ_WIN32_WINNT >= 0x0400 
    862     InitializeCriticalSection(&mutex->crit); 
     886#if PJ_WIN32_WINPHONE 
     887    InitializeCriticalSectionEx(&mutex->crit, 0, 0); 
     888#elif PJ_WIN32_WINNT >= 0x0400 
     889    InitializeCriticalSection(&mutex->crit);    
    863890#else 
    864891    mutex->hMutex = CreateMutex(NULL, FALSE, NULL); 
     
    11121139    PJ_ASSERT_RETURN(pool && sem_ptr, PJ_EINVAL); 
    11131140 
    1114     sem = pj_pool_alloc(pool, sizeof(*sem));     
     1141    sem = pj_pool_alloc(pool, sizeof(*sem));  
     1142#if PJ_WIN32_WINPHONE 
     1143    /** SEMAPHORE_ALL_ACCESS **/ 
     1144    sem->hSemaphore = CreateSemaphoreEx(NULL, initial, max, NULL, 0,  
     1145                                        SEMAPHORE_ALL_ACCESS); 
     1146#else 
    11151147    sem->hSemaphore = CreateSemaphore(NULL, initial, max, NULL); 
     1148#endif 
    11161149    if (!sem->hSemaphore) 
    11171150        return PJ_RETURN_OS_ERROR(GetLastError()); 
     
    11441177                              pj_thread_this()->obj_name)); 
    11451178 
     1179#if PJ_WIN32_WINPHONE 
     1180    result = WaitForSingleObjectEx(sem->hSemaphore, timeout, FALSE); 
     1181#else 
    11461182    result = WaitForSingleObject(sem->hSemaphore, timeout); 
     1183#endif 
     1184 
    11471185    if (result == WAIT_OBJECT_0) { 
    11481186        LOG_MUTEX((sem->obj_name, "Semaphore acquired by thread %s",  
     
    12411279        return PJ_ENOMEM; 
    12421280 
     1281#if PJ_WIN32_WINPHONE 
     1282    event->hEvent = CreateEventEx(NULL, NULL,  
     1283                                  (manual_reset?0x1:0x0)|(initial?0x2:0x0),  
     1284                                  EVENT_ALL_ACCESS); 
     1285#else 
    12431286    event->hEvent = CreateEvent(NULL, manual_reset?TRUE:FALSE,  
    12441287                                initial?TRUE:FALSE, NULL); 
     1288#endif 
    12451289 
    12461290    if (!event->hEvent) 
     
    12741318                                pj_thread_this()->obj_name)); 
    12751319 
     1320#if PJ_WIN32_WINPHONE 
     1321    result = WaitForSingleObjectEx(event->hEvent, timeout, FALSE); 
     1322#else 
    12761323    result = WaitForSingleObject(event->hEvent, timeout); 
     1324#endif 
    12771325    if (result == WAIT_OBJECT_0) { 
    12781326        PJ_LOG(6, (event->obj_name, "Event: thread %s is released",  
     
    13321380PJ_DEF(pj_status_t) pj_event_pulse(pj_event_t *event) 
    13331381{ 
     1382#ifdef PJ_WIN32_WINPHONE 
     1383    PJ_UNUSED_ARG(event); 
     1384    pj_assert(!"pj_event_pulse() not supported!"); 
     1385    return PJ_ENOTSUP; 
     1386#else 
    13341387    PJ_CHECK_STACK(); 
    13351388    PJ_ASSERT_RETURN(event, PJ_EINVAL); 
     
    13411394    else 
    13421395        return PJ_RETURN_OS_ERROR(GetLastError()); 
     1396#endif 
    13431397} 
    13441398 
Note: See TracChangeset for help on using the changeset viewer.