[asterisk-commits] russell: trunk r84143 - /trunk/funcs/func_lock.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Sep 29 22:05:05 CDT 2007


Author: russell
Date: Sat Sep 29 22:05:04 2007
New Revision: 84143

URL: http://svn.digium.com/view/asterisk?view=rev&rev=84143
Log:
* The documentation for the LOCK() function says that it will block for up to
  3 seconds while waiting on a lock when other locks are currently held to
  avoid deadlocks.  Change the code to reflect this.
* Since trying to grab a lock may block for some time, put the channel in
  autoservice so that audio is still read from the channel and that any
  active generators on the channel don't pause.

Modified:
    trunk/funcs/func_lock.c

Modified: trunk/funcs/func_lock.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_lock.c?view=diff&rev=84143&r1=84142&r2=84143
==============================================================================
--- trunk/funcs/func_lock.c (original)
+++ trunk/funcs/func_lock.c Sat Sep 29 22:05:04 2007
@@ -187,11 +187,12 @@
 
 	/* Okay, we have both frames, so now we need to try to lock the mutex. */
 	if (count_channel_locks > 1) {
-		/* If we fail after a certain number of attempts, assume a possible deadlock and bail. */
-		int x;
-		for (x = 0; x < 30; x++) {
+		struct timeval start = ast_tvnow();
+		for (;;) {
 			if ((res = ast_mutex_trylock(&current->mutex)) == 0)
 				break;
+			if (ast_tvdiff_ms(ast_tvnow(), start) > 3000)
+				break; /* bail after 3 seconds of waiting */
 			usleep(1);
 		}
 	} else {
@@ -256,13 +257,19 @@
 
 static int lock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
+	ast_autoservice_start(chan);
 	ast_copy_string(buf, get_lock(chan, data, 0) ? "0" : "1", len);
+	ast_autoservice_stop(chan);
+
 	return 0;
 }
 
 static int trylock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
+	ast_autoservice_start(chan);
 	ast_copy_string(buf, get_lock(chan, data, 1) ? "0" : "1", len);
+	ast_autoservice_stop(chan);
+
 	return 0;
 }
 




More information about the asterisk-commits mailing list