2017-01-06 07:10:15 +00:00
|
|
|
/*
|
2007-03-29 22:34:40 +00:00
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2014-02-05 21:02:28 +00:00
|
|
|
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-29 22:34:40 +00:00
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-29 22:34:40 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2017-01-06 07:10:15 +00:00
|
|
|
*
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2007-03-29 22:34:40 +00:00
|
|
|
* Michael Jerris <mike@jerris.com>
|
|
|
|
* Paul D. Tinsley <pdt at jackhammer.org>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* switch_core_rwlock.c -- Main Core Library (read / write locks)
|
|
|
|
*
|
|
|
|
*/
|
2008-01-27 17:36:53 +00:00
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
#include <switch.h>
|
2007-05-14 17:10:46 +00:00
|
|
|
#include "private/switch_core_pvt.h"
|
2007-03-29 22:34:40 +00:00
|
|
|
|
2008-02-26 16:55:40 +00:00
|
|
|
|
2010-11-30 21:34:22 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_session_io_read_lock(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
if (session->io_rwlock) {
|
|
|
|
if (switch_thread_rwlock_tryrdlock(session->io_rwlock) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_session_io_write_lock(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
if (session->io_rwlock) {
|
|
|
|
switch_thread_rwlock_wrlock(session->io_rwlock);
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_session_io_rwunlock(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
if (session->io_rwlock) {
|
|
|
|
switch_thread_rwlock_unlock(session->io_rwlock);
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
#ifdef SWITCH_DEBUG_RWLOCKS
|
2007-03-30 00:13:31 +00:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock(switch_core_session_t *session, const char *file, const char *func, int line)
|
2007-03-29 22:34:40 +00:00
|
|
|
#else
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(switch_core_session_t *session)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
if (session->rwlock) {
|
2011-11-18 19:17:56 +00:00
|
|
|
if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_down_nosig(session->channel)) {
|
2007-03-29 22:34:40 +00:00
|
|
|
status = SWITCH_STATUS_FALSE;
|
2010-01-22 00:51:32 +00:00
|
|
|
if (switch_thread_rwlock_tryrdlock(session->rwlock) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
if (switch_channel_test_flag(session->channel, CF_THREAD_SLEEPING)) {
|
|
|
|
#ifdef SWITCH_DEBUG_RWLOCKS
|
2010-05-06 16:38:36 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_ERROR, "%s %s Ping thread\n",
|
|
|
|
switch_core_session_get_uuid(session), switch_channel_get_name(session->channel));
|
2010-01-22 00:51:32 +00:00
|
|
|
#endif
|
|
|
|
switch_core_session_wake_session_thread(session);
|
|
|
|
}
|
|
|
|
switch_thread_rwlock_unlock(session->rwlock);
|
|
|
|
}
|
2007-03-29 22:34:40 +00:00
|
|
|
#ifdef SWITCH_DEBUG_RWLOCKS
|
2010-05-06 16:38:36 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_ERROR, "%s %s Read lock FAIL\n",
|
|
|
|
switch_core_session_get_uuid(session), switch_channel_get_name(session->channel));
|
2007-03-29 22:34:40 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock);
|
|
|
|
#ifdef SWITCH_DEBUG_RWLOCKS
|
2010-05-06 16:38:36 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_ERROR, "%s %s Read lock ACQUIRED\n",
|
|
|
|
switch_core_session_get_uuid(session), switch_channel_get_name(session->channel));
|
2007-03-29 22:34:40 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-11-20 02:27:59 +00:00
|
|
|
|
|
|
|
#ifdef SWITCH_DEBUG_RWLOCKS
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock_hangup(switch_core_session_t *session, const char *file, const char *func, int line)
|
|
|
|
#else
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock_hangup(switch_core_session_t *session)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
|
|
|
|
if (session->rwlock) {
|
2009-04-10 17:43:18 +00:00
|
|
|
if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_get_state(session->channel) >= CS_DESTROY) {
|
2008-11-20 02:27:59 +00:00
|
|
|
status = SWITCH_STATUS_FALSE;
|
|
|
|
#ifdef SWITCH_DEBUG_RWLOCKS
|
2010-05-06 16:38:36 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_ERROR, "%s %s Read lock FAIL\n",
|
|
|
|
switch_core_session_get_uuid(session), switch_channel_get_name(session->channel));
|
2008-11-20 02:27:59 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock);
|
|
|
|
#ifdef SWITCH_DEBUG_RWLOCKS
|
2010-05-06 16:38:36 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_ERROR, "%s %s Read lock ACQUIRED\n",
|
|
|
|
switch_core_session_get_uuid(session), switch_channel_get_name(session->channel));
|
2008-11-20 02:27:59 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-03-29 22:34:40 +00:00
|
|
|
#ifdef SWITCH_DEBUG_RWLOCKS
|
2007-03-30 00:13:31 +00:00
|
|
|
SWITCH_DECLARE(void) switch_core_session_perform_write_lock(switch_core_session_t *session, const char *file, const char *func, int line)
|
2007-03-29 22:34:40 +00:00
|
|
|
{
|
|
|
|
|
2010-05-06 16:38:36 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_ERROR, "%s %s Write lock ACQUIRED\n",
|
|
|
|
switch_core_session_get_uuid(session), switch_channel_get_name(session->channel));
|
2007-03-29 22:34:40 +00:00
|
|
|
#else
|
|
|
|
SWITCH_DECLARE(void) switch_core_session_write_lock(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
switch_thread_rwlock_wrlock(session->rwlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SWITCH_DEBUG_RWLOCKS
|
2007-03-30 00:13:31 +00:00
|
|
|
SWITCH_DECLARE(void) switch_core_session_perform_rwunlock(switch_core_session_t *session, const char *file, const char *func, int line)
|
2007-03-29 22:34:40 +00:00
|
|
|
{
|
2010-05-06 16:38:36 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_ERROR, "%s %s Read/Write lock CLEARED\n",
|
|
|
|
switch_core_session_get_uuid(session), switch_channel_get_name(session->channel));
|
2007-03-29 22:34:40 +00:00
|
|
|
#else
|
|
|
|
SWITCH_DECLARE(void) switch_core_session_rwunlock(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
switch_thread_rwlock_unlock(session->rwlock);
|
|
|
|
|
|
|
|
}
|
2008-01-27 05:02:52 +00:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 22:14:57 +00:00
|
|
|
* indent-tabs-mode:t
|
2008-01-27 05:02:52 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2013-06-25 16:50:17 +00:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
2008-01-27 05:02:52 +00:00
|
|
|
*/
|