[Freeswitch-svn] [commit] r3945 - freeswitch/trunk/src/mod/applications/mod_conference

Freeswitch SVN anthm at freeswitch.org
Thu Jan 11 17:34:04 EST 2007


Author: anthm
Date: Thu Jan 11 17:34:04 2007
New Revision: 3945

Modified:
   freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c

Log:
add rwlock to members

Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	Thu Jan 11 17:34:04 2007
@@ -115,7 +115,8 @@
 	MFLAG_CAN_HEAR = (1 << 2), 
 	MFLAG_KICKED = (1 << 3), 
 	MFLAG_ITHREAD = (1 << 4), 
-	MFLAG_NOCHANNEL = (1 << 5)
+	MFLAG_NOCHANNEL = (1 << 5),
+    MFLAG_INTREE = (1 << 6)
 } member_flag_t;
 
 typedef enum {
@@ -189,7 +190,7 @@
 	uint32_t interval;
 	switch_mutex_t *mutex;
 	conference_member_t *members;
-	switch_mutex_t *member_mutex;
+	switch_thread_rwlock_t *member_rwlock;
 	conference_file_node_t *fnode;
 	switch_memory_pool_t *pool;
 	switch_thread_rwlock_t *rwlock;
@@ -372,6 +373,7 @@
     assert(conference != NULL);
     assert(id != 0);
 
+    switch_thread_rwlock_rdlock(conference->member_rwlock);
     for(member = conference->members; member; member = member->next) {
         
         if (switch_test_flag(member, MFLAG_NOCHANNEL)) {
@@ -382,7 +384,12 @@
             break;
         }
     }
-	
+
+    if (member && !switch_test_flag(member, MFLAG_INTREE)) {
+        member = NULL;
+    }
+
+    switch_thread_rwlock_unlock(conference->member_rwlock);
 
 	return member;
 }
@@ -394,14 +401,14 @@
 	int count = 0;
 
 	assert (conference != NULL);
-
+    switch_thread_rwlock_rdlock(conference->member_rwlock);
     for(member = conference->members; member; member = member->next) {
         if (switch_test_flag(member, MFLAG_NOCHANNEL) && (!path || !strcmp(path, member->rec_path))) {
             switch_clear_flag_locked(member, MFLAG_RUNNING);
             count++;
         }
     }
-
+    switch_thread_rwlock_unlock(conference->member_rwlock);
 	return count;
 }
 
@@ -459,7 +466,7 @@
     assert(member != NULL);
 
     switch_mutex_lock(conference->mutex);
-    switch_mutex_lock(conference->member_mutex);
+    switch_thread_rwlock_wrlock(conference->member_rwlock);
     switch_mutex_lock(member->audio_in_mutex);
     switch_mutex_lock(member->audio_out_mutex);
     switch_mutex_lock(member->flag_mutex);
@@ -467,7 +474,7 @@
     member->next = conference->members;
     member->energy_level = conference->energy_level;
     conference->members = member;
