Ignore:
File:
1 edited

Legend:

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

    • Property svn:keywords set to Author
    r1 r3  
    1 /* $Header: /pjproject-0.3/pjlib/src/pj/os_core_unix.c 11    10/29/05 10:27p Bennylp $ */ 
    2 /*  
    3  * $Log: /pjproject-0.3/pjlib/src/pj/os_core_unix.c $  
    4  *  
    5  * 11    10/29/05 10:27p Bennylp 
    6  * Fixed misc warnings. 
    7  *  
    8  * 10    10/29/05 11:51a Bennylp 
    9  * Version 0.3-pre2. 
    10  *  
    11  * 9     10/14/05 12:26a Bennylp 
    12  * Finished error code framework, some fixes in ioqueue, etc. Pretty 
    13  * major. 
     1/* $Id$ 
    142 * 
    153 */ 
     
    3321 
    3422#define __USE_GNU 
     23//uncomment this to get pthread_mutexattr_settype declaration. 
     24//unfortunately this causes syntax error in pthread.h! :( 
     25//#define __USE_UNIX98 
    3526#include <pthread.h> 
    3627 
     
    175166#if PJ_HAS_THREADS 
    176167    char stack_ptr; 
     168    pj_status_t rc; 
    177169    pj_thread_t *thread = (pj_thread_t *)desc; 
    178170    pj_str_t thread_name = pj_str((char*)cstr_thread_name); 
     
    191183 
    192184    /* Initialize and set the thread entry. */ 
    193     pj_memset(desc, 0, sizeof(pj_thread_desc)); 
     185    pj_memset(desc, 0, sizeof(struct pj_thread_t)); 
    194186    thread->thread = pthread_self(); 
    195187 
     
    199191        pj_sprintf(thread->obj_name, "thr%p", (void*)thread->thread); 
    200192     
    201     pj_thread_local_set(thread_tls_id, thread); 
     193    rc = pj_thread_local_set(thread_tls_id, thread); 
     194    if (rc != PJ_SUCCESS) 
     195        return rc; 
    202196 
    203197#if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 
     
    214208    pj_thread_t *thread = (pj_thread_t*)desc; 
    215209    *ptr_thread = thread; 
    216     return SUCCESS; 
     210    return PJ_SUCCESS; 
    217211#endif 
    218212} 
     
    231225        return rc; 
    232226    } 
    233     return pj_thread_register("thr%p", (pj_uint8_t*)&main_thread, &dummy); 
     227    return pj_thread_register("thr%p", (long*)&main_thread, &dummy); 
    234228#else 
    235229    PJ_LOG(2,(THIS_FILE, "Thread init error. Threading is not enabled!")); 
     
    248242    pj_thread_t *rec = param; 
    249243    void *result; 
     244    pj_status_t rc; 
    250245 
    251246#if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 
     
    254249 
    255250    /* Set current thread id. */ 
    256     pj_thread_local_set(thread_tls_id, rec); 
     251    rc = pj_thread_local_set(thread_tls_id, rec); 
     252    if (rc != PJ_SUCCESS) { 
     253        pj_assert(!"Thread TLS ID is not set (pj_init() error?)"); 
     254    } 
    257255 
    258256    /* Check if suspension is required. */ 
     
    660658 * pj_thread_local_set() 
    661659 */ 
    662 PJ_DEF(void) pj_thread_local_set(long index, void *value) 
     660PJ_DEF(pj_status_t) pj_thread_local_set(long index, void *value) 
    663661{ 
    664662    //Can't check stack because this function is called in the 
     
    666664    //PJ_CHECK_STACK(); 
    667665#if PJ_HAS_THREADS 
    668     pthread_setspecific(index, value); 
     666    int rc=pthread_setspecific(index, value); 
     667    return rc==0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(rc); 
    669668#else 
    670669    pj_assert(index >= 0 && index < MAX_THREADS); 
    671670    tls[index] = value; 
     671    return PJ_SUCCESS; 
    672672#endif 
    673673} 
     
    706706{ 
    707707#if PJ_HAS_THREADS 
    708     PJ_UNUSED_ARG(type); 
    709  
    710     PJ_CHECK_STACK(); 
     708    pthread_mutexattr_t attr; 
     709    int rc; 
     710 
     711    PJ_CHECK_STACK(); 
     712 
     713    pthread_mutexattr_init(&attr); 
    711714 
    712715    if (type == PJ_MUTEX_SIMPLE) { 
    713         pthread_mutex_t the_mutex = PTHREAD_MUTEX_INITIALIZER; 
    714         mutex->mutex = the_mutex; 
     716#if defined(PJ_LINUX) && PJ_LINUX!=0 
     717        rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP); 
     718#else 
     719        rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); 
     720#endif 
    715721    } else { 
    716         pthread_mutex_t the_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; 
    717         mutex->mutex = the_mutex; 
     722#if defined(PJ_LINUX) && PJ_LINUX!=0 
     723        rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); 
     724#else 
     725        rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 
     726#endif 
     727    } 
     728     
     729    if (rc != 0) { 
     730        return PJ_RETURN_OS_ERROR(rc); 
     731    } 
     732 
     733    rc = pthread_mutex_init(&mutex->mutex, &attr); 
     734    if (rc != 0) { 
     735        return PJ_RETURN_OS_ERROR(rc); 
    718736    } 
    719737     
Note: See TracChangeset for help on using the changeset viewer.