Ignore:
Timestamp:
Feb 4, 2014 10:13:56 AM (10 years ago)
Author:
bennylp
Message:

Misc (re #1630): Fixing warnings about variable set but not used with recent gcc

File:
1 edited

Legend:

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

    r4359 r4728  
    11/* $Id$ */ 
    2 /*  
     2/* 
    33 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) 
    44 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> 
     
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1919 */ 
    2020/* 
     
    165165    pj_log_init(); 
    166166 
    167     /* Initialize exception ID for the pool.  
     167    /* Initialize exception ID for the pool. 
    168168     * Must do so after critical section is configured. 
    169169     */ 
     
    171171    if (rc != PJ_SUCCESS) 
    172172        return rc; 
    173      
     173 
    174174    /* Init random seed. */ 
    175175    /* Or probably not. Let application in charge of this */ 
     
    188188        } 
    189189    } 
    190 #endif    
     190#endif 
    191191 
    192192    /* Flag PJLIB as initialized */ 
     
    383383 * Get native thread handle 
    384384 */ 
    385 PJ_DEF(void*) pj_thread_get_os_handle(pj_thread_t *thread)  
     385PJ_DEF(void*) pj_thread_get_os_handle(pj_thread_t *thread) 
    386386{ 
    387387    PJ_ASSERT_RETURN(thread, NULL); 
     
    441441 
    442442    if(cstr_thread_name && pj_strlen(&thread_name) < sizeof(thread->obj_name)-1) 
    443         pj_ansi_snprintf(thread->obj_name, sizeof(thread->obj_name),  
     443        pj_ansi_snprintf(thread->obj_name, sizeof(thread->obj_name), 
    444444                         cstr_thread_name, thread->thread); 
    445445    else 
    446         pj_ansi_snprintf(thread->obj_name, sizeof(thread->obj_name),  
     446        pj_ansi_snprintf(thread->obj_name, sizeof(thread->obj_name), 
    447447                         "thr%p", (void*)thread->thread); 
    448      
     448 
    449449    rc = pj_thread_local_set(thread_tls_id, thread); 
    450450    if (rc != PJ_SUCCESS) { 
     
    458458    thread->stk_max_usage = 0; 
    459459#else 
    460     stack_ptr = '\0'; 
     460    PJ_UNUSED_ARG(stack_ptr); 
    461461#endif 
    462462 
     
    533533 * pj_thread_create(...) 
    534534 */ 
    535 PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool,  
     535PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool, 
    536536                                      const char *thread_name, 
    537                                       pj_thread_proc *proc,  
     537                                      pj_thread_proc *proc, 
    538538                                      void *arg, 
    539                                       pj_size_t stack_size,  
     539                                      pj_size_t stack_size, 
    540540                                      unsigned flags, 
    541541                                      pj_thread_t **ptr_thread) 
     
    555555    rec = (struct pj_thread_t*) pj_pool_zalloc(pool, sizeof(pj_thread_t)); 
    556556    PJ_ASSERT_RETURN(rec, PJ_ENOMEM); 
    557      
     557 
    558558    /* Set name. */ 
    559     if (!thread_name)  
     559    if (!thread_name) 
    560560        thread_name = "thr%p"; 
    561      
     561 
    562562    if (strchr(thread_name, '%')) { 
    563563        pj_ansi_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec); 
     
    587587        pj_assert(rec->suspended_mutex == NULL); 
    588588    } 
    589      
     589 
    590590 
    591591    /* Init thread attributes */ 
     
    668668#if PJ_HAS_THREADS 
    669669    pj_thread_t *rec = (pj_thread_t*)pj_thread_local_get(thread_tls_id); 
    670      
     670 
    671671    if (rec == NULL) { 
    672672        pj_assert(!"Calling pjlib from unknown/external thread. You must " 
     
    706706        return PJ_SUCCESS; 
    707707    else { 
    708         /* Calling pthread_join() on a thread that no longer exists and  
    709          * getting back ESRCH isn't an error (in this context).  
     708        /* Calling pthread_join() on a thread that no longer exists and 
     709         * getting back ESRCH isn't an error (in this context). 
    710710         * Thanks Phil Torre <ptorre@zetron.com>. 
    711711         */ 
     
    762762    /* MacOS X (reported on 10.5) seems to always set errno to ETIMEDOUT. 
    763763     * It does so because usleep() is declared to return int, and we're 
    764      * supposed to check for errno only when usleep() returns non-zero.  
     764     * supposed to check for errno only when usleep() returns non-zero. 
    765765     * Unfortunately, usleep() is declared to return void in other platforms 
    766      * so it's not possible to always check for the return value (unless  
     766     * so it's not possible to always check for the return value (unless 
    767767     * we add a detection routine in autoconf). 
    768768     * 
     
    832832 * pj_atomic_create() 
    833833 */ 
    834 PJ_DEF(pj_status_t) pj_atomic_create( pj_pool_t *pool,  
     834PJ_DEF(pj_status_t) pj_atomic_create( pj_pool_t *pool, 
    835835                                      pj_atomic_value_t initial, 
    836836                                      pj_atomic_t **ptr_atomic) 
     
    842842 
    843843    PJ_ASSERT_RETURN(atomic_var, PJ_ENOMEM); 
    844      
     844 
    845845#if PJ_HAS_THREADS 
    846846    rc = pj_mutex_create(pool, "atm%p", PJ_MUTEX_SIMPLE, &atomic_var->mutex); 
     
    880880#if PJ_HAS_THREADS 
    881881    pj_mutex_unlock( atomic_var->mutex); 
    882 #endif  
     882#endif 
    883883} 
    884884 
     
    889889{ 
    890890    pj_atomic_value_t oldval; 
    891      
     891 
    892892    PJ_CHECK_STACK(); 
    893893 
     
    959959/* 
    960960 * pj_atomic_add_and_get() 
    961  */  
    962 PJ_DEF(pj_atomic_value_t) pj_atomic_add_and_get( pj_atomic_t *atomic_var,  
     961 */ 
     962PJ_DEF(pj_atomic_value_t) pj_atomic_add_and_get( pj_atomic_t *atomic_var, 
    963963                                                 pj_atomic_value_t value ) 
    964964{ 
     
    968968    pj_mutex_lock(atomic_var->mutex); 
    969969#endif 
    970      
     970 
    971971    atomic_var->value += value; 
    972972    new_value = atomic_var->value; 
     
    981981/* 
    982982 * pj_atomic_add() 
    983  */  
    984 PJ_DEF(void) pj_atomic_add( pj_atomic_t *atomic_var,  
     983 */ 
     984PJ_DEF(void) pj_atomic_add( pj_atomic_t *atomic_var, 
    985985                            pj_atomic_value_t value ) 
    986986{ 
     
    10121012            break; 
    10131013    } 
    1014     if (i == MAX_THREADS)  
     1014    if (i == MAX_THREADS) 
    10151015        return PJ_ETOOMANY; 
    1016      
     1016 
    10171017    tls_flag[i] = 1; 
    10181018    tls[i] = NULL; 
     
    11191119       defined(PJ_PTHREAD_MUTEXATTR_T_HAS_RECURSIVE) 
    11201120        // Phil Torre <ptorre@zetron.com>: 
    1121         // The RTEMS implementation of POSIX mutexes doesn't include  
     1121        // The RTEMS implementation of POSIX mutexes doesn't include 
    11221122        // pthread_mutexattr_settype(), so what follows is a hack 
    11231123        // until I get RTEMS patched to support the set/get functions. 
     
    11321132#endif 
    11331133    } 
    1134      
     1134 
    11351135    if (rc != 0) { 
    11361136        return PJ_RETURN_OS_ERROR(rc); 
     
    11411141        return PJ_RETURN_OS_ERROR(rc); 
    11421142    } 
    1143      
     1143 
    11441144    rc = pthread_mutexattr_destroy(&attr); 
    11451145    if (rc != 0) { 
     
    11761176 * pj_mutex_create() 
    11771177 */ 
    1178 PJ_DEF(pj_status_t) pj_mutex_create(pj_pool_t *pool,  
    1179                                     const char *name,  
     1178PJ_DEF(pj_status_t) pj_mutex_create(pj_pool_t *pool, 
     1179                                    const char *name, 
    11801180                                    int type, 
    11811181                                    pj_mutex_t **ptr_mutex) 
     
    11921192    if ((rc=init_mutex(mutex, name, type)) != PJ_SUCCESS) 
    11931193        return rc; 
    1194      
     1194 
    11951195    *ptr_mutex = mutex; 
    11961196    return PJ_SUCCESS; 
     
    12041204 * pj_mutex_create_simple() 
    12051205 */ 
    1206 PJ_DEF(pj_status_t) pj_mutex_create_simple( pj_pool_t *pool,  
     1206PJ_DEF(pj_status_t) pj_mutex_create_simple( pj_pool_t *pool, 
    12071207                                            const char *name, 
    12081208                                            pj_mutex_t **mutex ) 
     
    12331233 
    12341234#if PJ_DEBUG 
    1235     PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is waiting (mutex owner=%s)",  
     1235    PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is waiting (mutex owner=%s)", 
    12361236                                pj_thread_this()->obj_name, 
    12371237                                mutex->owner_name)); 
    12381238#else 
    1239     PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is waiting",  
     1239    PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is waiting", 
    12401240                                pj_thread_this()->obj_name)); 
    12411241#endif 
     
    12511251    } 
    12521252 
    1253     PJ_LOG(6,(mutex->obj_name,  
    1254               (status==0 ?  
    1255                 "Mutex acquired by thread %s (level=%d)" :  
     1253    PJ_LOG(6,(mutex->obj_name, 
     1254              (status==0 ? 
     1255                "Mutex acquired by thread %s (level=%d)" : 
    12561256                "Mutex acquisition FAILED by %s (level=%d)"), 
    12571257              pj_thread_this()->obj_name, 
    12581258              mutex->nesting_level)); 
    12591259#else 
    1260     PJ_LOG(6,(mutex->obj_name,  
     1260    PJ_LOG(6,(mutex->obj_name, 
    12611261              (status==0 ? "Mutex acquired by thread %s" : "FAILED by %s"), 
    12621262              pj_thread_this()->obj_name)); 
     
    12911291    } 
    12921292 
    1293     PJ_LOG(6,(mutex->obj_name, "Mutex released by thread %s (level=%d)",  
    1294                                 pj_thread_this()->obj_name,  
     1293    PJ_LOG(6,(mutex->obj_name, "Mutex released by thread %s (level=%d)", 
     1294                                pj_thread_this()->obj_name, 
    12951295                                mutex->nesting_level)); 
    12961296#else 
    1297     PJ_LOG(6,(mutex->obj_name, "Mutex released by thread %s",  
     1297    PJ_LOG(6,(mutex->obj_name, "Mutex released by thread %s", 
    12981298                                pj_thread_this()->obj_name)); 
    12991299#endif 
     
    13221322    PJ_ASSERT_RETURN(mutex, PJ_EINVAL); 
    13231323 
    1324     PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is trying",  
     1324    PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is trying", 
    13251325                                pj_thread_this()->obj_name)); 
    13261326 
     
    13331333        ++mutex->nesting_level; 
    13341334 
    1335         PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s (level=%d)",  
     1335        PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s (level=%d)", 
    13361336                                   pj_thread_this()->obj_name, 
    13371337                                   mutex->nesting_level)); 
    13381338#else 
    1339         PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s",  
     1339        PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s", 
    13401340                                  pj_thread_this()->obj_name)); 
    13411341#endif 
    13421342    } else { 
    1343         PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s's trylock() failed",  
     1343        PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s's trylock() failed", 
    13441344                                    pj_thread_this()->obj_name)); 
    13451345    } 
    1346      
     1346 
    13471347    if (status==0) 
    13481348        return PJ_SUCCESS; 
     
    14261426 
    14271427    PJ_UNUSED_ARG(name); 
    1428      
     1428 
    14291429    rwm = PJ_POOL_ALLOC_T(pool, pj_rwmutex_t); 
    14301430    PJ_ASSERT_RETURN(rwm, PJ_ENOMEM); 
     
    15161516 * pj_sem_create() 
    15171517 */ 
    1518 PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,  
     1518PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool, 
    15191519                                   const char *name, 
    1520                                    unsigned initial,  
     1520                                   unsigned initial, 
    15211521                                   unsigned max, 
    15221522                                   pj_sem_t **ptr_sem) 
     
    15371537        pj_str_t nam; 
    15381538 
    1539         /* We should use SEM_NAME_LEN, but this doesn't seem to be  
     1539        /* We should use SEM_NAME_LEN, but this doesn't seem to be 
    15401540         * declared anywhere? The value here is just from trial and error 
    15411541         * to get the longest name supported. 
     
    15541554 
    15551555        /* Create semaphore */ 
    1556         sem->sem = sem_open(sem_name, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR,  
     1556        sem->sem = sem_open(sem_name, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR, 
    15571557                            initial); 
    15581558        if (sem->sem == SEM_FAILED) 
     
    15641564#else 
    15651565    sem->sem = PJ_POOL_ALLOC_T(pool, sem_t); 
    1566     if (sem_init( sem->sem, 0, initial) != 0)  
     1566    if (sem_init( sem->sem, 0, initial) != 0) 
    15671567        return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 
    15681568#endif 
    1569      
     1569 
    15701570    /* Set name. */ 
    15711571    if (!name) { 
     
    16001600    PJ_ASSERT_RETURN(sem, PJ_EINVAL); 
    16011601 
    1602     PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s is waiting",  
     1602    PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s is waiting", 
    16031603                              pj_thread_this()->obj_name)); 
    16041604 
    16051605    result = sem_wait( sem->sem ); 
    1606      
     1606 
    16071607    if (result == 0) { 
    1608         PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s",  
     1608        PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s", 
    16091609                                  pj_thread_this()->obj_name)); 
    16101610    } else { 
    1611         PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s FAILED to acquire",  
     1611        PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s FAILED to acquire", 
    16121612                                  pj_thread_this()->obj_name)); 
    16131613    } 
     
    16351635 
    16361636    result = sem_trywait( sem->sem ); 
    1637      
     1637 
    16381638    if (result == 0) { 
    1639         PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s",  
     1639        PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s", 
    16401640                                  pj_thread_this()->obj_name)); 
    1641     }  
     1641    } 
    16421642    if (result == 0) 
    16431643        return PJ_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.