Ignore:
Timestamp:
Dec 9, 2011 5:15:39 AM (12 years ago)
Author:
ming
Message:

Re #1420: Create a pool for the event manager so subscriber doesn't need to supply its own pool.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/event.c

    r3899 r3905  
    5050struct pjmedia_event_mgr 
    5151{ 
     52    pj_pool_t      *pool; 
    5253    pj_thread_t    *thread;             /**< worker thread.             */ 
    5354    pj_bool_t       is_quitting; 
     
    5758    event_queue    *pub_ev_queue;       /**< publish() event queue.     */ 
    5859    esub            esub_list;          /**< list of subscribers.       */ 
     60    esub            free_esub_list;     /**< list of subscribers.       */ 
    5961    esub           *th_next_sub,        /**< worker thread's next sub.  */ 
    6062                   *pub_next_sub;       /**< publish() next sub.        */ 
     
    155157 
    156158    mgr = PJ_POOL_ZALLOC_T(pool, pjmedia_event_mgr); 
     159    mgr->pool = pj_pool_create(pool->factory, "evt mgr", 500, 500, NULL); 
    157160    pj_list_init(&mgr->esub_list); 
     161    pj_list_init(&mgr->free_esub_list); 
    158162 
    159163    if (!(options & PJMEDIA_EVENT_MGR_NO_THREAD)) { 
    160         status = pj_sem_create(pool, "ev_sem", 0, MAX_EVENTS + 1, &mgr->sem); 
     164        status = pj_sem_create(mgr->pool, "ev_sem", 0, MAX_EVENTS + 1, 
     165                               &mgr->sem); 
    161166        if (status != PJ_SUCCESS) 
    162167            return status; 
    163168 
    164         status = pj_thread_create(pool, "ev_thread", &event_worker_thread, 
     169        status = pj_thread_create(mgr->pool, "ev_thread", 
     170                                  &event_worker_thread, 
    165171                                  mgr, 0, 0, &mgr->thread); 
    166172        if (status != PJ_SUCCESS) { 
     
    170176    } 
    171177 
    172     status = pj_mutex_create_recursive(pool, "ev_mutex", &mgr->mutex); 
     178    status = pj_mutex_create_recursive(mgr->pool, "ev_mutex", &mgr->mutex); 
    173179    if (status != PJ_SUCCESS) { 
    174180        pjmedia_event_mgr_destroy(mgr); 
     
    197203PJ_DEF(void) pjmedia_event_mgr_destroy(pjmedia_event_mgr *mgr) 
    198204{ 
    199     esub *sub; 
    200  
    201205    if (!mgr) mgr = pjmedia_event_mgr_instance(); 
    202206    PJ_ASSERT_ON_FAIL(mgr != NULL, return); 
     
    218222    } 
    219223 
    220     sub = mgr->esub_list.next; 
    221     while (sub != &mgr->esub_list) { 
    222         esub *next = sub->next; 
    223         pj_list_erase(sub); 
    224         sub = next; 
    225     } 
     224    if (mgr->pool) 
     225        pj_pool_release(mgr->pool); 
    226226 
    227227    if (event_manager_instance == mgr) 
     
    242242 
    243243PJ_DEF(pj_status_t) pjmedia_event_subscribe( pjmedia_event_mgr *mgr, 
    244                                              pj_pool_t *pool, 
    245244                                             pjmedia_event_cb *cb, 
    246245                                             void *user_data, 
     
    249248    esub *sub; 
    250249 
    251     PJ_ASSERT_RETURN(pool && cb, PJ_EINVAL); 
     250    PJ_ASSERT_RETURN(cb, PJ_EINVAL); 
    252251 
    253252    if (!mgr) mgr = pjmedia_event_mgr_instance(); 
     
    271270    } 
    272271 
    273     sub = PJ_POOL_ZALLOC_T(pool, esub); 
     272    if (mgr->free_esub_list.next != &mgr->free_esub_list) { 
     273        sub = mgr->free_esub_list.next; 
     274        pj_list_erase(sub); 
     275    } else 
     276        sub = PJ_POOL_ZALLOC_T(mgr->pool, esub); 
    274277    sub->cb = cb; 
    275278    sub->user_data = user_data; 
     
    310313                mgr->pub_next_sub = sub->next; 
    311314            pj_list_erase(sub); 
     315            pj_list_push_back(&mgr->free_esub_list, sub); 
    312316            if (user_data && epub) 
    313317                break; 
Note: See TracChangeset for help on using the changeset viewer.