[Freeswitch-svn] [commit] r1664 - in freeswitch/trunk/src: include mod/endpoints/mod_dingaling mod/endpoints/mod_iax mod/endpoints/mod_portaudio mod/endpoints/mod_wanpipe mod/endpoints/mod_woomera

anthm at freeswitch.org anthm at freeswitch.org
Fri Jun 23 12:59:48 EDT 2006


Author: anthm
Date: Fri Jun 23 12:59:47 2006
New Revision: 1664

Modified:
   freeswitch/trunk/src/include/switch_utils.h
   freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c
   freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c
   freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
   freeswitch/trunk/src/mod/endpoints/mod_woomera/mod_woomera.c

Log:
add more mutexed flag ops

Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h	(original)
+++ freeswitch/trunk/src/include/switch_utils.h	Fri Jun 23 12:59:47 2006
@@ -117,7 +117,10 @@
   \param obj the object to set the flags on
   \param flag the or'd list of flags to set
 */
-#define switch_set_flag_locked(obj, flag) switch_mutex_lock(obj->flag_mutex); (obj)->flags |= (flag); switch_mutex_unlock(obj->flag_mutex);
+#define switch_set_flag_locked(obj, flag) assert(obj->flag_mutex != NULL);\
+switch_mutex_lock(obj->flag_mutex);\
+(obj)->flags |= (flag);\
+switch_mutex_unlock(obj->flag_mutex);
 
 /*!
   \brief Clear a flag on an arbitrary object

Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Fri Jun 23 12:59:47 2006
@@ -138,6 +138,7 @@
 	char *recip;
 	char *dnis;
 	uint16_t stun_port;
+	switch_mutex_t *flag_mutex;
 };
 
 struct rfc2833_digit {
@@ -309,7 +310,7 @@
 		switch_rtp_activate_ice(tech_pvt->rtp_session, tech_pvt->remote_user, tech_pvt->local_user);
 		if ((vad_in && inb) || (vad_out && !inb)) {
 			switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING);
-			switch_set_flag(tech_pvt, TFLAG_VAD);
+			switch_set_flag_locked(tech_pvt, TFLAG_VAD);
 		}
 	}
 
@@ -333,7 +334,7 @@
 	if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
 		return -1;
 	}
-	switch_set_flag(tech_pvt, TFLAG_DO_CAND);
+	switch_set_flag_locked(tech_pvt, TFLAG_DO_CAND);
 
 	if (force || !switch_test_flag(tech_pvt, TFLAG_RTP_READY)) {
 		ldl_candidate_t cand[1];
@@ -393,9 +394,9 @@
 		cand[0].protocol = "udp";
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Candidate %s:%d [%s]\n", cand[0].address, cand[0].port, cand[0].username);
 		tech_pvt->cand_id = ldl_session_candidates(tech_pvt->dlsession, cand, 1);
-		switch_set_flag(tech_pvt, TFLAG_RTP_READY);
+		switch_set_flag_locked(tech_pvt, TFLAG_RTP_READY);
 	}
-	switch_clear_flag(tech_pvt, TFLAG_DO_CAND);
+	switch_clear_flag_locked(tech_pvt, TFLAG_DO_CAND);
 	return 0;
 }
 
@@ -425,13 +426,13 @@
 	}
 
 	memset(payloads, 0, sizeof(payloads));
-	switch_set_flag(tech_pvt, TFLAG_DO_CAND);
+	switch_set_flag_locked(tech_pvt, TFLAG_DO_CAND);
 	if (!tech_pvt->num_codecs) {
 		get_codecs(tech_pvt);
 		if (!tech_pvt->num_codecs) {
 			switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
-			switch_set_flag(tech_pvt, TFLAG_BYE);
-			switch_clear_flag(tech_pvt, TFLAG_IO);
+			switch_set_flag_locked(tech_pvt, TFLAG_BYE);
+			switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 			return -1;
 		}
 	}
@@ -455,9 +456,9 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Describe [%s]\n", payloads[0].name);
 		tech_pvt->desc_id = ldl_session_describe(tech_pvt->dlsession, payloads, 1,
 												 switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? LDL_DESCRIPTION_INITIATE : LDL_DESCRIPTION_ACCEPT);
-		switch_set_flag(tech_pvt, TFLAG_CODEC_READY);
+		switch_set_flag_locked(tech_pvt, TFLAG_CODEC_READY);
 	} 
-	switch_clear_flag(tech_pvt, TFLAG_DO_CAND);
+	switch_clear_flag_locked(tech_pvt, TFLAG_DO_CAND);
 	return 0;
 }
 
@@ -477,7 +478,7 @@
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
-	switch_set_flag(tech_pvt, TFLAG_IO);
+	switch_set_flag_locked(tech_pvt, TFLAG_IO);
 
 	started = switch_time_now();
 
@@ -513,8 +514,8 @@
 		}
 		if (elapsed > 60000) {
 			switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-			switch_set_flag(tech_pvt, TFLAG_BYE);
-			switch_clear_flag(tech_pvt, TFLAG_IO);
+			switch_set_flag_locked(tech_pvt, TFLAG_BYE);
+			switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 			return NULL;
 		}
 		if (switch_test_flag(tech_pvt, TFLAG_BYE) || ! switch_test_flag(tech_pvt, TFLAG_IO)) {
@@ -624,9 +625,9 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-	switch_clear_flag(tech_pvt, TFLAG_IO);
-	switch_clear_flag(tech_pvt, TFLAG_VOICE);
-	switch_set_flag(tech_pvt, TFLAG_BYE);
+	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+	switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+	switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 	
 	if (tech_pvt->dlsession) {
 		ldl_session_terminate(tech_pvt->dlsession);
@@ -659,9 +660,9 @@
 
 	if ((channel = switch_core_session_get_channel(session))) {
 		if ((tech_pvt = switch_core_session_get_private(session))) {
-			switch_clear_flag(tech_pvt, TFLAG_IO);
-			switch_clear_flag(tech_pvt, TFLAG_VOICE);
-			switch_set_flag(tech_pvt, TFLAG_BYE);
+			switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+			switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+			switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 			switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
 			if (tech_pvt->dlsession) {
 				ldl_session_terminate(tech_pvt->dlsession);
@@ -749,7 +750,7 @@
 	}
 
 	tech_pvt->read_frame.datalen = 0;
-	switch_set_flag(tech_pvt, TFLAG_READING);
+	switch_set_flag_locked(tech_pvt, TFLAG_READING);
 
 	bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
 	samples = tech_pvt->read_codec.implementation->samples_per_frame;
@@ -770,11 +771,11 @@
 			char dtmf[128];
 			switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, dtmf, sizeof(dtmf));
 			switch_channel_queue_dtmf(channel, dtmf);
-			switch_set_flag(tech_pvt, TFLAG_DTMF);
+			switch_set_flag_locked(tech_pvt, TFLAG_DTMF);
 		}
 
 		if (switch_test_flag(tech_pvt, TFLAG_DTMF)) {
-			switch_clear_flag(tech_pvt, TFLAG_DTMF);
+			switch_clear_flag_locked(tech_pvt, TFLAG_DTMF);
 			return SWITCH_STATUS_BREAK;
 		}
 
@@ -798,7 +799,7 @@
 	}
 
 
-	switch_clear_flag(tech_pvt, TFLAG_READING);
+	switch_clear_flag_locked(tech_pvt, TFLAG_READING);
 
 	if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
 		switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
@@ -838,7 +839,7 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	switch_set_flag(tech_pvt, TFLAG_WRITING);
+	switch_set_flag_locked(tech_pvt, TFLAG_WRITING);
 
 
 	bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
@@ -852,7 +853,7 @@
 	}
 	tech_pvt->timestamp_send += (int) samples;
 
-	switch_clear_flag(tech_pvt, TFLAG_WRITING);
+	switch_clear_flag_locked(tech_pvt, TFLAG_WRITING);
 	//switch_mutex_unlock(tech_pvt->rtp_lock);
 	return status;
 }
@@ -1022,6 +1023,7 @@
 		switch_core_session_add_stream(*new_session, NULL);
 		if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
 			memset(tech_pvt, 0, sizeof(*tech_pvt));
+			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
 			tech_pvt->flags |= globals.flags;
 			tech_pvt->flags |= mdl_profile->flags;
 			channel = switch_core_session_get_channel(*new_session);
@@ -1053,7 +1055,7 @@
 		}
 
 		switch_channel_set_flag(channel, CF_OUTBOUND);
-		switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
+		switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
 		
 		switch_stun_random_string(sess_id, 10, "0123456789");
 
@@ -1466,6 +1468,7 @@
 			switch_core_session_add_stream(session, NULL);
 			if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
 				memset(tech_pvt, 0, sizeof(*tech_pvt));
+				switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 				tech_pvt->flags |= globals.flags;
 				tech_pvt->flags |= profile->flags;
 				channel = switch_core_session_get_channel(session);
@@ -1474,7 +1477,7 @@
 				tech_pvt->codec_index = -1;
 				tech_pvt->profile = profile;
 				tech_pvt->local_port = switch_rtp_request_port();
-				switch_set_flag(tech_pvt, TFLAG_ANSWER);
+				switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
 				tech_pvt->recip = switch_core_session_strdup(session, from);
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hey where is my memory pool?\n");
@@ -1495,7 +1498,7 @@
 		if (msg) { 
 			if (*msg == '+') {
 				switch_channel_queue_dtmf(channel, msg + 1);
-				switch_set_flag(tech_pvt, TFLAG_DTMF);
+				switch_set_flag_locked(tech_pvt, TFLAG_DTMF);
 				switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK);
 			}
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "SESSION MSG [%s]\n", msg);
@@ -1519,7 +1522,7 @@
 
 			if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 				if (!strcasecmp(msg, "accept")) {
-					switch_set_flag(tech_pvt, TFLAG_ANSWER);
+					switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
 					do_candidates(tech_pvt, 0);
 				}
 			}
@@ -1665,7 +1668,7 @@
 						}
 
 						if (lanaddr) {
-							switch_set_flag(tech_pvt, TFLAG_LANADDR);
+							switch_set_flag_locked(tech_pvt, TFLAG_LANADDR);
 						}
 
 						if (!tech_pvt->num_codecs) {
@@ -1683,7 +1686,7 @@
 						if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
 							do_candidates(tech_pvt, 0);
 						}
-						switch_set_flag(tech_pvt, TFLAG_TRANSPORT);
+						switch_set_flag_locked(tech_pvt, TFLAG_TRANSPORT);
 						
 						return LDL_STATUS_SUCCESS;
 					}
@@ -1696,8 +1699,10 @@
 		if (channel) {
 			switch_channel_state_t state = switch_channel_get_state(channel);
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hungup %s %u %d\n", switch_channel_get_name(channel), state, CS_INIT);
+			switch_mutex_lock(tech_pvt->flag_mutex);
 			switch_set_flag(tech_pvt, TFLAG_BYE);
 			switch_clear_flag(tech_pvt, TFLAG_IO);
+			switch_mutex_unlock(tech_pvt->flag_mutex);
 			switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
 
 			if (state <= CS_INIT && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {

Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c	Fri Jun 23 12:59:47 2006
@@ -90,6 +90,7 @@
 	unsigned int codecs;
 	unsigned short samprate;
 	switch_mutex_t *mutex;
+	switch_mutex_t *flag_mutex;
 	//switch_thread_cond_t *cond;
 };
 
@@ -344,7 +345,7 @@
 	}
 
 	if (!strcasecmp(dname, "l16")) {
-		switch_set_flag(tech_pvt, TFLAG_LINEAR);
+		switch_set_flag_locked(tech_pvt, TFLAG_LINEAR);
 	}
 	if (switch_core_codec_init(&tech_pvt->read_codec,
 							   dname,
@@ -376,7 +377,7 @@
 			tech_pvt->read_frame.codec = &tech_pvt->read_codec;
 			switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
 			switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
-			switch_set_flag(tech_pvt, TFLAG_CODEC);
+			switch_set_flag_locked(tech_pvt, TFLAG_CODEC);
 		}
 		tech_pvt->codec = chosen;
 		tech_pvt->codecs = local_cap;
@@ -437,7 +438,7 @@
 	tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
 	iax_set_private(tech_pvt->iax_session, tech_pvt);
 
-	switch_set_flag(tech_pvt, TFLAG_IO);
+	switch_set_flag_locked(tech_pvt, TFLAG_IO);
 
 	switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 	//switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session));    
@@ -494,8 +495,8 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-	switch_clear_flag(tech_pvt, TFLAG_IO);
-	switch_clear_flag(tech_pvt, TFLAG_VOICE);
+	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+	switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
 	//switch_thread_cond_signal(tech_pvt->cond);
 
 	if (tech_pvt->read_codec.implementation) {
@@ -509,7 +510,7 @@
 	if (tech_pvt->iax_session) {
 		if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
 			iax_hangup(tech_pvt->iax_session, "Hangup");
-			switch_set_flag(tech_pvt, TFLAG_HANGUP);
+			switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
 		}
 		iax_session_destroy(&tech_pvt->iax_session);
 	}
@@ -530,8 +531,8 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-	switch_clear_flag(tech_pvt, TFLAG_IO);
-	switch_clear_flag(tech_pvt, TFLAG_VOICE);
+	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+	switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
 	switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
 	//switch_thread_cond_signal(tech_pvt->cond);
 
@@ -612,7 +613,7 @@
 		}
 
 		if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
-			switch_clear_flag(tech_pvt, TFLAG_VOICE);
+			switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
 			if (!tech_pvt->read_frame.datalen) {
 				continue;
 			}
@@ -737,6 +738,7 @@
 		if ((tech_pvt =
 			 (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
 			memset(tech_pvt, 0, sizeof(*tech_pvt));
+			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
 			channel = switch_core_session_get_channel(*new_session);
 			switch_core_session_set_private(*new_session, tech_pvt);
 			tech_pvt->session = *new_session;
@@ -781,7 +783,7 @@
 				 caller_profile->caller_id_name, caller_profile->destination_number, NULL, 0, req, cap);
 
 		switch_channel_set_flag(channel, CF_OUTBOUND);
-		switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
+		switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
 		switch_channel_set_state(channel, CS_INIT);
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -988,6 +990,7 @@
 							 (struct private_object *) switch_core_session_alloc(session,
 																				 sizeof(struct private_object))) != 0) {
 							memset(tech_pvt, 0, sizeof(*tech_pvt));
+							switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 							channel = switch_core_session_get_channel(session);
 							switch_core_session_set_private(session, tech_pvt);
 							tech_pvt->session = session;
@@ -1041,12 +1044,15 @@
 			case IAX_EVENT_HANGUP:
 				if (tech_pvt) {
 					switch_channel_t *channel;
-
+					
+					switch_mutex_lock(tech_pvt->flag_mutex);
 					switch_clear_flag(tech_pvt, TFLAG_IO);
 					switch_clear_flag(tech_pvt, TFLAG_VOICE);
+					switch_mutex_unlock(tech_pvt->flag_mutex);
+
 					if ((channel = switch_core_session_get_channel(tech_pvt->session)) != 0) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
-						switch_set_flag(tech_pvt, TFLAG_HANGUP);
+						switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
 						switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
 						//switch_thread_cond_signal(tech_pvt->cond);
 						iaxevent->session = NULL;
@@ -1079,7 +1085,7 @@
 						tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
 						memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
 						/* wake up the i/o thread */
