Bug#356756: [Patch] pthread_mutexes and such

Barry deFreese bddebian at comcast.net
Tue Mar 27 20:52:50 UTC 2007


Folks,

Here is a patch I did for Ubuntu.  It does build and install but I'm a 
little concerned about a couple of things.  For example I didn't do an 
ast_mutex_init() on any of the locks which I believe should be done.  I 
also could not find drop in replacements for pthread_join and 
pthread_equal.  This might be OK but it seems a little odd.  As for #3 
it appears that callerid was moved to a struct cid inside of the 
ast_channel struct.

Hope that helps!

Thanks,

Barry deFreese (aka bddebian)
Ubuntu MOTU


-------------- next part --------------
diff -u rate-engine-0.5.5/debian/changelog rate-engine-0.5.5/debian/changelog
--- rate-engine-0.5.5/debian/changelog
+++ rate-engine-0.5.5/debian/changelog
@@ -1,3 +1,16 @@
+rate-engine (0.5.5-1ubuntu1) feisty; urgency=low
+
+  * Update b-d to libmysqlclient15-dev
+  * Bump standards version to 3.7.2 (no changes)
+  * Bump compat to 5 and dh b-d to >= 5.0.37
+  * rate_engine.c:
+    * Include stdio.h
+    * Use ast_mutex and ast_cond instead of pthread_*
+    * Fix callerid in chan struct (should be chan->cid, not callerid)
+      * Similar for ani (cid_ani is a member of channel->cid struct)
+
+ -- Barry deFreese <bddebian at comcast.net>  Tue, 27 Mar 2007 11:10:47 -0400
+
 rate-engine (0.5.5-1) unstable; urgency=low
 
   * New upstream release
diff -u rate-engine-0.5.5/debian/control rate-engine-0.5.5/debian/control
--- rate-engine-0.5.5/debian/control
+++ rate-engine-0.5.5/debian/control
@@ -1,10 +1,11 @@
 Source: rate-engine
 Section: comm
 Priority: optional
-Maintainer: Debian VoIP Team <pkg-voip-maintainers at lists.alioth.debian.org>
+XSBC-Original-Maintainer: Debian VoIP Team <pkg-voip-maintainers at lists.alioth.debian.org>
+Maintainer: Ubuntu MOTU Devolopers <ubuntu-motu at lists.ubuntu.com>
 Uploaders: Mark Purcell <msp at debian.org>
-Build-Depends: debhelper (>= 4.0.0), libpcre3-dev, libmysqlclient14-dev, asterisk-dev
-Standards-Version: 3.6.0
+Build-Depends: debhelper (>= 5.0.37), libpcre3-dev, libmysqlclient15-dev, asterisk-dev
+Standards-Version: 3.7.2
 
 Package: asterisk-rate-engine
 Conflicts: rate-engine
diff -u rate-engine-0.5.5/debian/compat rate-engine-0.5.5/debian/compat
--- rate-engine-0.5.5/debian/compat
+++ rate-engine-0.5.5/debian/compat
@@ -1 +1 @@
-4
+5
only in patch2:
unchanged:
--- rate-engine-0.5.5.orig/rate_engine.c
+++ rate-engine-0.5.5/rate_engine.c
@@ -15,10 +15,12 @@
 #endif
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 
-#include <pthread.h>
+/* Now included by asterisk/lock.h */
+/* #include <pthread.h> */
 
 #include <mysql.h>
 
@@ -36,6 +38,7 @@
 #include <asterisk/manager.h>
 #include <asterisk/utils.h>
 #include <asterisk/term.h>
+#include <asterisk/lock.h>
 
 static char *tdesc = "Call Routing and Rating Application";
 static char *cdr_name = "ratecall";
@@ -66,8 +69,8 @@
 
 static pthread_t poster_thread;
 static int cancel_poster = 0;
-static pthread_mutex_t poster_lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t poster_cond = PTHREAD_COND_INITIALIZER;
+static ast_mutex_t poster_lock;
+static ast_cond_t poster_cond;
 
 static int warn_threshold = 500;	/* Start giving warnings if CDR queue is this long */
 static int drop_threshold = 1000;	/* Start dropping entries if CDR queue is this long */
@@ -255,7 +258,7 @@
 	/*
 	 * Jump to priority + 101, since we got an error
 	 */
-	if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
+	if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_dnid))
 	    chan->priority += 100;
 	else
 	    res = -1;
@@ -511,7 +514,7 @@
     /*
      * Jump to priority + 101, since we got an error
      */
-    if (res == 0 && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->callerid))
+    if (res == 0 && ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_dnid))
 	chan->priority += 100;
     else
 	res = -1;
@@ -593,9 +596,9 @@
     /*
      * Try to pick up real ANI if that exists
      */
