[asterisk-commits] russell: branch russell/events r84326 - in /team/russell/events: main/ pbx/ r...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 1 17:44:54 CDT 2007


Author: russell
Date: Mon Oct  1 17:44:54 2007
New Revision: 84326

URL: http://svn.digium.com/view/asterisk?view=rev&rev=84326
Log:
Implement the DLOCK_UNLOCK function.  This is now roughly complete and should
theoretically work.  However, it is completely untested for now ...

Modified:
    team/russell/events/main/asterisk.c
    team/russell/events/pbx/pbx_dundi.c
    team/russell/events/res/ais/lck.c

Modified: team/russell/events/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/asterisk.c?view=diff&rev=84326&r1=84325&r2=84326
==============================================================================
--- team/russell/events/main/asterisk.c (original)
+++ team/russell/events/main/asterisk.c Mon Oct  1 17:44:54 2007
@@ -1163,6 +1163,7 @@
    else.  If your PBX has heavy activity on it, this is a good thing.  */
 int ast_set_priority(int pri)
 {
+#if 0
 	struct sched_param sched;
 	memset(&sched, 0, sizeof(sched));
 #ifdef __linux__
@@ -1191,6 +1192,7 @@
 		/* According to the manpage, these parameters can never fail. */
 		setpriority(PRIO_PROCESS, 0, 0);
 	}
+#endif
 #endif
 	return 0;
 }

Modified: team/russell/events/pbx/pbx_dundi.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/pbx/pbx_dundi.c?view=diff&rev=84326&r1=84325&r2=84326
==============================================================================
--- team/russell/events/pbx/pbx_dundi.c (original)
+++ team/russell/events/pbx/pbx_dundi.c Mon Oct  1 17:44:54 2007
@@ -4614,8 +4614,6 @@
 {
 	struct pub_event_map *pub_event_map;
 	struct ao2_iterator i;
-
-	/* XXX Would this be better done with an ao2_callback loop with OBJ_UNLINK ? */
 
 	i = ao2_iterator_init(pub_event_maps, 0);
 	while ((pub_event_map = ao2_iterator_next(&i))) {

Modified: team/russell/events/res/ais/lck.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/res/ais/lck.c?view=diff&rev=84326&r1=84325&r2=84326
==============================================================================
--- team/russell/events/res/ais/lck.c (original)
+++ team/russell/events/res/ais/lck.c Mon Oct  1 17:44:54 2007
@@ -110,6 +110,14 @@
 static void lock_unref_cb(void *data)
 {
 	struct lock_resource *lock = data;
+	SaAisErrorT ais_res;
+
+	ais_res = saLckResourceUnlock(lock->id, SA_TIME_ONE_SECOND * 3);
+	if (ais_res != SA_AIS_OK) {
+		ast_log(LOG_ERROR, "Error unlocking '%s': %s\n", lock->name->str, 
+			ais_err2str(ais_res));
+	}
+
 	lock_unref(lock);
 }
 
@@ -197,6 +205,8 @@
 	if (ais_res != SA_AIS_OK) {
 		ast_log(LOG_ERROR, "Problem acquiring lock '%s': %s\n",
 			lock->name->str, ais_err2str(ais_res));
+		ast_copy_string(buf, (ais_res == SA_AIS_ERR_TIMEOUT) ? "TIMEOUT" : 
+			"FAILURE", len);
 		return;
 	}
 
@@ -307,9 +317,49 @@
 static int handle_unlock(struct ast_channel *chan, const char *cmd, char *data,
 	char *buf, size_t len)
 {
-	// XXX
-
-	return -1;
+	struct ast_datastore *datastore;
+	struct lock_resource *lock;
+	SaAisErrorT ais_res;
+	int res = 0;
+
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_ERROR, "DLOCK_UNLOCK requires a lock name\n");
+		ast_copy_string(buf, "FAILURE", len);
+		return -1;
+	}
+
+	ast_autoservice_start(chan);
+	
+	ast_channel_lock(chan);
+	datastore = ast_channel_datastore_find(chan, &dlock_datastore_info, lock->name->str);
+	if (!datastore) {
+		ast_log(LOG_ERROR, "The DLOCK '%s' is not locked by channel '%s'\n",
+			lock->name->str, chan->name);
+		ast_channel_unlock(chan);
+		ast_copy_string(buf, "FAILURE", len);
+		return -1;
+	}
+	ast_channel_datastore_remove(chan, datastore);
+	ast_channel_unlock(chan);
+
+	lock = datastore->data;
+	ais_res = saLckResourceUnlock(lock->id, SA_TIME_ONE_SECOND * 3);
+	if (ais_res != SA_AIS_OK) {
+		ast_log(LOG_ERROR, "Error unlocking '%s': %s\n", lock->name->str, 
+			ais_err2str(ais_res));
+		res = -1;
+		ast_copy_string(buf, (ais_res == SA_AIS_ERR_TIMEOUT) ? "TIMEOUT" : 
+			"FAILURE", len);
+	} else {
+		ast_copy_string(buf, "SUCCESS", len);
+	}
+
+	datastore->data = lock_unref(lock);
+	ast_channel_datastore_free(datastore);
+
+	ast_autoservice_stop(chan);
+
+	return res;
 }
 
 static struct ast_custom_function dlock_rdlock = {
@@ -383,7 +433,7 @@
 "  This function will unlock a currently held distributed lock.  This should\n"
 "be used regardless of the lock was read or write locked.  The result of\n"
 "this funtion will be one of the following:\n"
-"      SUCCESS | FAILURE\n"
+"      SUCCESS | TIMEOUT | FAILURE\n"
 "",
 	.syntax = "DLOCK_UNLOCK(<lock_name>)",
 	.read = handle_unlock,




More information about the asterisk-commits mailing list