Changeset 3905 for pjproject/trunk/pjmedia/src/pjmedia/event.c
- Timestamp:
- Dec 9, 2011 5:15:39 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/event.c
r3899 r3905 50 50 struct pjmedia_event_mgr 51 51 { 52 pj_pool_t *pool; 52 53 pj_thread_t *thread; /**< worker thread. */ 53 54 pj_bool_t is_quitting; … … 57 58 event_queue *pub_ev_queue; /**< publish() event queue. */ 58 59 esub esub_list; /**< list of subscribers. */ 60 esub free_esub_list; /**< list of subscribers. */ 59 61 esub *th_next_sub, /**< worker thread's next sub. */ 60 62 *pub_next_sub; /**< publish() next sub. */ … … 155 157 156 158 mgr = PJ_POOL_ZALLOC_T(pool, pjmedia_event_mgr); 159 mgr->pool = pj_pool_create(pool->factory, "evt mgr", 500, 500, NULL); 157 160 pj_list_init(&mgr->esub_list); 161 pj_list_init(&mgr->free_esub_list); 158 162 159 163 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); 161 166 if (status != PJ_SUCCESS) 162 167 return status; 163 168 164 status = pj_thread_create(pool, "ev_thread", &event_worker_thread, 169 status = pj_thread_create(mgr->pool, "ev_thread", 170 &event_worker_thread, 165 171 mgr, 0, 0, &mgr->thread); 166 172 if (status != PJ_SUCCESS) { … … 170 176 } 171 177 172 status = pj_mutex_create_recursive( pool, "ev_mutex", &mgr->mutex);178 status = pj_mutex_create_recursive(mgr->pool, "ev_mutex", &mgr->mutex); 173 179 if (status != PJ_SUCCESS) { 174 180 pjmedia_event_mgr_destroy(mgr); … … 197 203 PJ_DEF(void) pjmedia_event_mgr_destroy(pjmedia_event_mgr *mgr) 198 204 { 199 esub *sub;200 201 205 if (!mgr) mgr = pjmedia_event_mgr_instance(); 202 206 PJ_ASSERT_ON_FAIL(mgr != NULL, return); … … 218 222 } 219 223 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); 226 226 227 227 if (event_manager_instance == mgr) … … 242 242 243 243 PJ_DEF(pj_status_t) pjmedia_event_subscribe( pjmedia_event_mgr *mgr, 244 pj_pool_t *pool,245 244 pjmedia_event_cb *cb, 246 245 void *user_data, … … 249 248 esub *sub; 250 249 251 PJ_ASSERT_RETURN( pool &&cb, PJ_EINVAL);250 PJ_ASSERT_RETURN(cb, PJ_EINVAL); 252 251 253 252 if (!mgr) mgr = pjmedia_event_mgr_instance(); … … 271 270 } 272 271 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); 274 277 sub->cb = cb; 275 278 sub->user_data = user_data; … … 310 313 mgr->pub_next_sub = sub->next; 311 314 pj_list_erase(sub); 315 pj_list_push_back(&mgr->free_esub_list, sub); 312 316 if (user_data && epub) 313 317 break;
Note: See TracChangeset
for help on using the changeset viewer.