Ignore:
Timestamp:
Nov 1, 2005 4:42:51 PM (18 years ago)
Author:
bennylp
Message:

Added suppor /and fix things for SunOS port

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/main/pjlib/src/pj/os_core_unix.c

    r1 r2  
    175175#if PJ_HAS_THREADS 
    176176    char stack_ptr; 
     177    pj_status_t rc; 
    177178    pj_thread_t *thread = (pj_thread_t *)desc; 
    178179    pj_str_t thread_name = pj_str((char*)cstr_thread_name); 
     
    191192 
    192193    /* Initialize and set the thread entry. */ 
    193     pj_memset(desc, 0, sizeof(pj_thread_desc)); 
     194    pj_memset(desc, 0, sizeof(struct pj_thread_t)); 
    194195    thread->thread = pthread_self(); 
    195196 
     
    199200        pj_sprintf(thread->obj_name, "thr%p", (void*)thread->thread); 
    200201     
    201     pj_thread_local_set(thread_tls_id, thread); 
     202    rc = pj_thread_local_set(thread_tls_id, thread); 
     203    if (rc != PJ_SUCCESS) 
     204        return rc; 
    202205 
    203206#if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 
     
    214217    pj_thread_t *thread = (pj_thread_t*)desc; 
    215218    *ptr_thread = thread; 
    216     return SUCCESS; 
     219    return PJ_SUCCESS; 
    217220#endif 
    218221} 
     
    231234        return rc; 
    232235    } 
    233     return pj_thread_register("thr%p", (pj_uint8_t*)&main_thread, &dummy); 
     236    return pj_thread_register("thr%p", (long*)&main_thread, &dummy); 
    234237#else 
    235238    PJ_LOG(2,(THIS_FILE, "Thread init error. Threading is not enabled!")); 
     
    248251    pj_thread_t *rec = param; 
    249252    void *result; 
     253    pj_status_t rc; 
    250254 
    251255#if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 
     
    254258 
    255259    /* Set current thread id. */ 
    256     pj_thread_local_set(thread_tls_id, rec); 
     260    rc = pj_thread_local_set(thread_tls_id, rec); 
     261    if (rc != PJ_SUCCESS) { 
     262        pj_assert(!"Thread TLS ID is not set (pj_init() error?)"); 
     263    } 
    257264 
    258265    /* Check if suspension is required. */ 
     
    660667 * pj_thread_local_set() 
    661668 */ 
    662 PJ_DEF(void) pj_thread_local_set(long index, void *value) 
     669PJ_DEF(pj_status_t) pj_thread_local_set(long index, void *value) 
    663670{ 
    664671    //Can't check stack because this function is called in the 
     
    666673    //PJ_CHECK_STACK(); 
    667674#if PJ_HAS_THREADS 
    668     pthread_setspecific(index, value); 
     675    int rc=pthread_setspecific(index, value); 
     676    return rc==0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(rc); 
    669677#else 
    670678    pj_assert(index >= 0 && index < MAX_THREADS); 
    671679    tls[index] = value; 
     680    return PJ_SUCCESS; 
    672681#endif 
    673682} 
     
    706715{ 
    707716#if PJ_HAS_THREADS 
    708     PJ_UNUSED_ARG(type); 
    709  
    710     PJ_CHECK_STACK(); 
     717    pthread_mutexattr_t attr; 
     718    int rc; 
     719 
     720    PJ_CHECK_STACK(); 
     721 
     722    pthread_mutexattr_init(&attr); 
    711723 
    712724    if (type == PJ_MUTEX_SIMPLE) { 
    713         pthread_mutex_t the_mutex = PTHREAD_MUTEX_INITIALIZER; 
    714         mutex->mutex = the_mutex; 
     725#if defined(PJ_LINUX) && PJ_LINUX!=0 
     726        rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP); 
     727#else 
     728        rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); 
     729#endif 
    715730    } else { 
    716         pthread_mutex_t the_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; 
    717         mutex->mutex = the_mutex; 
     731#if defined(PJ_LINUX) && PJ_LINUX!=0 
     732        rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); 
     733#else 
     734        rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 
     735#endif 
     736    } 
     737     
     738    if (rc != 0) { 
     739        return PJ_RETURN_OS_ERROR(rc); 
     740    } 
     741 
     742    rc = pthread_mutex_init(&mutex->mutex, &attr); 
     743    if (rc != 0) { 
     744        return PJ_RETURN_OS_ERROR(rc); 
    718745    } 
    719746     
Note: See TracChangeset for help on using the changeset viewer.