Ignore:
Timestamp:
Mar 1, 2013 3:46:45 AM (11 years ago)
Author:
nanang
Message:

Re 1394 and re #1531: backported to 1.x

Location:
pjproject/branches/1.x
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.x

  • pjproject/branches/1.x/pjmedia/src/pjmedia/clock_thread.c

    r3553 r4410  
    3232struct pjmedia_clock 
    3333{ 
     34    pj_pool_t               *pool; 
    3435    pj_timestamp             freq; 
    3536    pj_timestamp             interval; 
     
    7172 
    7273    clock = PJ_POOL_ALLOC_T(pool, pjmedia_clock); 
    73  
    74      
     74    clock->pool = pj_pool_create(pool->factory, "clock%p", 512, 512, NULL); 
     75 
    7576    status = pj_get_timestamp_freq(&clock->freq); 
    7677    if (status != PJ_SUCCESS) 
     
    9596        return status; 
    9697 
    97     if ((clock->options & PJMEDIA_CLOCK_NO_ASYNC) == 0) { 
    98         status = pj_thread_create(pool, "clock", &clock_thread, clock, 
    99                                   0, 0, &clock->thread); 
    100         if (status != PJ_SUCCESS) { 
    101             pj_lock_destroy(clock->lock); 
    102             return status; 
    103         } 
    104     } 
    105  
    106  
    10798    *p_clock = clock; 
    10899 
     
    128119        return status; 
    129120 
    130     pj_lock_acquire(clock->lock); 
    131121    clock->next_tick.u64 = now.u64 + clock->interval.u64; 
    132122    clock->running = PJ_TRUE; 
    133     pj_lock_release(clock->lock); 
    134  
    135     return status; 
     123    clock->quitting = PJ_FALSE; 
     124 
     125    if ((clock->options & PJMEDIA_CLOCK_NO_ASYNC) == 0 && !clock->thread) { 
     126        status = pj_thread_create(clock->pool, "clock", &clock_thread, clock, 
     127                                  0, 0, &clock->thread); 
     128        if (status != PJ_SUCCESS) { 
     129            clock->running = PJ_FALSE; 
     130            return status; 
     131        } 
     132    } 
     133 
     134    return PJ_SUCCESS; 
    136135} 
    137136 
     
    145144 
    146145    clock->running = PJ_FALSE; 
     146    clock->quitting = PJ_TRUE; 
     147 
     148    if (clock->thread) { 
     149        if (pj_thread_join(clock->thread) == PJ_SUCCESS) { 
     150            pj_thread_destroy(clock->thread); 
     151            clock->thread = NULL; 
     152            pj_pool_reset(clock->pool); 
     153        } else { 
     154            clock->quitting = PJ_FALSE; 
     155        } 
     156    } 
    147157 
    148158    return PJ_SUCCESS; 
     
    255265            (*clock->cb)(&clock->timestamp, clock->user_data); 
    256266 
     267        /* Best effort way to detect if we've been destroyed in the callback */ 
     268        if (clock->quitting) 
     269            break; 
     270 
    257271        /* Increment timestamp */ 
    258272        clock->timestamp.u64 += clock->timestamp_inc; 
     
    289303    } 
    290304 
     305    if (clock->pool) { 
     306        pj_pool_t *pool = clock->pool; 
     307        clock->pool = NULL; 
     308        pj_pool_release(pool); 
     309    } 
    291310    return PJ_SUCCESS; 
    292311} 
Note: See TracChangeset for help on using the changeset viewer.