-
+    switch_set_flag(member, MFLAG_INTREE);
 
     if (!switch_test_flag(member, MFLAG_NOCHANNEL)) {
         conference->count++;
@@ -506,7 +513,7 @@
     switch_mutex_unlock(member->flag_mutex);
     switch_mutex_unlock(member->audio_out_mutex);
     switch_mutex_unlock(member->audio_in_mutex);
-    switch_mutex_unlock(conference->member_mutex);
+    switch_thread_rwlock_unlock(conference->member_rwlock);
     switch_mutex_unlock(conference->mutex);
     status = SWITCH_STATUS_SUCCESS;
 	
@@ -524,15 +531,13 @@
     assert(conference != NULL);
     assert(member != NULL);
     
-
-
-
     switch_mutex_lock(conference->mutex);
-    switch_mutex_lock(conference->member_mutex);
+    switch_thread_rwlock_wrlock(conference->member_rwlock);
     switch_mutex_lock(member->audio_in_mutex);
     switch_mutex_lock(member->audio_out_mutex);
     switch_mutex_lock(member->flag_mutex);
-
+    switch_clear_flag(member, MFLAG_INTREE);
+    
     for (imember = conference->members; imember; imember = imember->next) {
         if (imember == member ) {
             if (last) {
@@ -606,7 +611,7 @@
     switch_mutex_unlock(member->flag_mutex);
     switch_mutex_unlock(member->audio_out_mutex);
     switch_mutex_unlock(member->audio_in_mutex);
-    switch_mutex_unlock(conference->member_mutex);
+    switch_thread_rwlock_unlock(conference->member_rwlock);
     switch_mutex_unlock(conference->mutex);
     status = SWITCH_STATUS_SUCCESS;
 	
@@ -648,6 +653,7 @@
 		ready = 0;
 
 		/* Read one frame of audio from each member channel and save it for redistribution */
+        switch_thread_rwlock_rdlock(conference->member_rwlock);
 		for (imember = conference->members; imember; imember = imember->next) {
 			if (imember->buflen) {
 				memset(imember->frame, 255, imember->buflen);
@@ -686,7 +692,7 @@
 			}
 			switch_mutex_unlock(imember->audio_in_mutex);
 		}
-
+        switch_thread_rwlock_unlock(conference->member_rwlock);
 		/* If a file or speech event is being played */
 		if (conference->fnode) {
 			/* Lead in time */
@@ -719,6 +725,7 @@
 
 		if (ready) {
 			/* Build a muxed frame for every member that contains the mixed audio of everyone else */
+            switch_thread_rwlock_rdlock(conference->member_rwlock);
 			for (omember = conference->members; omember; omember = omember->next) {
 				omember->len = bytes;
 				if (conference->fnode) {
@@ -785,6 +792,7 @@
 				switch_mutex_unlock(imember->audio_out_mutex);
 			}
 		}
+        switch_thread_rwlock_unlock(conference->member_rwlock);
 
 		if (conference->fnode && conference->fnode->done) {
 			conference_file_node_t *fnode;
@@ -849,6 +857,7 @@
 			conference->fnode = NULL; 
 		} 
 
+        switch_thread_rwlock_rdlock(conference->member_rwlock);
 		for(imember = conference->members; imember; imember = imember->next) {
 			switch_channel_t *channel;
 
@@ -867,6 +876,7 @@
 
 			switch_clear_flag_locked(imember, MFLAG_RUNNING);
 		}
+        switch_thread_rwlock_unlock(conference->member_rwlock);
 
 		switch_mutex_unlock(conference->mutex);
 
@@ -1428,7 +1438,8 @@
 	launch_conference_loop_input(member, switch_core_session_get_pool(member->session));
 
 	/* build a digit stream object */
-	if (member->conference->dtmf_parser != NULL && switch_ivr_digit_stream_new(member->conference->dtmf_parser, &member->digit_stream) != SWITCH_STATUS_SUCCESS) {
+	if (member->conference->dtmf_parser != NULL && 
+        switch_ivr_digit_stream_new(member->conference->dtmf_parser, &member->digit_stream) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Warning Will Robinson, there is no digit parser stream object\n");
 	}
 
@@ -1813,9 +1824,9 @@
     assert(conference != NULL);
 
     switch_mutex_lock(conference->mutex);
-    switch_mutex_lock(conference->member_mutex);
+    switch_thread_rwlock_rdlock(conference->member_rwlock);
     count = conference->count;
-    switch_mutex_unlock(conference->member_mutex);
+    switch_thread_rwlock_unlock(conference->member_rwlock);
     switch_mutex_unlock(conference->mutex);	
 
     if (!count) {
@@ -2040,15 +2051,13 @@
         return SWITCH_STATUS_GENERR;
     }
 
-
-
     switch_mutex_lock(conference->mutex);
-    switch_mutex_lock(conference->member_mutex);
+    switch_thread_rwlock_rdlock(conference->member_rwlock);
     count = conference->count;
     if (!(conference->tts_engine && conference->tts_voice)) {
         count = 0;
     }
-    switch_mutex_unlock(conference->member_mutex);
+    switch_thread_rwlock_unlock(conference->member_rwlock);
     switch_mutex_unlock(conference->mutex);	
 
     if (!count) {
@@ -2113,13 +2122,11 @@
     assert(stream != NULL);
     assert(pfncallback != NULL);
 
-    switch_mutex_lock(conference->member_mutex);
-
+    switch_thread_rwlock_rdlock(conference->member_rwlock);
     for (member = conference->members; member; member = member->next) {
         pfncallback(member, stream, data);
     }
-
-    switch_mutex_unlock(conference->member_mutex);
+    switch_thread_rwlock_unlock(conference->member_rwlock);
 	
 }
 
@@ -2130,7 +2137,7 @@
     assert(conference != NULL);
     assert(stream != NULL);
 
-    switch_mutex_lock(conference->member_mutex);
+    switch_thread_rwlock_rdlock(conference->member_rwlock);
     //		stream->write_function(stream, "<pre>Current Callers:\n");
 
     for (member = conference->members; member; member = member->next) {
@@ -2152,7 +2159,7 @@
 
     }
 
-    switch_mutex_unlock(conference->member_mutex);
+    switch_thread_rwlock_unlock(conference->member_rwlock);
 	
 }
 
@@ -2165,7 +2172,7 @@
     assert(delim != NULL);
 
 
-    switch_mutex_lock(conference->member_mutex);
+    switch_thread_rwlock_rdlock(conference->member_rwlock);
 
     for (member = conference->members; member; member = member->next) {
         switch_channel_t *channel;
@@ -2209,7 +2216,7 @@
                                member->energy_level);
     }
 
-    switch_mutex_unlock(conference->member_mutex);
+    switch_thread_rwlock_unlock(conference->member_rwlock);
 	
 }
 
@@ -2785,23 +2792,17 @@
             uint32_t id = atoi(argv[2]);
             uint32_t oid = atoi(argv[3]);
 
-            switch_mutex_lock(conference->mutex);
-            switch_mutex_lock(conference->member_mutex);
             if ((member = conference_member_get(conference, id))) {
                 member_del_relationship(member, oid);
                 stream->write_function(stream, "relationship %u->%u cleared.", id, oid);
             } else {
                 stream->write_function(stream, "relationship %u->%u not found", id, oid);
             }
-            switch_mutex_unlock(conference->member_mutex);
-            switch_mutex_unlock(conference->mutex);
         } else if (nospeak || nohear) {
             conference_member_t *member = NULL, *other_member = NULL;
             uint32_t id = atoi(argv[2]);
             uint32_t oid = atoi(argv[3]);
 
-            switch_mutex_lock(conference->mutex);
-            switch_mutex_lock(conference->member_mutex);
             if ((member = conference_member_get(conference, id)) && (other_member = conference_member_get(conference, oid))) {
                 conference_relationship_t *rel = NULL;
                 if ((rel = member_get_relationship(member, other_member))) {
@@ -2825,8 +2826,6 @@
             } else {
                 stream->write_function(stream, "relationship %u->%u not found", id, oid);
             }
-            switch_mutex_unlock(conference->member_mutex);
-            switch_mutex_unlock(conference->mutex);
         }
     }
 
@@ -3119,7 +3118,7 @@
                         conference_member_t *member = NULL;
                         conference_member_t *last_member = NULL;
 
-                        switch_mutex_lock(conference->member_mutex);
+                        switch_thread_rwlock_rdlock(conference->member_rwlock);
 
                         /* find last (oldest) member */
                         member = conference->members;
@@ -3136,7 +3135,7 @@
                             pfn(last_member, stream, argv[argn+2]);
                         }
 
-                        switch_mutex_unlock(conference->member_mutex);
+                        switch_thread_rwlock_unlock(conference->member_rwlock);
                     } else {
                         conf_api_member_cmd_t pfn = (conf_api_member_cmd_t)conf_api_sub_commands[i].pfnapicmd;
                         conference_member_t *member = conference_member_get(conference, id);
@@ -4461,9 +4460,9 @@
 
     /* Activate the conference mutex for exclusivity */
     switch_mutex_init(&conference->mutex, SWITCH_MUTEX_NESTED, conference->pool);
-    switch_mutex_init(&conference->member_mutex, SWITCH_MUTEX_NESTED, conference->pool);
     switch_mutex_init(&conference->flag_mutex, SWITCH_MUTEX_NESTED, conference->pool);
     switch_thread_rwlock_create(&conference->rwlock, conference->pool);
+    switch_thread_rwlock_create(&conference->member_rwlock, conference->pool);
 
     return conference;
 }



More information about the Freeswitch-svn mailing list