/* * pj_ioqueue_destroy() * * Destroy ioqueue. */ PJ_DEF(pj_status_t) pj_ioqueue_destroy(pj_ioqueue_t *ioqueue) { pj_ioqueue_key_t *key; PJ_ASSERT_RETURN(ioqueue, PJ_EINVAL); pj_lock_acquire(ioqueue->lock); #if PJ_IOQUEUE_HAS_SAFE_UNREG /* Destroy reference counters */ key = ioqueue->active_list.next; while (key != &ioqueue->active_list) { pj_mutex_destroy(key->mutex); key = key->next; } key = ioqueue->closing_list.next; while (key != &ioqueue->closing_list) { pj_mutex_destroy(key->mutex); key = key->next; } key = ioqueue->free_list.next; while (key != &ioqueue->free_list) { pj_mutex_destroy(key->mutex); key = key->next; } pj_mutex_destroy(ioqueue->ref_cnt_mutex); #endif return ioqueue_destroy(ioqueue); }
/* * pj_ioqueue_destroy() */ PJ_DEF(pj_status_t) pj_ioqueue_destroy( pj_ioqueue_t *ioqueue ) { #if PJ_HAS_TCP unsigned i; #endif pj_ioqueue_key_t *key; PJ_CHECK_STACK(); PJ_ASSERT_RETURN(ioqueue, PJ_EINVAL); pj_lock_acquire(ioqueue->lock); #if PJ_HAS_TCP /* Destroy events in the pool */ for (i=0; i<ioqueue->event_count; ++i) { CloseHandle(ioqueue->event_pool[i]); } ioqueue->event_count = 0; #endif if (CloseHandle(ioqueue->iocp) != TRUE) return PJ_RETURN_OS_ERROR(GetLastError()); #if PJ_IOQUEUE_HAS_SAFE_UNREG /* Destroy reference counters */ key = ioqueue->active_list.next; while (key != &ioqueue->active_list) { pj_atomic_destroy(key->ref_count); pj_mutex_destroy(key->mutex); key = key->next; } key = ioqueue->closing_list.next; while (key != &ioqueue->closing_list) { pj_atomic_destroy(key->ref_count); pj_mutex_destroy(key->mutex); key = key->next; } key = ioqueue->free_list.next; while (key != &ioqueue->free_list) { pj_atomic_destroy(key->ref_count); pj_mutex_destroy(key->mutex); key = key->next; } #endif if (ioqueue->auto_delete_lock) pj_lock_destroy(ioqueue->lock); return PJ_SUCCESS; }
static pj_status_t job_queue_destroy(job_queue *jq) { unsigned i; jq->is_quitting = PJ_TRUE; if (jq->thread) { pj_sem_post(jq->sem); pj_thread_join(jq->thread); pj_thread_destroy(jq->thread); } if (jq->sem) { pj_sem_destroy(jq->sem); jq->sem = NULL; } for (i = 0; i < jq->size; i++) { if (jq->job_sem[i]) { pj_sem_destroy(jq->job_sem[i]); jq->job_sem[i] = NULL; } } if (jq->mutex) { pj_mutex_destroy(jq->mutex); jq->mutex = NULL; } return PJ_SUCCESS; }
/* * pj_shutdown(void) */ PJ_DEF(void) pj_shutdown() { int i; /* Call atexit() functions */ for (i=atexit_count-1; i>=0; --i) { (*atexit_func[i])(); } atexit_count = 0; /* Free exception ID */ if (PJ_NO_MEMORY_EXCEPTION != -1) { pj_exception_id_free(PJ_NO_MEMORY_EXCEPTION); PJ_NO_MEMORY_EXCEPTION = -1; } #if PJ_HAS_THREADS /* Destroy PJLIB critical section */ pj_mutex_destroy(&critical_section); /* Free PJLIB TLS */ if (thread_tls_id != -1) { pj_thread_local_free(thread_tls_id); thread_tls_id = -1; } #endif /* Clear static variables */ pj_errno_clear_handlers(); }
PJ_DEF(void) pjmedia_event_mgr_destroy(pjmedia_event_mgr *mgr) { if (!mgr) mgr = pjmedia_event_mgr_instance(); PJ_ASSERT_ON_FAIL(mgr != NULL, return); if (mgr->thread) { mgr->is_quitting = PJ_TRUE; pj_sem_post(mgr->sem); pj_thread_join(mgr->thread); } if (mgr->sem) { pj_sem_destroy(mgr->sem); mgr->sem = NULL; } if (mgr->mutex) { pj_mutex_destroy(mgr->mutex); mgr->mutex = NULL; } if (mgr->pool) pj_pool_release(mgr->pool); if (event_manager_instance == mgr) event_manager_instance = NULL; }
// // Destroy mutex. // void destroy() { if (mutex_) { pj_mutex_destroy(mutex_); mutex_ = NULL; } }
/* * Destroy reader/writer mutex. * */ PJ_DEF(pj_status_t) pj_rwmutex_destroy(pj_rwmutex_t *mutex) { PJ_ASSERT_RETURN(mutex, PJ_EINVAL); pj_mutex_destroy(mutex->read_lock); pj_sem_destroy(mutex->write_lock); return PJ_SUCCESS; }
/* * Unregister G722 codec factory from pjmedia endpoint and deinitialize * the G722 codec library. */ PJ_DEF(pj_status_t) pjmedia_codec_g722_deinit(void) { pjmedia_codec_mgr *codec_mgr; pj_status_t status; if (g722_codec_factory.pool == NULL) return PJ_SUCCESS; /* Get the codec manager. */ codec_mgr = pjmedia_endpt_get_codec_mgr(g722_codec_factory.endpt); if (!codec_mgr) { pj_pool_release(g722_codec_factory.pool); g722_codec_factory.pool = NULL; return PJ_EINVALIDOP; } /* Unregister G722 codec factory. */ status = pjmedia_codec_mgr_unregister_factory(codec_mgr, &g722_codec_factory.base); /* Destroy mutex. */ pj_mutex_destroy(g722_codec_factory.mutex); /* Destroy pool. */ pj_pool_release(g722_codec_factory.pool); g722_codec_factory.pool = NULL; TRACE_((THIS_FILE, "G722 codec factory shutdown")); return status; }
/* * Module deinitialization. * Called by endpoint. */ static pj_status_t mod_deinit( struct pjsip_module *mod ) { pj_mutex_lock(mgr.mutex); pj_mutex_destroy(mgr.mutex); pjsip_endpt_destroy_pool(mgr.endpt, mgr.pool); return 0; }
/* * Unregister CODEC2 codec factory from pjmedia endpoint and deinitialize * the CODEC2 codec library. */ PJ_DEF(pj_status_t) pjmedia_codec_codec2_deinit(void) { pjmedia_codec_mgr *codec_mgr; pj_status_t status; if (codec2_codec_factory.pool == NULL) return PJ_SUCCESS; /* Get the codec manager. */ codec_mgr = pjmedia_endpt_get_codec_mgr(codec2_codec_factory.endpt); if (!codec_mgr) { pj_pool_release(codec2_codec_factory.pool); codec2_codec_factory.pool = NULL; return PJ_EINVALIDOP; } /* Unregister GSM codec factory. */ status = pjmedia_codec_mgr_unregister_factory(codec_mgr, &codec2_codec_factory.base); /* Destroy mutex. */ pj_mutex_destroy(codec2_codec_factory.mutex); /* Destroy pool. */ pj_pool_release(codec2_codec_factory.pool); codec2_codec_factory.pool = NULL; return status; }
*/ PJ_DEF(pj_status_t) pjmedia_codec_opus_deinit(void) { pjmedia_codec_mgr *codec_mgr; pj_status_t status; if (opus_factory.endpt == NULL) { /* Not registered. */ return PJ_SUCCESS; } /* Lock mutex. */ pj_mutex_lock(opus_factory.mutex); /* Get the codec manager. */ codec_mgr = pjmedia_endpt_get_codec_mgr(opus_factory.endpt); if (!codec_mgr) { opus_factory.endpt = NULL; pj_mutex_unlock(opus_factory.mutex); return PJ_EINVALIDOP; } /* Unregister opus codec factory. */ status = pjmedia_codec_mgr_unregister_factory(codec_mgr, &opus_factory.base); opus_factory.endpt = NULL; /* Destroy mutex. */ pj_mutex_destroy(opus_factory.mutex); opus_factory.mutex = NULL; /* Release pool. */ pj_pool_release(opus_factory.pool); opus_factory.pool = NULL; return status; }
/* * destroy() is called when the transport is no longer needed. */ static pj_status_t transport_destroy(pjmedia_transport *tp) { struct tp_zrtp *zrtp = (struct tp_zrtp*)tp; PJ_ASSERT_RETURN(tp, PJ_EINVAL); PJ_LOG(4, (THIS_FILE, "Destroy - encrypted packets: %ld, decrypted packets: %ld", zrtp->protect, zrtp->unprotect)); /* close the slave transport in case */ if (zrtp->close_slave && zrtp->slave_tp) { pjmedia_transport_close(zrtp->slave_tp); } /* Self destruct.. */ zrtp_DestroyWrapper(zrtp->zrtpCtx); /* In case mutex is being acquired by other thread */ pj_mutex_lock(zrtp->zrtpMutex); pj_mutex_unlock(zrtp->zrtpMutex); pj_mutex_destroy(zrtp->zrtpMutex); pj_pool_release(zrtp->pool); return PJ_SUCCESS; }
static void on_read_complete(pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, pj_ssize_t bytes_read) { pj_ssize_t size; char *sendbuf = "Hello world"; pj_status_t status; if (sock_data.unregistered) return; pj_mutex_lock(sock_data.mutex); if (sock_data.unregistered) { pj_mutex_unlock(sock_data.mutex); return; } if (bytes_read < 0) { if (-bytes_read != PJ_STATUS_FROM_OS(PJ_BLOCKING_ERROR_VAL)) app_perror("ioqueue reported recv error", -bytes_read); } else { sock_data.received += bytes_read; } if (test_method == UNREGISTER_IN_CALLBACK) { pj_time_val now; pj_gettimeofday(&now); if (PJ_TIME_VAL_GTE(now, time_to_unregister)) { sock_data.unregistered = 1; pj_ioqueue_unregister(key); pj_mutex_destroy(sock_data.mutex); pj_pool_release(sock_data.pool); sock_data.pool = NULL; return; } } do { size = sock_data.bufsize; status = pj_ioqueue_recv(key, op_key, sock_data.buffer, &size, 0); if (status != PJ_EPENDING && status != PJ_SUCCESS) app_perror("recv() error", status); } while (status == PJ_SUCCESS); pj_mutex_unlock(sock_data.mutex); size = pj_ansi_strlen(sendbuf); status = pj_sock_send(sock_data.csock, sendbuf, &size, 0); if (status != PJ_SUCCESS) app_perror("send() error", status); size = pj_ansi_strlen(sendbuf); status = pj_sock_send(sock_data.csock, sendbuf, &size, 0); if (status != PJ_SUCCESS) app_perror("send() error", status); }
/* * Create reader/writer mutex. * */ PJ_DEF(pj_status_t) pj_rwmutex_create(pj_pool_t *pool, const char *name, pj_rwmutex_t **p_mutex) { pj_status_t status; pj_rwmutex_t *rwmutex; PJ_ASSERT_RETURN(pool && p_mutex, PJ_EINVAL); *p_mutex = NULL; rwmutex = PJ_POOL_ALLOC_T(pool, pj_rwmutex_t); status = pj_mutex_create_simple(pool, name, &rwmutex ->read_lock); if (status != PJ_SUCCESS) return status; status = pj_sem_create(pool, name, 1, 1, &rwmutex->write_lock); if (status != PJ_SUCCESS) { pj_mutex_destroy(rwmutex->read_lock); return status; } rwmutex->reader_count = 0; *p_mutex = rwmutex; return PJ_SUCCESS; }
PJ_DEF(pj_status_t) pj_atomic_destroy( pj_atomic_t *atomic_var ) { #if PJ_HAS_THREADS return pj_mutex_destroy( atomic_var->mutex ); #else return 0; #endif }
/* * pj_ioqueue_unregister() * * Unregister handle from ioqueue. */ PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key) { pj_ioqueue_t *ioqueue; PJ_ASSERT_RETURN(key, PJ_EINVAL); ioqueue = key->ioqueue; /* Lock the key to make sure no callback is simultaneously modifying * the key. We need to lock the key before ioqueue here to prevent * deadlock. */ pj_mutex_lock(key->mutex); /* Also lock ioqueue */ pj_lock_acquire(ioqueue->lock); pj_assert(ioqueue->count > 0); --ioqueue->count; #if !PJ_IOQUEUE_HAS_SAFE_UNREG /* Ticket #520, key will be erased more than once */ pj_list_erase(key); #endif PJ_FD_CLR(key->fd, &ioqueue->rfdset); PJ_FD_CLR(key->fd, &ioqueue->wfdset); #if PJ_HAS_TCP PJ_FD_CLR(key->fd, &ioqueue->xfdset); #endif /* Close socket. */ pj_sock_close(key->fd); /* Clear callback */ key->cb.on_accept_complete = NULL; key->cb.on_connect_complete = NULL; key->cb.on_read_complete = NULL; key->cb.on_write_complete = NULL; /* Must release ioqueue lock first before decrementing counter, to * prevent deadlock. */ pj_lock_release(ioqueue->lock); #if PJ_IOQUEUE_HAS_SAFE_UNREG /* Mark key is closing. */ key->closing = 1; /* Decrement counter. */ decrement_counter(key); /* Done. */ pj_mutex_unlock(key->mutex); #else pj_mutex_destroy(key->mutex); #endif return PJ_SUCCESS; }
/* * Destroy stream. */ PJ_DEF(pj_status_t) pjmedia_natnl_stream_destroy( natnl_stream *stream ) { PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL); /** * don't need to destroy mutex here, * after stream destroy, the mutex will also be freed */ #if 0 /* Free mutex */ if (stream->gcbuff_mutex) { pj_mutex_destroy(stream->gcbuff_mutex); stream->gcbuff_mutex = NULL; } if (stream->rbuff_mutex) { pj_mutex_destroy(stream->rbuff_mutex); stream->rbuff_mutex = NULL; } if (stream->sbuff_mutex) { pj_mutex_destroy(stream->sbuff_mutex); stream->sbuff_mutex = NULL; } #endif #if 1 // DEAN don't release pool hear, let pjsip to release it. if (stream->own_pool) { //pj_pool_release(stream->own_pool); stream->own_pool = NULL; } #endif if (stream->rx_band) { free(stream->rx_band); stream->rx_band = NULL; } if (stream->tx_band) { free(stream->tx_band); stream->tx_band = NULL; } return PJ_SUCCESS; }
PJ_DEF(pj_status_t) pjmedia_codec_opus_init(pjmedia_endpt *endpt) { pjmedia_codec_mgr *codec_mgr; pj_status_t status; if (opus_factory.endpt != NULL) { /* Already initialized. */ return PJ_SUCCESS; } /* Init factory */ opus_factory.base.op = &opus_factory_op; opus_factory.base.factory_data = NULL; opus_factory.endpt = endpt; if (opus_factory.internal_clock_rate == 0) { opus_factory.internal_clock_rate = 48000; } /* Create pool */ opus_factory.pool = pjmedia_endpt_create_pool(endpt, "opus codecs", 4000, 4000); if (!opus_factory.pool) return PJ_ENOMEM; /* Init list */ pj_list_init(&opus_factory.codec_list); /* Create mutex. */ status = pj_mutex_create_simple(opus_factory.pool, "opus codecs", &opus_factory.mutex); if (status != PJ_SUCCESS) goto on_error; PJ_LOG(5, (THIS_FILE, "Init opus")); /* Get the codec manager. */ codec_mgr = pjmedia_endpt_get_codec_mgr(endpt); if (!codec_mgr) { return PJ_EINVALIDOP; } PJ_LOG(5, (THIS_FILE, "Init opus > DONE")); /* Register codec factory to endpoint. */ status = pjmedia_codec_mgr_register_factory(codec_mgr, &opus_factory.base); if (status != PJ_SUCCESS) return status; return PJ_SUCCESS; on_error: if (opus_factory.mutex) { pj_mutex_destroy(opus_factory.mutex); opus_factory.mutex = NULL; } if (opus_factory.pool) { pj_pool_release(opus_factory.pool); opus_factory.pool = NULL; } return status; }
PJ_DEF(pj_status_t) pjmedia_codec_l16_init(pjmedia_endpt *endpt, unsigned options) { pjmedia_codec_mgr *codec_mgr; pj_status_t status; PJ_UNUSED_ARG(options); if (l16_factory.endpt != NULL) { /* Already initialized. */ return PJ_SUCCESS; } /* Init factory */ l16_factory.base.op = &l16_factory_op; l16_factory.base.factory_data = NULL; l16_factory.endpt = endpt; /* Create pool */ l16_factory.pool = pjmedia_endpt_create_pool(endpt, "l16", 4000, 4000); if (!l16_factory.pool) return PJ_ENOMEM; /* Create mutex. */ status = pj_mutex_create_simple(l16_factory.pool, "l16", &l16_factory.mutex); if (status != PJ_SUCCESS) goto on_error; /* Get the codec manager. */ codec_mgr = pjmedia_endpt_get_codec_mgr(endpt); if (!codec_mgr) { return PJ_EINVALIDOP; } /* Register codec factory to endpoint. */ status = pjmedia_codec_mgr_register_factory(codec_mgr, &l16_factory.base); if (status != PJ_SUCCESS) return status; return PJ_SUCCESS; on_error: if (l16_factory.mutex) { pj_mutex_destroy(l16_factory.mutex); l16_factory.mutex = NULL; } if (l16_factory.pool) { pj_pool_release(l16_factory.pool); l16_factory.pool = NULL; } return status; }
/* * pj_atomic_destroy() */ PJ_DEF(pj_status_t) pj_atomic_destroy( pj_atomic_t *atomic_var ) { PJ_ASSERT_RETURN(atomic_var, PJ_EINVAL); #if PJ_HAS_THREADS return pj_mutex_destroy( atomic_var->mutex ); #else return 0; #endif }
/* * pj_ioqueue_unregister() * * Unregister handle from ioqueue. */ PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key) { pj_ioqueue_t *ioqueue; struct epoll_event ev; int status; PJ_ASSERT_RETURN(key != NULL, PJ_EINVAL); ioqueue = key->ioqueue; /* Lock the key to make sure no callback is simultaneously modifying * the key. We need to lock the key before ioqueue here to prevent * deadlock. */ pj_mutex_lock(key->mutex); /* Also lock ioqueue */ pj_lock_acquire(ioqueue->lock); pj_assert(ioqueue->count > 0); --ioqueue->count; #if !PJ_IOQUEUE_HAS_SAFE_UNREG pj_list_erase(key); #endif ev.events = 0; ev.epoll_data = (epoll_data_type)key; status = os_epoll_ctl( ioqueue->epfd, EPOLL_CTL_DEL, key->fd, &ev); if (status != 0) { pj_status_t rc = pj_get_os_error(); pj_lock_release(ioqueue->lock); return rc; } /* Destroy the key. */ pj_sock_close(key->fd); pj_lock_release(ioqueue->lock); #if PJ_IOQUEUE_HAS_SAFE_UNREG /* Mark key is closing. */ key->closing = 1; /* Decrement counter. */ decrement_counter(key); /* Done. */ pj_mutex_unlock(key->mutex); #else pj_mutex_destroy(key->mutex); #endif return PJ_SUCCESS; }
/* * pj_thread_destroy() */ PJ_DEF(pj_status_t) pj_thread_destroy(pj_thread_t *p) { PJ_CHECK_STACK(); /* Destroy mutex used to suspend thread */ if (p->suspended_mutex) { pj_mutex_destroy(p->suspended_mutex); p->suspended_mutex = NULL; } /* Destroy mutex used to wait thread */ if (p->wait_mutex) { pj_mutex_destroy(p->wait_mutex); p->wait_mutex = NULL; } return PJ_SUCCESS; }
PJ_DEF(pj_status_t) pjmedia_codec_g711_init(pjmedia_endpt *endpt) { pjmedia_codec_mgr *codec_mgr; pj_status_t status; if (g711_factory.endpt != NULL) { /* Already initialized. */ return PJ_SUCCESS; } /* Init factory */ g711_factory.base.op = &g711_factory_op; g711_factory.base.factory_data = NULL; g711_factory.endpt = endpt; pj_list_init(&g711_factory.codec_list); /* Create pool */ g711_factory.pool = pjmedia_endpt_create_pool(endpt, "g711", 4000, 4000); if (!g711_factory.pool) return PJ_ENOMEM; /* Create mutex. */ status = pj_mutex_create_simple(g711_factory.pool, "g611", &g711_factory.mutex); if (status != PJ_SUCCESS) goto on_error; /* Get the codec manager. */ codec_mgr = pjmedia_endpt_get_codec_mgr(endpt); if (!codec_mgr) { return PJ_EINVALIDOP; } /* Register codec factory to endpoint. */ status = pjmedia_codec_mgr_register_factory(codec_mgr, &g711_factory.base); if (status != PJ_SUCCESS) return status; return PJ_SUCCESS; on_error: if (g711_factory.mutex) { pj_mutex_destroy(g711_factory.mutex); g711_factory.mutex = NULL; } if (g711_factory.pool) { pj_pool_release(g711_factory.pool); g711_factory.pool = NULL; } return status; }
/* * mod_ua_unload() * * Called when module is being unloaded. */ static pj_status_t mod_ua_unload(void) { pj_thread_local_free(pjsip_dlg_lock_tls_id); pj_mutex_destroy(mod_ua.mutex); /* Release pool */ if (mod_ua.pool) { pjsip_endpt_release_pool( mod_ua.endpt, mod_ua.pool ); } return PJ_SUCCESS; }
PJ_DEF(pj_status_t) pjsip_publishc_create( pjsip_endpoint *endpt, const pjsip_publishc_opt *opt, void *token, pjsip_publishc_cb *cb, pjsip_publishc **p_pubc) { pj_pool_t *pool; pjsip_publishc *pubc; pjsip_publishc_opt default_opt; pj_status_t status; /* Verify arguments. */ PJ_ASSERT_RETURN(endpt && cb && p_pubc, PJ_EINVAL); pool = pjsip_endpt_create_pool(endpt, "pubc%p", 1024, 1024); PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM); pubc = PJ_POOL_ZALLOC_T(pool, pjsip_publishc); pubc->pool = pool; pubc->endpt = endpt; pubc->token = token; pubc->cb = cb; pubc->expires = PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED; if (!opt) { pjsip_publishc_opt_default(&default_opt); opt = &default_opt; } pj_memcpy(&pubc->opt, opt, sizeof(*opt)); pj_list_init(&pubc->pending_reqs); pj_list_init(&pubc->pending_reqs_empty); status = pj_mutex_create_recursive(pubc->pool, "pubc%p", &pubc->mutex); if (status != PJ_SUCCESS) { pj_pool_release(pool); return status; } status = pjsip_auth_clt_init(&pubc->auth_sess, endpt, pubc->pool, 0); if (status != PJ_SUCCESS) { pj_mutex_destroy(pubc->mutex); pj_pool_release(pool); return status; } pj_list_init(&pubc->route_set); pj_list_init(&pubc->usr_hdr); /* Done */ *p_pubc = pubc; return PJ_SUCCESS; }
/* Test witn non-recursive mutex. */ static int simple_mutex_test(pj_pool_t *pool) { pj_status_t rc; pj_mutex_t *mutex; PJ_LOG(3,("", "...testing simple mutex")); /* Create mutex. */ TRACE_(("", "....create mutex")); rc = pj_mutex_create( pool, "", PJ_MUTEX_SIMPLE, &mutex); if (rc != PJ_SUCCESS) { app_perror("...error: pj_mutex_create", rc); return -10; } /* Normal lock/unlock cycle. */ TRACE_(("", "....lock mutex")); rc = pj_mutex_lock(mutex); if (rc != PJ_SUCCESS) { app_perror("...error: pj_mutex_lock", rc); return -20; } TRACE_(("", "....unlock mutex")); rc = pj_mutex_unlock(mutex); if (rc != PJ_SUCCESS) { app_perror("...error: pj_mutex_unlock", rc); return -30; } /* Lock again. */ TRACE_(("", "....lock mutex")); rc = pj_mutex_lock(mutex); if (rc != PJ_SUCCESS) return -40; /* Try-lock should fail. It should not deadlocked. */ TRACE_(("", "....trylock mutex")); rc = pj_mutex_trylock(mutex); if (rc == PJ_SUCCESS) PJ_LOG(3,("", "...info: looks like simple mutex is recursive")); /* Unlock and done. */ TRACE_(("", "....unlock mutex")); rc = pj_mutex_unlock(mutex); if (rc != PJ_SUCCESS) return -50; TRACE_(("", "....destroy mutex")); rc = pj_mutex_destroy(mutex); if (rc != PJ_SUCCESS) return -60; TRACE_(("", "....done")); return PJ_SUCCESS; }
/* * pj_shutdown(void) */ PJ_DEF(void) pj_shutdown() { int i; /* Only perform shutdown operation when 'initialized' reaches zero */ pj_assert(initialized > 0); if (--initialized != 0) return; /* Display stack usage */ #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 { pj_thread_t *rec = (pj_thread_t*)main_thread; PJ_LOG(5,(rec->obj_name, "Main thread stack max usage=%u by %s:%d", rec->stk_max_usage, rec->caller_file, rec->caller_line)); } #endif /* Call atexit() functions */ for (i=atexit_count-1; i>=0; --i) { (*atexit_func[i])(); } atexit_count = 0; /* Free exception ID */ if (PJ_NO_MEMORY_EXCEPTION != -1) { pj_exception_id_free(PJ_NO_MEMORY_EXCEPTION); PJ_NO_MEMORY_EXCEPTION = -1; } /* Destroy PJLIB critical section */ pj_mutex_destroy(&critical_section_mutex); /* Free PJLIB TLS */ if (thread_tls_id != -1) { pj_thread_local_free(thread_tls_id); thread_tls_id = -1; } /* Clear static variables */ pj_errno_clear_handlers(); /* Ticket #1132: Assertion when (re)starting PJLIB on different thread */ pj_bzero(main_thread, sizeof(main_thread)); /* Shutdown Winsock */ WSACleanup(); }
SIPPresence::~SIPPresence() { /* Flush the lists */ // FIXME: Can't destroy/unsubscribe buddies properly. // Is the transport usable when the account is being destroyed? //for (const auto & c : sub_client_list_) // delete(c); sub_client_list_.clear(); sub_server_list_.clear(); if (mutex_ and pj_mutex_destroy(mutex_) != PJ_SUCCESS) ERROR("Error destroying mutex"); pj_pool_release(pool_); pj_caching_pool_destroy(&cp_); }
/* * Free codec. */ static pj_status_t factory_dealloc_codec( pjmedia_codec_factory *factory, pjmedia_codec *codec ) { struct opus_data *opus_data; PJ_ASSERT_RETURN(factory && codec, PJ_EINVAL); PJ_ASSERT_RETURN(factory == &opus_codec_factory.base, PJ_EINVAL); opus_data = (struct opus_data *)codec->codec_data; if (opus_data) { pj_mutex_destroy(opus_data->mutex); opus_data->mutex = NULL; pj_pool_release(opus_data->pool); } return PJ_SUCCESS; }
/* * Initialize codec manager. */ PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_destroy (pjmedia_vid_codec_mgr *mgr) { if (!mgr) mgr = def_vid_codec_mgr; PJ_ASSERT_RETURN(mgr, PJ_EINVAL); /* Destroy mutex */ if (mgr->mutex) pj_mutex_destroy(mgr->mutex); /* Just for safety, set codec manager states to zero */ pj_bzero(mgr, sizeof(pjmedia_vid_codec_mgr)); if (mgr == def_vid_codec_mgr) def_vid_codec_mgr = NULL; return PJ_SUCCESS; }