#endif
+#ifdef SWITCH_DEBUG_RWLOCKS
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock_hangup(_In_ switch_core_session_t *session, const char *file, const char *func, int line);
+#endif
+
+/*!
+ \brief Acquire a read lock on the session
+ \param session the session to acquire from
+ \return success if it is safe to read from the session
+*/
+#ifdef SWITCH_DEBUG_RWLOCKS
+#define switch_core_session_read_lock(session) switch_core_session_perform_read_lock_hangup(session, __FILE__, __SWITCH_FUNC__, __LINE__)
+#else
+SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock_hangup(_In_ switch_core_session_t *session);
+#endif
+
+
#ifdef SWITCH_DEBUG_RWLOCKS
SWITCH_DECLARE(void) switch_core_session_perform_write_lock(_In_ switch_core_session_t *session, const char *file, const char *func, int line);
#endif
(*jss)->stack_depth = 0;
if ((JS_SetPrivate(cx, session_obj, *jss) &&
JS_DefineProperties(cx, session_obj, session_props) && JS_DefineFunctions(cx, session_obj, session_methods))) {
- if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_session_read_lock_hangup(session) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Failure.\n");
free(*jss);
return NULL;
/* Emaculent conception of session object into the script if one is available */
if (!(session && new_js_session(cx, javascript_global_object, session, &jss, "session", flags))) {
- switch_snprintf(buf, sizeof(buf), "~var session = false;");
+ switch_snprintf(buf, sizeof(buf), "~var session = new Object();");
eval_some_js(buf, cx, javascript_global_object, &rval);
+ return;
}
if (ro) {
new_request(cx, javascript_global_object, ro);
return status;
}
+
+#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) {
+ if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_get_state(session->channel) >= CS_DONE) {
+ status = SWITCH_STATUS_FALSE;
+#ifdef SWITCH_DEBUG_RWLOCKS
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Read lock FAIL\n",
+ switch_channel_get_name(session->channel));
+#endif
+ } else {
+ status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock);
+#ifdef SWITCH_DEBUG_RWLOCKS
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Read lock ACQUIRED\n",
+ switch_channel_get_name(session->channel));
+#endif
+ }
+ }
+
+ return status;
+}
+
#ifdef SWITCH_DEBUG_RWLOCKS
SWITCH_DECLARE(void) switch_core_session_perform_write_lock(switch_core_session_t *session, const char *file, const char *func, int line)
{
switch_channel_get_variables(session->channel, &stream.param_event);
expanded = switch_channel_expand_variables(session->channel, arg);
- switch_api_execute(cmd, expanded, use_session, &stream);
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hangup Command %s(%s):\n%s\n", cmd, expanded,
switch_str_nil((char *) stream.data));
+ switch_api_execute(cmd, expanded, use_session, &stream);
if (expanded != arg) {
switch_safe_free(expanded);
}