-						switch_set_flag(tech_pvt, TFLAG_VOICE);
+						switch_set_flag_locked(tech_pvt, TFLAG_VOICE);
 						//switch_thread_cond_signal(tech_pvt->cond);
 					}
 				}

Modified: freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c	Fri Jun 23 12:59:47 2006
@@ -92,6 +92,7 @@
 	PABLIO_Stream *audio_out;
 	int indev;
 	int outdev;
+	switch_mutex_t *flag_mutex;
 };
 
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
@@ -177,7 +178,7 @@
 	if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
 		switch_channel_hangup(channel, SWITCH_CAUSE_NO_ANSWER);
 	} else {
-		switch_set_flag(tech_pvt, TFLAG_IO);
+		switch_set_flag_locked(tech_pvt, TFLAG_IO);
 
 		/* Move Channel's State Machine to RING */
 		switch_channel_set_state(channel, CS_RING);
@@ -245,7 +246,7 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-	switch_clear_flag(tech_pvt, TFLAG_IO);
+	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 	switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
 
 	switch_core_codec_destroy(&tech_pvt->read_codec);
@@ -269,7 +270,7 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-	switch_clear_flag(tech_pvt, TFLAG_IO);
+	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 	deactivate_audio_device(tech_pvt);
 	switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
 
@@ -425,7 +426,7 @@
 	case SWITCH_MESSAGE_INDICATE_PROGRESS: 
 		{
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engage Early Media\n");
-			switch_set_flag(tech_pvt, TFLAG_IO);
+			switch_set_flag_locked(tech_pvt, TFLAG_IO);
 		}
 	default:
 		break;
@@ -524,6 +525,7 @@
 		if ((tech_pvt =
 			 (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
 			memset(tech_pvt, 0, sizeof(*tech_pvt));
+			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
 			channel = switch_core_session_get_channel(*new_session);
 			switch_core_session_set_private(*new_session, tech_pvt);
 			tech_pvt->session = *new_session;
@@ -550,7 +552,7 @@
 		}
 
 		switch_channel_set_flag(channel, CF_OUTBOUND);
-		switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
+		switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
 		switch_channel_set_state(channel, CS_INIT);
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -838,6 +840,7 @@
 		switch_core_session_add_stream(session, NULL);
 		if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
 			memset(tech_pvt, 0, sizeof(*tech_pvt));
+			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 			channel = switch_core_session_get_channel(session);
 			switch_core_session_set_private(session, tech_pvt);
 			tech_pvt->session = session;
@@ -947,7 +950,7 @@
 	if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid)) != 0) {
 		channel = switch_core_session_get_channel(tech_pvt->session);
 		assert(channel != NULL);
-		switch_set_flag(tech_pvt, TFLAG_ANSWER);
+		switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
 		switch_channel_answer(channel);
 	} else {
 		stream->write_function(stream, "NO SUCH CALL");

Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c	Fri Jun 23 12:59:47 2006
@@ -116,6 +116,7 @@
 	switch_buffer_t *dtmf_buffer;
 	unsigned int skip_read_frames;
 	unsigned int skip_write_frames;
+	switch_mutex_t *flag_mutex;
 #ifdef DOTRACE
 	int fd;
 	int fd2;
@@ -337,7 +338,7 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-	switch_set_flag(tech_pvt, TFLAG_BYE);
+	switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 
 	if (!switch_test_flag(tech_pvt, TFLAG_NOSIG)) {
 		chanmap = tech_pvt->spri->private_info;
@@ -656,9 +657,11 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-
+	switch_mutex_lock(tech_pvt->flag_mutex);
 	switch_set_flag(tech_pvt, TFLAG_BYE);
 	switch_clear_flag(tech_pvt, TFLAG_MEDIA);
+	switch_mutex_unlock(tech_pvt->flag_mutex);
+
 	sangoma_socket_close(&tech_pvt->socket);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -737,6 +740,7 @@
 		switch_core_session_add_stream(*new_session, NULL);
 		if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
 			memset(tech_pvt, 0, sizeof(*tech_pvt));
+			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
 			channel = switch_core_session_get_channel(*new_session);
 			switch_core_session_set_private(*new_session, tech_pvt);
 			tech_pvt->session = *new_session;
@@ -806,7 +810,7 @@
 						switch_core_session_destroy(new_session);
 						return SWITCH_STATUS_GENERR;
 					}
-					switch_set_flag(tech_pvt, TFLAG_NOSIG);
+					switch_set_flag_locked(tech_pvt, TFLAG_NOSIG);
 					snprintf(name, sizeof(name), "WanPipe/%s/nosig-%04x", bchan, rand() & 0xffff);
 					switch_channel_set_name(channel, name);			
 					switch_channel_set_caller_profile(channel, caller_profile);
@@ -901,7 +905,7 @@
 		}
 
 		switch_channel_set_flag(channel, CF_OUTBOUND);
