RTS API Documentation  1.10.11
switch_core_rwlock.c
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  * Michael Jerris <mike@jerris.com>
28  * Paul D. Tinsley <pdt at jackhammer.org>
29  *
30  *
31  * switch_core_rwlock.c -- Main Core Library (read / write locks)
32  *
33  */
34 
35 #include <switch.h>
37 
38 
40 {
42 
43  if (session->io_rwlock) {
45  status = SWITCH_STATUS_SUCCESS;
46  }
47  }
48 
49  return status;
50 }
51 
53 {
55 
56  if (session->io_rwlock) {
58  status = SWITCH_STATUS_SUCCESS;
59  }
60 
61  return status;
62 }
63 
64 
66 {
68 
69  if (session->io_rwlock) {
71  status = SWITCH_STATUS_SUCCESS;
72  }
73 
74  return status;
75 }
76 
77 
78 
79 #ifdef SWITCH_DEBUG_RWLOCKS
80 SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock(switch_core_session_t *session, const char *file, const char *func, int line)
81 #else
83 #endif
84 {
86 
87  if (session->rwlock) {
88  if ((status = switch_thread_rwlock_tryrdlock(session->rwlock)) == SWITCH_STATUS_SUCCESS) {
90  status = SWITCH_STATUS_FALSE;
92 #ifdef SWITCH_DEBUG_RWLOCKS
93  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_ERROR, "%s %s Ping thread\n",
95 #endif
97  }
98 
99 #ifdef SWITCH_DEBUG_RWLOCKS
100  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",
102 #endif
104  } else {
105 #ifdef SWITCH_DEBUG_RWLOCKS
106  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",
108 #endif
109  }
110  }
111  }
112 
113  return status;
114 }
115 
116 
117 #ifdef SWITCH_DEBUG_RWLOCKS
118 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)
119 #else
121 #endif
122 {
124 
125  if (session->rwlock) {
126  if ((status = switch_thread_rwlock_tryrdlock(session->rwlock)) == SWITCH_STATUS_SUCCESS) {
128  status = SWITCH_STATUS_FALSE;
129 #ifdef SWITCH_DEBUG_RWLOCKS
130  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",
132 #endif
134  } else {
135 #ifdef SWITCH_DEBUG_RWLOCKS
136  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",
138 #endif
139  }
140  }
141  }
142 
143  return status;
144 }
145 
146 #ifdef SWITCH_DEBUG_RWLOCKS
147 SWITCH_DECLARE(void) switch_core_session_perform_write_lock(switch_core_session_t *session, const char *file, const char *func, int line)
148 {
149 
150  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",
152 #else
154 {
155 #endif
157 }
158 
159 #ifdef SWITCH_DEBUG_RWLOCKS
160 SWITCH_DECLARE(void) switch_core_session_perform_rwunlock(switch_core_session_t *session, const char *file, const char *func, int line)
161 {
162  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",
164 #else
166 {
167 #endif
169 
170 }
171 
172 /* For Emacs:
173  * Local Variables:
174  * mode:c
175  * indent-tabs-mode:t
176  * tab-width:4
177  * c-basic-offset:4
178  * End:
179  * For VIM:
180  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
181  */
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
switch_status_t switch_core_session_io_write_lock(switch_core_session_t *session)
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_status_t switch_core_session_io_read_lock(switch_core_session_t *session)
switch_status_t switch_core_session_io_rwunlock(switch_core_session_t *session)
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
switch_channel_t * channel
switch_status_t switch_core_session_read_lock_hangup(switch_core_session_t *session)
switch_status_t switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:255
#define switch_channel_down_nosig(_channel)
switch_thread_rwlock_t * io_rwlock
void switch_core_session_rwunlock(switch_core_session_t *session)
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
void switch_core_session_write_lock(switch_core_session_t *session)
switch_status_t
Common return values.
Main Library Header.
#define SWITCH_DECLARE(type)
switch_status_t switch_core_session_wake_session_thread(_In_ switch_core_session_t *session)
switch_status_t switch_core_session_read_lock(switch_core_session_t *session)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
switch_thread_rwlock_t * rwlock