[asterisk-commits] mmichelson: branch mmichelson/agent_experiment r375298 - in /team/mmichelson/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 22 13:57:08 CDT 2012


Author: mmichelson
Date: Mon Oct 22 13:57:04 2012
New Revision: 375298

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=375298
Log:
Add ao2_cond_wait and ao2_cond_signal.


Modified:
    team/mmichelson/agent_experiment/channels/chan_agent2.c
    team/mmichelson/agent_experiment/include/asterisk/astobj2.h
    team/mmichelson/agent_experiment/main/astobj2.c

Modified: team/mmichelson/agent_experiment/channels/chan_agent2.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/agent_experiment/channels/chan_agent2.c?view=diff&rev=375298&r1=375297&r2=375298
==============================================================================
--- team/mmichelson/agent_experiment/channels/chan_agent2.c (original)
+++ team/mmichelson/agent_experiment/channels/chan_agent2.c Mon Oct 22 13:57:04 2012
@@ -418,19 +418,20 @@
 		return -1;
 	}
 
+	ao2_link(agents, agent);
+
 	if (change_agent_state(agent, &LOGGED_IN)) {
 		ast_log(LOG_WARNING, "Problem attempting to log agent %s in\n", data);
 		return -1;
 	}
 
-	/* XXX Presumably, we need to devise a way to wait here until
-	 * the agent has logged out. The logical way to do this would be
-	 * to use ast_cond_wait(). The problem is that ast_cond_wait()
-	 * requires an ast_mutex_t as the second argument. With ao2 objects,
-	 * we can't get direct access to the lock.
-	 *
-	 * Possible solution: Create an ao2_cond_wait/ao2_cond_signal?
-	 */
+	ao2_cond_wait(agent);
+
+	ao2_unlink(agents, agent);
+
+	if (ast_check_hangup(chan)) {
+		return -1;
+	}
 
 	return 0;
 }

Modified: team/mmichelson/agent_experiment/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/agent_experiment/include/asterisk/astobj2.h?view=diff&rev=375298&r1=375297&r2=375298
==============================================================================
--- team/mmichelson/agent_experiment/include/asterisk/astobj2.h (original)
+++ team/mmichelson/agent_experiment/include/asterisk/astobj2.h Mon Oct 22 13:57:04 2012
@@ -551,6 +551,12 @@
 #define ao2_trylock(a) __ao2_trylock(a, AO2_LOCK_REQ_MUTEX, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
 #define ao2_tryrdlock(a) __ao2_trylock(a, AO2_LOCK_REQ_RDLOCK, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
 #define ao2_trywrlock(a) __ao2_trylock(a, AO2_LOCK_REQ_WRLOCK, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
+
+int __ao2_cond_wait(void *a, const char *file, const char *funct, int line, const char *var);
+#define ao2_cond_wait(a) __ao2_cond_wait(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
+
+int __ao2_cond_signal(void *a, const char *file, const char *func, int line, const char *var);
+#define ao2_cond_signoal(a) __ao2_cond_signal(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
 
 /*!
  * \brief Return the mutex lock address of an object

Modified: team/mmichelson/agent_experiment/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/agent_experiment/main/astobj2.c?view=diff&rev=375298&r1=375297&r2=375298
==============================================================================
--- team/mmichelson/agent_experiment/main/astobj2.c (original)
+++ team/mmichelson/agent_experiment/main/astobj2.c Mon Oct 22 13:57:04 2012
@@ -74,6 +74,7 @@
 
 struct ao2_lock_priv {
 	ast_mutex_t lock;
+	ast_cond_t cond;
 };
 
 /* AstObj2 with recursive lock. */
@@ -170,6 +171,61 @@
  * \return the pointer to the user-defined portion.
  */
 #define EXTERNAL_OBJ(_p)	((_p) == NULL ? NULL : (_p)->user_data)
+
+int __ao2_cond_wait(void *user_data, const char *file, const char *func, int line, const char *var)
+{
+	struct astobj2 *obj = INTERNAL_OBJ(user_data);
+	struct astobj2_lock *obj_mutex;
+	int res = -1;
+
+	if (obj == NULL) {
+		ast_assert(0);
+		return -1;
+	}
+
+	switch (obj->priv_data.options & AO2_ALLOC_OPT_LOCK_MASK) {
+	case AO2_ALLOC_OPT_LOCK_MUTEX:
+		obj_mutex = INTERNAL_OBJ_MUTEX(user_data);
+		res = __ast_cond_wait(file, line, func, var, var, &obj_mutex->mutex.cond, &obj_mutex->mutex.lock);
+		break;
+	case AO2_ALLOC_OPT_LOCK_RWLOCK:
+	case AO2_ALLOC_OPT_LOCK_NOLOCK:
+	default:
+		ast_log(LOG_ERROR, "ao2_cond_wait called with non-mutex lock\n");
+		ast_assert(0);
+		break;
+	}
+	
+	return res;
+}
+
+int __ao2_cond_signal(void *user_data, const char *file, const char *func, int line, const char *var)
+{
+	struct astobj2 *obj = INTERNAL_OBJ(user_data);
+	struct astobj2_lock *obj_mutex;
+	int res = -1;
+
+	if (obj == NULL) {
+		ast_assert(0);
+		return -1;
+	}
+
+	switch (obj->priv_data.options & AO2_ALLOC_OPT_LOCK_MASK) {
+	case AO2_ALLOC_OPT_LOCK_MUTEX:
+		obj_mutex = INTERNAL_OBJ_MUTEX(user_data);
+		res = __ast_cond_signal(file, line, func, var, &obj_mutex->mutex.cond);
+		break;
+	case AO2_ALLOC_OPT_LOCK_RWLOCK:
+	case AO2_ALLOC_OPT_LOCK_NOLOCK:
+	default:
+		ast_log(LOG_ERROR, "ao2_cond_signal called with non-mutex lock\n");
+		ast_assert(0);
+		break;
+	}
+	
+	return res;
+
+}
 
 int __ao2_lock(void *user_data, enum ao2_lock_req lock_how, const char *file, const char *func, int line, const char *var)
 {
@@ -337,6 +393,8 @@
 
 	return res;
 }
+
+
 
 /*!
  * \internal




More information about the asterisk-commits mailing list