-		switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
+		switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
 		switch_channel_set_state(channel, CS_INIT);
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -1118,6 +1122,7 @@
 		switch_core_session_add_stream(session, NULL);
 		if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
 			memset(tech_pvt, 0, sizeof(*tech_pvt));
+			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 			channel = switch_core_session_get_channel(session);
 			switch_core_session_set_private(session, tech_pvt);
 			sprintf(name, "s%dc%d", spri->span, event->ring.channel);
@@ -1148,7 +1153,7 @@
 			switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
 		}
 
-		switch_set_flag(tech_pvt, TFLAG_INBOUND);
+		switch_set_flag_locked(tech_pvt, TFLAG_INBOUND);
 		tech_pvt->spri = spri;
 		tech_pvt->cause = -1;
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_woomera/mod_woomera.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_woomera/mod_woomera.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_woomera/mod_woomera.c	Fri Jun 23 12:59:47 2006
@@ -154,6 +154,7 @@
 	char dtmfbuf[WOOMERA_STRLEN];
 	switch_caller_profile_t *caller_profile;
 	struct woomera_event_queue event_queue;
+	switch_mutex_t *flag_mutex;
 };
 
 typedef struct private_object private_object;
@@ -230,7 +231,7 @@
 	switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
 
 
-	switch_set_flag(tech_pvt, TFLAG_ACTIVATE);
+	switch_set_flag_locked(tech_pvt, TFLAG_ACTIVATE);
 
 	switch_core_session_launch_thread(session, woomera_channel_thread_run, session);
 
