[Freeswitch-svn] [commit] r11680 - freeswitch/trunk/src/mod/event_handlers/mod_event_socket
FreeSWITCH SVN
anthm at freeswitch.org
Sat Feb 7 08:44:46 PST 2009
Author: anthm
Date: Sat Feb 7 10:44:46 2009
New Revision: 11680
Log:
add extra checking for race cond in bgapi
Modified:
freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Sat Feb 7 10:44:46 2009
@@ -1199,7 +1199,8 @@
char *arg;
listener_t *listener;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
- uint8_t bg;
+ int bg;
+ int ack;
switch_memory_pool_t *pool;
};
@@ -1210,18 +1211,21 @@
switch_stream_handle_t stream = { 0 };
char *reply, *freply = NULL;
switch_status_t status;
-
+
if (!acs) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Internal error.\n");
return NULL;
}
- if (!acs->listener || !acs->listener->rwlock || switch_thread_rwlock_tryrdlock(acs->listener->rwlock) != SWITCH_STATUS_SUCCESS) {
+ if (!acs->listener || !switch_test_flag(acs->listener, LFLAG_RUNNING) ||
+ !acs->listener->rwlock || switch_thread_rwlock_tryrdlock(acs->listener->rwlock) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error! cannot get read lock.\n");
+ acs->ack = -1;
goto done;
}
-
-
+
+ acs->ack = 1;
+
SWITCH_STANDARD_STREAM(stream);
if ((status = switch_api_execute(acs->api_cmd, acs->arg, NULL, &stream)) == SWITCH_STATUS_SUCCESS) {
@@ -1270,12 +1274,23 @@
}
done:
+
if (acs->bg) {
switch_memory_pool_t *pool = acs->pool;
+ if (acs->ack == -1) {
+ int sanity = 2000;
+ while(acs->ack == -1) {
+ switch_cond_next();
+ if (--sanity <= 0) break;
+ }
+ }
+
acs = NULL;
switch_core_destroy_memory_pool(&pool);
pool = NULL;
+
}
+
return NULL;
}
@@ -1539,6 +1554,7 @@
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
switch_uuid_t uuid;
+ int sanity;
strip_cr(api_cmd);
@@ -1571,6 +1587,14 @@
}
switch_snprintf(reply, reply_len, "~Reply-Text: +OK Job-UUID: %s\nJob-UUID: %s\n\n", acs->uuid_str, acs->uuid_str);
switch_thread_create(&thread, thd_attr, api_exec, acs, acs->pool);
+ sanity = 2000;
+ while(!acs->ack) {
+ switch_cond_next();
+ if (--sanity <= 0) break;
+ }
+ if (acs->ack == -1) {
+ acs->ack--;
+ }
status = SWITCH_STATUS_SUCCESS;
goto done_noreply;
@@ -1942,7 +1966,7 @@
if (revent) {
switch_event_destroy(&revent);
}
-
+
remove_listener(listener);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session complete, waiting for children\n");
More information about the Freeswitch-svn
mailing list