Ignore:
Timestamp:
Mar 5, 2014 6:48:59 AM (10 years ago)
Author:
riza
Message:

Re #1704:

  • Fix duplicate code on os_winphone.h
  • Change the use of PJ_WIN32_WINPHONE to follow the code convention
  • Fix incorrect link of the Thread library
  • Handle exception raised from select() API. However the break window will still be shown when debugging on Visual Studio. To disable it, from Debug>Exceptions>Win32 Exceptions> unmark the "An invalid handle was specified” exception.
File:
1 edited

Legend:

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

    r4618 r4777  
    3939#endif 
    4040 
    41 #if PJ_WIN32_WINPHONE 
    42 #   include "../../third_party/threademulation/include/ThreadEmulation.h" 
     41#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     42#   include "../../../third_party/threademulation/include/ThreadEmulation.h" 
    4343#endif 
    4444 
     
    306306PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread) 
    307307{ 
    308 #if PJ_WIN32_WINPHONE 
     308#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
    309309    PJ_UNUSED_ARG(thread); 
    310310    return -1; 
     
    326326                     PJ_EINVAL); 
    327327 
     328#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     329    if (SetThreadPriorityRT(thread->hthread, prio) == FALSE) 
     330#else 
    328331    if (SetThreadPriority(thread->hthread, prio) == FALSE) 
     332#endif 
    329333        return PJ_RETURN_OS_ERROR(GetLastError()); 
    330334 
     
    487491    pj_thread_t *rec; 
    488492 
     493#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     494    PJ_UNUSED_ARG(stack_size); 
     495#endif 
     496 
    489497    PJ_CHECK_STACK(); 
    490498    PJ_ASSERT_RETURN(pool && proc && thread_ptr, PJ_EINVAL); 
     
    521529    rec->arg = arg; 
    522530 
    523 #ifdef PJ_WIN32_WINPHONE 
    524     rec->hthread = CreateThread(NULL, stack_size,  
    525                                 thread_main, rec, 
    526                                 dwflags, NULL); 
     531#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     532    rec->hthread = CreateThreadRT(NULL, 0,  
     533                                  thread_main, rec, 
     534                                  dwflags, NULL); 
    527535#else 
    528536    rec->hthread = CreateThread(NULL, stack_size,  
     
    562570    PJ_ASSERT_RETURN(p, PJ_EINVAL); 
    563571 
     572#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     573    if (ResumeThreadRT(rec->hthread) == (DWORD)-1) 
     574#else 
    564575    if (ResumeThread(rec->hthread) == (DWORD)-1) 
     576#endif 
    565577        return PJ_RETURN_OS_ERROR(GetLastError()); 
    566578    else 
     
    606618    PJ_LOG(6, (pj_thread_this()->obj_name, "Joining thread %s", p->obj_name)); 
    607619 
    608 #if PJ_WIN32_WINPHONE 
     620#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
    609621    rc = WaitForSingleObjectEx(rec->hthread, INFINITE, FALSE); 
    610622#else 
     
    642654{ 
    643655    PJ_CHECK_STACK(); 
     656#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     657    SleepRT(msec); 
     658#else 
    644659    Sleep(msec); 
     660#endif 
    645661    return PJ_SUCCESS; 
    646662} 
     
    836852    //PJ_CHECK_STACK(); 
    837853 
     854#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     855    *index = TlsAllocRT(); 
     856#else 
    838857    *index = TlsAlloc(); 
     858#endif 
    839859 
    840860    if (*index == TLS_OUT_OF_INDEXES) 
     
    850870{ 
    851871    PJ_CHECK_STACK(); 
     872#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     873    TlsFreeRT(index); 
     874#else 
    852875    TlsFree(index); 
     876#endif 
    853877} 
    854878 
     
    863887    //beginning before main thread is initialized. 
    864888    //PJ_CHECK_STACK(); 
     889#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     890    rc = TlsSetValueRT(index, value); 
     891#else 
    865892    rc = TlsSetValue(index, value); 
     893#endif 
    866894    return rc!=0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(GetLastError()); 
    867895} 
     
    875903    //by PJ_CHECK_STACK() itself!!! 
    876904    //PJ_CHECK_STACK(); 
     905#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
     906    return TlsGetValueRT(index); 
     907#else 
    877908    return TlsGetValue(index); 
     909#endif 
    878910} 
    879911 
     
    884916    PJ_CHECK_STACK(); 
    885917 
    886 #if PJ_WIN32_WINPHONE 
     918#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
    887919    InitializeCriticalSectionEx(&mutex->crit, 0, 0); 
    888920#elif PJ_WIN32_WINNT >= 0x0400 
     
    11401172 
    11411173    sem = pj_pool_alloc(pool, sizeof(*sem));  
    1142 #if PJ_WIN32_WINPHONE 
     1174#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
    11431175    /** SEMAPHORE_ALL_ACCESS **/ 
    11441176    sem->hSemaphore = CreateSemaphoreEx(NULL, initial, max, NULL, 0,  
     
    11771209                              pj_thread_this()->obj_name)); 
    11781210 
    1179 #if PJ_WIN32_WINPHONE 
     1211#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
    11801212    result = WaitForSingleObjectEx(sem->hSemaphore, timeout, FALSE); 
    11811213#else 
     
    12791311        return PJ_ENOMEM; 
    12801312 
    1281 #if PJ_WIN32_WINPHONE 
     1313#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
    12821314    event->hEvent = CreateEventEx(NULL, NULL,  
    12831315                                  (manual_reset?0x1:0x0)|(initial?0x2:0x0),  
     
    13181350                                pj_thread_this()->obj_name)); 
    13191351 
    1320 #if PJ_WIN32_WINPHONE 
     1352#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
    13211353    result = WaitForSingleObjectEx(event->hEvent, timeout, FALSE); 
    13221354#else 
     
    13801412PJ_DEF(pj_status_t) pj_event_pulse(pj_event_t *event) 
    13811413{ 
    1382 #ifdef PJ_WIN32_WINPHONE 
     1414#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE 
    13831415    PJ_UNUSED_ARG(event); 
    13841416    pj_assert(!"pj_event_pulse() not supported!"); 
Note: See TracChangeset for help on using the changeset viewer.