@@ -483,6 +484,7 @@
 		if ((tech_pvt =
 			 (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
 			memset(tech_pvt, 0, sizeof(*tech_pvt));
+			switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
 			tech_pvt->profile = &default_profile;
 			channel = switch_core_session_get_channel(*new_session);
 			switch_core_session_set_private(*new_session, tech_pvt);
@@ -510,7 +512,7 @@
 		}
 
 		switch_channel_set_flag(channel, CF_OUTBOUND);
-		switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
+		switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
 		switch_channel_set_state(channel, CS_INIT);
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -907,13 +909,13 @@
 			woomera_message_parse(tech_pvt->command_channel,
 								  &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue);
 		} else {
-			switch_set_flag(tech_pvt, TFLAG_PARSE_INCOMING);
+			switch_set_flag_locked(tech_pvt, TFLAG_PARSE_INCOMING);
 			woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
 			if (woomera_message_parse(tech_pvt->command_channel,
 									  &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
 									  tech_pvt->profile->name);
-				switch_set_flag(tech_pvt, TFLAG_ABORT);
+				switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 				globals.panic = 1;
 			}
 		}
@@ -949,7 +951,7 @@
 
 	for (;;) {
 		if (globals.panic) {
-			switch_set_flag(tech_pvt, TFLAG_ABORT);
+			switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 		}
 
 		if (switch_test_flag(tech_pvt, TFLAG_ABORT)) {
@@ -959,12 +961,12 @@
 		}
 
 		if (switch_test_flag(tech_pvt, TFLAG_ACTIVATE)) {
-			switch_clear_flag(tech_pvt, TFLAG_ACTIVATE);
+			switch_clear_flag_locked(tech_pvt, TFLAG_ACTIVATE);
 			tech_activate(tech_pvt);
 		}
 
 		if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
-			switch_clear_flag(tech_pvt, TFLAG_ANSWER);
+			switch_clear_flag_locked(tech_pvt, TFLAG_ANSWER);
 #ifdef USE_ANSWER
 			woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s", tech_pvt->call_info.callid,
 						   WOOMERA_RECORD_SEPERATOR);
@@ -973,7 +975,7 @@
 				 &tech_pvt->event_queue) < 0) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
 									  tech_pvt->profile->name);