-    if (chan && chan->ani) {
-	if ((ani = alloca((len = strlen(chan->ani)) * 2 + 1)) != NULL)
-	    mysql_real_escape_string(&mysql, ani, chan->ani, len);
+    if (chan && chan->cid.cid_ani) {
+	if ((ani = alloca((len = strlen(chan->cid.cid_ani)) * 2 + 1)) != NULL)
+	    mysql_real_escape_string(&mysql, ani, chan->cid.cid_ani, len);
     }
     else
 	ani = src;
@@ -702,7 +705,7 @@
     /*
      * Acquire shared data lock
      */
-    pthread_mutex_lock(&poster_lock);
+    ast_mutex_lock(&poster_lock);
 
     /*
      * Only add to queue if we are below the maximum threshold
@@ -735,12 +738,12 @@
     /*
      * Signal worker thread that there is data available
      */
-    pthread_cond_signal(&poster_cond);
+    ast_cond_signal(&poster_cond);
 
     /*
      * Release shared data lock
      */
-    pthread_mutex_unlock(&poster_lock);
+    ast_mutex_unlock(&poster_lock);
 
     return 0;
 }
@@ -763,7 +766,7 @@
     /*
      * Get lock on shared data
      */
-    pthread_mutex_lock(&poster_lock);
+    ast_mutex_lock(&poster_lock);
 
     /*
      * We need a timeout if there is something on the queue
@@ -786,8 +789,8 @@
      * Wait for [more] data to be available
      */
     for (;; (queue_head ?
-	     (ts.tv_sec = time(NULL) + 30, ts.tv_nsec = 0, pthread_cond_timedwait(&poster_cond, &poster_lock, &ts)) :
-	     pthread_cond_wait(&poster_cond, &poster_lock))) {
+	     (ts.tv_sec = time(NULL) + 30, ts.tv_nsec = 0, ast_cond_timedwait(&poster_cond, &poster_lock, &ts)) :
+	     ast_cond_wait(&poster_cond, &poster_lock))) {
 
 	ast_log(LOG_DEBUG, "Rating Engine poster thread processing\n");
 
@@ -804,7 +807,7 @@
 	 * take a little while, so release the lock while we do
 	 * that
 	 */
-	pthread_mutex_unlock(&poster_lock);
+	ast_mutex_unlock(&poster_lock);
 
 	/*
 	 * If we are not connected to a database, try to connect
@@ -818,7 +821,7 @@
 		/*
 		 * Reacquire the lock before we restart loop
 		 */
-		pthread_mutex_lock(&poster_lock);
+		ast_mutex_lock(&poster_lock);
 
 		continue;
 	    }
@@ -835,7 +838,7 @@
 	    /*
 	     * Reacquire the lock before we restart loop
 	     */
-	    pthread_mutex_lock(&poster_lock);
+	    ast_mutex_lock(&poster_lock);
 
 	    continue;
 	}
@@ -844,7 +847,7 @@
 	 * We do have to reacquire the lock before we can actually
 	 * touch the queue, however...
 	 */
-	pthread_mutex_lock(&poster_lock);
+	ast_mutex_lock(&poster_lock);
 
 	/*
 	 * Process CDR records on queue
@@ -864,7 +867,7 @@
 	    /*
 	     * Release the lock before doing potentially long operation
 	     */
-	    pthread_mutex_unlock(&poster_lock);
+	    ast_mutex_unlock(&poster_lock);
 
 	    /*
 	     * Perform query
@@ -879,7 +882,7 @@
 	    /*
 	     * Re-acquire the lock
 	     */
-	    pthread_mutex_lock(&poster_lock);
+	    ast_mutex_lock(&poster_lock);
 
 	    /*
 	     * If we errored out of sending the CDR entry, put it back
@@ -911,7 +914,7 @@
     /*
      * Release the lock before exiting thread
      */
-    pthread_mutex_unlock(&poster_lock);
+    ast_mutex_unlock(&poster_lock);
 
     /*
      * Close connection if it is open
@@ -2089,18 +2092,18 @@
 	/*
 	 * Get lock on shared data
 	 */
-	pthread_mutex_lock(&poster_lock);
+	ast_mutex_lock(&poster_lock);
 
 	/*
 	 * Tell posting thread to exit and signal a change
 	 */
 	cancel_poster = 1;
-	pthread_cond_signal(&poster_cond);
+	ast_cond_signal(&poster_cond);
 
 	/*
 	 * Release lock on shared data
 	 */
-	pthread_mutex_unlock(&poster_lock);
+	ast_mutex_unlock(&poster_lock);
 
 	/*
 	 * Wait for posting thread to exit


More information about the Pkg-voip-maintainers mailing list