-				switch_set_flag(tech_pvt, TFLAG_ABORT);
+				switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 				globals.panic = 1;
 				continue;
 			}
@@ -989,11 +991,11 @@
 				 &tech_pvt->event_queue) < 0) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
 									  tech_pvt->profile->name);
-				switch_set_flag(tech_pvt, TFLAG_ABORT);
+				switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 				globals.panic = 1;
 				continue;
 			}
-			switch_clear_flag(tech_pvt, TFLAG_DTMF);
+			switch_clear_flag_locked(tech_pvt, TFLAG_DTMF);
 			memset(tech_pvt->dtmfbuf, 0, sizeof(tech_pvt->dtmfbuf));
 			switch_mutex_unlock(tech_pvt->iolock);
 		}
@@ -1007,7 +1009,7 @@
 				 ((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000));
 			if (elapsed > tech_pvt->timeout) {
 				/* call timed out! */
-				switch_set_flag(tech_pvt, TFLAG_ABORT);
+				switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 			}
 		}
 #endif
@@ -1020,7 +1022,7 @@
 			(res = woomera_message_parse(tech_pvt->command_channel, &wmsg, 100, tech_pvt->profile, NULL)) != 0) {
 
 			if (res < 0 || !strcasecmp(wmsg.command, "HANGUP")) {
-				switch_set_flag(tech_pvt, TFLAG_ABORT);
+				switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 				continue;
 			} else if (!strcasecmp(wmsg.command, "DTMF")) {
 				/*
@@ -1043,8 +1045,8 @@
 				char *cid_num;
 				char *ip;
 				char *p;
-				switch_clear_flag(tech_pvt, TFLAG_PARSE_INCOMING);
-				switch_set_flag(tech_pvt, TFLAG_INCOMING);
+				switch_clear_flag_locked(tech_pvt, TFLAG_PARSE_INCOMING);
+				switch_set_flag_locked(tech_pvt, TFLAG_INCOMING);
 				tech_pvt->call_info = wmsg;
 
 				exten = woomera_message_header(&wmsg, "Local-Number");
@@ -1088,7 +1090,7 @@
 										  &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
 										  tech_pvt->profile->name);
-					switch_set_flag(tech_pvt, TFLAG_ABORT);
+					switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
 					globals.panic = 1;
 					continue;
 				}
@@ -1242,6 +1244,7 @@
 					if ((tech_pvt =
 						 (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
 						memset(tech_pvt, 0, sizeof(*tech_pvt));
+						switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 						tech_pvt->profile = &default_profile;
 						channel = switch_core_session_get_channel(session);
 						switch_core_session_set_private(session, tech_pvt);



More information about the Freeswitch-svn mailing list