[svn-commits] seanbright: branch seanbright/resolve-shadow-warnings r122724 - in /team/sean...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jun 13 17:19:10 CDT 2008


Author: seanbright
Date: Fri Jun 13 17:19:09 2008
New Revision: 122724

URL: http://svn.digium.com/view/asterisk?view=rev&rev=122724
Log:
Merged revisions 122523,122526,122557,122616,122664,122714,122716 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r122523 | russell | 2008-06-13 08:45:50 -0400 (Fri, 13 Jun 2008) | 11 lines

Merge changes from timing branch

 - Convert chan_iax2 to use the timing API
 - Convert usage of timing in the core to use the timing API instead of
   using DAHDI directly
 - Make a change to the timing API to add the set_rate() function
 - change the timing core to use a rwlock
 - merge a timing implementation, res_timing_dahdi

Basic testing was successful using res_timing_dahdi

................
r122526 | russell | 2008-06-13 08:53:08 -0400 (Fri, 13 Jun 2008) | 3 lines

Do not allow res_timing_dahdi to be unloaded.  We can re-enable this once we
add automatic use count handling for timing modules.

................
r122557 | tilghman | 2008-06-13 10:15:07 -0400 (Fri, 13 Jun 2008) | 7 lines

Convert one more delimiter to use comma.
(closes issue #12850)
 Reported by: bcnit
 Patches: 
       20080613__bug12850.diff.txt uploaded by Corydon76 (license 14)
 Tested by: bcnit

................
r122616 | jpeeler | 2008-06-13 13:38:28 -0400 (Fri, 13 Jun 2008) | 13 lines

Blocked revisions 122613 via svnmerge

........
r122613 | jpeeler | 2008-06-13 12:36:56 -0500 (Fri, 13 Jun 2008) | 6 lines

(closes issue #12846)
Reported by: Netview
Tested by: jpeeler

Use correct location to search for tonezone.

........

................
r122664 | jpeeler | 2008-06-13 14:58:29 -0400 (Fri, 13 Jun 2008) | 8 lines

Blocked revisions 122663 via svnmerge

........
r122663 | jpeeler | 2008-06-13 13:57:24 -0500 (Fri, 13 Jun 2008) | 1 line

fixed dahdi compatability header from assuming either dahdi or zaptel is installed (may not have either)
........

................
r122714 | mmichelson | 2008-06-13 17:45:21 -0400 (Fri, 13 Jun 2008) | 17 lines

Merged revisions 122713 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r122713 | mmichelson | 2008-06-13 16:44:53 -0500 (Fri, 13 Jun 2008) | 9 lines

Short circuit the loop in autoservice_run if there are no channels to poll.
If we continued, then the result would be calling poll() with a NULL
pollfd array. While this is fine with POSIX's poll(2) system call, those
who use Asterisk's internal poll mechanism (Darwin systems) would have
a failed assertion occur when poll is called.

(related to issue #10342)


........

................
r122716 | tilghman | 2008-06-13 17:50:28 -0400 (Fri, 13 Jun 2008) | 2 lines

Properly detect the size of char/varchar fields

................

Added:
    team/seanbright/resolve-shadow-warnings/res/res_timing_dahdi.c
      - copied unchanged from r122716, trunk/res/res_timing_dahdi.c
Modified:
    team/seanbright/resolve-shadow-warnings/   (props changed)
    team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c
    team/seanbright/resolve-shadow-warnings/include/asterisk/channel.h
    team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h
    team/seanbright/resolve-shadow-warnings/main/asterisk.c
    team/seanbright/resolve-shadow-warnings/main/autoservice.c
    team/seanbright/resolve-shadow-warnings/main/channel.c
    team/seanbright/resolve-shadow-warnings/main/dial.c
    team/seanbright/resolve-shadow-warnings/main/file.c
    team/seanbright/resolve-shadow-warnings/main/timing.c
    team/seanbright/resolve-shadow-warnings/res/res_config_pgsql.c

Propchange: team/seanbright/resolve-shadow-warnings/
------------------------------------------------------------------------------
Binary property 'branch-1.4-blocked' - no diff available.

Propchange: team/seanbright/resolve-shadow-warnings/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Propchange: team/seanbright/resolve-shadow-warnings/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jun 13 17:19:09 2008
@@ -1,1 +1,1 @@
-/trunk:1-122516
+/trunk:1-122717

Modified: team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c (original)
+++ team/seanbright/resolve-shadow-warnings/channels/chan_iax2.c Fri Jun 13 17:19:09 2008
@@ -31,7 +31,6 @@
  */
 
 /*** MODULEINFO
-	<use>dahdi</use>
 	<use>crypto</use>
  ***/
 
@@ -55,7 +54,6 @@
 #include <sys/stat.h>
 #include <regex.h>
 
-#include "asterisk/dahdi.h"
 #include "asterisk/paths.h"	/* need ast_config_AST_DATA_DIR for firmware */
 
 #include "asterisk/lock.h"
@@ -89,6 +87,7 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/event.h"
 #include "asterisk/astobj2.h"
+#include "asterisk/timing.h"
 
 #include "iax2.h"
 #include "iax2-parser.h"
@@ -7255,32 +7254,17 @@
 
 static int timing_read(int *id, int fd, short events, void *cbdata)
 {
-	char buf[1024];
 	int res, processed = 0, totalcalls = 0;
 	struct iax2_trunk_peer *tpeer = NULL, *drop = NULL;
-#ifdef DAHDI_TIMERACK
-	int x = 1;
-#endif
 	struct timeval now = ast_tvnow();
+
 	if (iaxtrunkdebug)
 		ast_verbose("Beginning trunk processing. Trunk queue ceiling is %d bytes per host\n", trunkmaxsize);
-	if (events & AST_IO_PRI) {
-#ifdef DAHDI_TIMERACK
-		/* Great, this is a timing interface, just call the ioctl */
-		if (ioctl(fd, DAHDI_TIMERACK, &x)) {
-			ast_log(LOG_WARNING, "Unable to acknowledge DAHDI timer. IAX trunking will fail!\n");
-			usleep(1);
-			return -1;
-		}
-#endif		
-	} else {
-		/* Read and ignore from the pseudo channel for timing */
-		res = read(fd, buf, sizeof(buf));
-		if (res < 1) {
-			ast_log(LOG_WARNING, "Unable to read from timing fd\n");
-			return 1;
-		}
-	}
+
+	if (timingfd > -1) { 
+		ast_timer_ack(timingfd, 1);
+	}
+
 	/* For each peer that supports trunking... */
 	AST_LIST_LOCK(&tpeers);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&tpeers, tpeer, list) {
@@ -10846,21 +10830,6 @@
 	}
 }
 
-static void set_timing(void)
-{
-#ifdef HAVE_DAHDI
-	int bs = trunkfreq * 8;
-	if (timingfd > -1) {
-		if (
-#ifdef DAHDI_TIMERACK
-			ioctl(timingfd, DAHDI_TIMERCONFIG, &bs) &&
-#endif			
-			ioctl(timingfd, DAHDI_SET_BLOCKSIZE, &bs))
-			ast_log(LOG_WARNING, "Unable to set blocksize on timing source\n");
-	}
-#endif
-}
-
 static void set_config_destroy(void)
 {
 	strcpy(accountcode, "");
@@ -11267,7 +11236,6 @@
 		cat = ast_category_browse(cfg, cat);
 	}
 	ast_config_destroy(cfg);
-	set_timing();
 	return 1;
 }
 
@@ -12050,7 +12018,11 @@
 	ao2_ref(peers, -1);
 	ao2_ref(users, -1);
 	ao2_ref(iax_peercallno_pvts, -1);
-	
+
+	if (timingfd > -1) {
+		ast_timer_close(timingfd);
+	}
+
 	con = ast_context_find(regcontext);
 	if (con)
 		ast_context_destroy(con, "IAX2");
@@ -12121,16 +12093,6 @@
 	iax_set_output(iax_debug_output);
 	iax_set_error(iax_error_output);
 	jb_setoutput(jb_error_output, jb_warning_output, NULL);
-	
-#ifdef HAVE_DAHDI
-#ifdef DAHDI_TIMERACK
-	timingfd = open("/dev/dahdi/timer", O_RDWR);
-	if (timingfd < 0)
-#endif
-		timingfd = open("/dev/dahdi/pseudo", O_RDWR);
-	if (timingfd < 0) 
-		ast_log(LOG_WARNING, "Unable to open IAX timing interface: %s\n", strerror(errno));
-#endif		
 
 	memset(iaxs, 0, sizeof(iaxs));
 
@@ -12179,6 +12141,11 @@
 	if(set_config(config, 0) == -1)
 		return AST_MODULE_LOAD_DECLINE;
 
+	timingfd = ast_timer_open();
+	if (timingfd > -1) {
+		ast_timer_set_rate(timingfd, trunkfreq);
+	}
+
  	if (ast_channel_register(&iax2_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel class %s\n", "IAX2");
 		__unload_module();

Modified: team/seanbright/resolve-shadow-warnings/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/include/asterisk/channel.h?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/include/asterisk/channel.h (original)
+++ team/seanbright/resolve-shadow-warnings/include/asterisk/channel.h Fri Jun 13 17:19:09 2008
@@ -1423,9 +1423,17 @@
  */
 int ast_autoservice_stop(struct ast_channel *chan);
 
-/* If built with dahdi optimizations, force a scheduled expiration on the
-   timer fd, at which point we call the callback function / data */
-int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data);
+/*!
+ * \brief Enable or disable timer ticks for a channel
+ *
+ * \arg rate number of timer ticks per second
+ *
+ * If timers are supported, force a scheduled expiration on the
+ * timer fd, at which point we call the callback function / data 
+ *
+ * Call this function with a rate of 0 to turn off the timer ticks
+ */
+int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
 
 /*!	\brief Transfer a channel (if supported).  Returns -1 on error, 0 if not supported
    and 1 if supported and requested 

Modified: team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h (original)
+++ team/seanbright/resolve-shadow-warnings/include/asterisk/timing.h Fri Jun 13 17:19:09 2008
@@ -65,8 +65,9 @@
  * public API calls.
  */
 struct ast_timing_functions {
-	int (*timer_open)(unsigned int rate);
+	int (*timer_open)(void);
 	void (*timer_close)(int handle);
+	int (*timer_set_rate)(int handle, unsigned int rate);
 	void (*timer_ack)(int handle, unsigned int quantity);
 	int (*timer_enable_continuous)(int handle);
 	int (*timer_disable_continuous)(int handle);
@@ -97,12 +98,10 @@
 /*!
  * \brief Open a timing fd
  *
- * \arg rate number of timer ticks per second
- *
  * \retval -1 error, with errno set
  * \retval >=0 success
  */
-int ast_timer_open(unsigned int rate);
+int ast_timer_open(void);
 
 /*!
  * \brief Close an opened timing handle
@@ -112,6 +111,21 @@
  * \return nothing
  */
 void ast_timer_close(int handle);
+
+/*!
+ * \brief Set the timing tick rate
+ *
+ * \arg handle timing fd returned from timer_open()
+ * \arg rate ticks per second, 0 turns the ticks off if needed
+ *
+ * Use this function if you want the timing fd to show input at a certain
+ * rate.  The other alternative use of a timing fd, is using the continuous
+ * mode.
+ *
+ * \retval -1 error, with errno set
+ * \retval 0 success
+ */
+int ast_timer_set_rate(int handle, unsigned int rate);
 
 /*!
  * \brief Acknowledge a timer event

Modified: team/seanbright/resolve-shadow-warnings/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/main/asterisk.c?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/main/asterisk.c (original)
+++ team/seanbright/resolve-shadow-warnings/main/asterisk.c Fri Jun 13 17:19:09 2008
@@ -3299,36 +3299,7 @@
 		printf("%s", term_quit());
 		exit(1);
 	}
-#ifdef HAVE_DAHDI
-	{
-		int fd;
-		int period = 160;
-		
-		fd = open("/dev/dahdi/timer", O_RDWR);
-		if (fd >= 0) {
-			if (ioctl(fd, DAHDI_TIMERCONFIG, &period)) {
-				ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer test failed to set DAHDI_TIMERCONFIG to %d.\n", period);
-				exit(1);
-			}
-			if ((period = ast_wait_for_input(fd, 300)) < 0) {
-				ast_log(LOG_ERROR, "You have DAHDI built and drivers loaded, but the DAHDI timer could not be polled during the DAHDI timer test.\n");
-				exit(1);
-			}
-			if (!period) {
-				const char dahdi_timer_error[] = {
-					"Asterisk has detected a problem with your DAHDI configuration and will shutdown for your protection.  You have options:"
-					"\n\t1. You only have to compile DAHDI support into Asterisk if you need it.  One option is to recompile without DAHDI support."
-					"\n\t2. You only have to load DAHDI drivers if you want to take advantage of DAHDI services.  One option is to unload DAHDI modules if you don't need them."
-					"\n\t3. If you need DAHDI services, you must correctly configure DAHDI."
-				};
-				ast_log(LOG_ERROR, "%s\n", dahdi_timer_error);
-				usleep(100);
-				exit(1);
-			}
-			close(fd);
-		}
-	}
-#endif
+
 	threadstorage_init();
 
 	astobj2_init();

Modified: team/seanbright/resolve-shadow-warnings/main/autoservice.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/main/autoservice.c?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/main/autoservice.c (original)
+++ team/seanbright/resolve-shadow-warnings/main/autoservice.c Fri Jun 13 17:19:09 2008
@@ -100,6 +100,10 @@
 		}
 
 		AST_LIST_UNLOCK(&aslist);
+
+		if (!x) {
+			continue;
+		}
 
 		chan = ast_waitfor_n(mons, x, &ms);
 		if (!chan) {

Modified: team/seanbright/resolve-shadow-warnings/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/main/channel.c?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/main/channel.c (original)
+++ team/seanbright/resolve-shadow-warnings/main/channel.c Fri Jun 13 17:19:09 2008
@@ -61,6 +61,7 @@
 #include "asterisk/threadstorage.h"
 #include "asterisk/slinfactory.h"
 #include "asterisk/audiohook.h"
+#include "asterisk/timing.h"
 
 #ifdef HAVE_EPOLL
 #include <sys/epoll.h>
@@ -808,27 +809,19 @@
 #endif
 	}
 
-#ifdef HAVE_DAHDI
-	tmp->timingfd = open("/dev/dahdi/timer", O_RDWR);
+	tmp->timingfd = ast_timer_open();
 	if (tmp->timingfd > -1) {
-		/* Check if timing interface supports new
-		   ping/pong scheme */
-		flags = 1;
-		if (!ioctl(tmp->timingfd, DAHDI_TIMERPONG, &flags))
-			needqueue = 0;
-	}
-#else
-	tmp->timingfd = -1;					
-#endif					
+		needqueue = 0;
+	}
 
 	if (needqueue) {
 		if (pipe(tmp->alertpipe)) {
 			ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
 alertpipe_failed:
-#ifdef HAVE_DAHDI
-			if (tmp->timingfd > -1)
-				close(tmp->timingfd);
-#endif
+			if (tmp->timingfd > -1) {
+				ast_timer_close(tmp->timingfd);
+			}
+
 			sched_context_destroy(tmp->sched);
 			ast_string_field_free_memory(tmp);
 			ast_free(tmp);
@@ -1007,10 +1000,8 @@
 		if (write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah))
 			ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d (qlen = %d): %s!\n",
 				chan->name, f->frametype, f->subclass, qlen, strerror(errno));
-#ifdef HAVE_DAHDI
 	} else if (chan->timingfd > -1) {
-		ioctl(chan->timingfd, DAHDI_TIMERPING, &blah);
-#endif				
+		ast_timer_enable_continuous(chan->timingfd);
 	} else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
 		pthread_kill(chan->blocker, SIGURG);
 	}
@@ -1343,7 +1334,7 @@
 	if ((fd = chan->alertpipe[1]) > -1)
 		close(fd);
 	if ((fd = chan->timingfd) > -1)
-		close(fd);
+		ast_timer_close(fd);
 #ifdef HAVE_EPOLL
 	for (i = 0; i < AST_MAX_FDS; i++) {
 		if (chan->epfd_data[i])
@@ -1795,7 +1786,7 @@
 	}
 	
 	if (!res) {
-		ast_settimeout(chan, 160, generator_force, chan);
+		ast_settimeout(chan, 50, generator_force, chan);
 		chan->generator = gen;
 	}
 
@@ -2181,21 +2172,26 @@
 	return ast_waitfordigit_full(c, ms, -1, -1);
 }
 
-int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data)
-{
-	int res = -1;
-#ifdef HAVE_DAHDI
-	if (c->timingfd > -1) {
-		if (!func) {
-			samples = 0;
-			data = 0;
-		}
-		ast_debug(1, "Scheduling timer at %d sample intervals\n", samples);
-		res = ioctl(c->timingfd, DAHDI_TIMERCONFIG, &samples);
-		c->timingfunc = func;
-		c->timingdata = data;
-	}
-#endif	
+int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data)
+{
+	int res;
+
+	if (c->timingfd == -1) {
+		return -1;
+	}
+
+	if (!func) {
+		rate = 0;
+		data = NULL;
+	}
+
+	ast_debug(1, "Scheduling timer at %u timer ticks per second\n", rate);
+
+	res = ast_timer_set_rate(c->timingfd, rate);
+
+	c->timingfunc = func;
+	c->timingdata = data;
+
 	return res;
 }
 
@@ -2334,7 +2330,7 @@
 	} else if (f->frametype == AST_FRAME_CNG) {
 		if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) {
 			ast_debug(1, "Generator got CNG, switching to timed mode\n");
-			ast_settimeout(chan, 160, generator_force, chan);
+			ast_settimeout(chan, 50, generator_force, chan);
 		}
 	}
 }

Modified: team/seanbright/resolve-shadow-warnings/main/dial.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/main/dial.c?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/main/dial.c (original)
+++ team/seanbright/resolve-shadow-warnings/main/dial.c Fri Jun 13 17:19:09 2008
@@ -91,7 +91,7 @@
 		return NULL;
 	
 	/* Parse out application and arguments */
-	if ((args = strchr(app, '|'))) {
+	if ((args = strchr(app, ','))) {
 		*args++ = '\0';
 		answer_exec->args = ast_strdup(args);
 	}

Modified: team/seanbright/resolve-shadow-warnings/main/file.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/main/file.c?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/main/file.c (original)
+++ team/seanbright/resolve-shadow-warnings/main/file.c Fri Jun 13 17:19:09 2008
@@ -29,6 +29,7 @@
 
 #include <dirent.h>
 #include <sys/stat.h>
+#include <math.h>
 
 #include "asterisk/_private.h"	/* declare ast_file_init() */
 #include "asterisk/paths.h"	/* use ast_config_AST_DATA_DIR */
@@ -659,21 +660,17 @@
 		}
 	}
 	if (whennext != s->lasttimeout) {
-#ifdef HAVE_DAHDI
 		if (s->owner->timingfd > -1) {
-			int zap_timer_samples = whennext;
-			int rate;
-			/* whennext is in samples, but DAHDI timers operate in 8 kHz samples. */
-			if ((rate = ast_format_rate(s->fmt->format)) != 8000) {
-				float factor;
-				factor = ((float) rate) / ((float) 8000.0); 
-				zap_timer_samples = (int) ( ((float) zap_timer_samples) / factor );
-			}
-			ast_settimeout(s->owner, zap_timer_samples, ast_fsread_audio, s);
-		} else
-#endif		
+			float samp_rate = (float) ast_format_rate(s->fmt->format);
+			unsigned int rate;
+
+			rate = (unsigned int) roundf(samp_rate / ((float) whennext));
+
+			ast_settimeout(s->owner, rate, ast_fsread_audio, s);
+		} else {
 			s->owner->streamid = ast_sched_add(s->owner->sched, 
 				whennext / (ast_format_rate(s->fmt->format) / 1000), ast_fsread_audio, s);
+		}
 		s->lasttimeout = whennext;
 		return FSREAD_SUCCESS_NOSCHED;
 	}
@@ -681,9 +678,7 @@
 
 return_failure:
 	s->owner->streamid = -1;
-#ifdef HAVE_DAHDI
 	ast_settimeout(s->owner, 0, NULL, NULL);
-#endif			
 	return FSREAD_FAILURE;
 }
 
@@ -792,9 +787,7 @@
 		if (f->fmt->format & AST_FORMAT_AUDIO_MASK) {
 			f->owner->stream = NULL;
 			AST_SCHED_DEL(f->owner->sched, f->owner->streamid);
-#ifdef HAVE_DAHDI
 			ast_settimeout(f->owner, 0, NULL, NULL);
-#endif			
 		} else {
 			f->owner->vstream = NULL;
 			AST_SCHED_DEL(f->owner->sched, f->owner->vstreamid);

Modified: team/seanbright/resolve-shadow-warnings/main/timing.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/main/timing.c?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/main/timing.c (original)
+++ team/seanbright/resolve-shadow-warnings/main/timing.c Fri Jun 13 17:19:09 2008
@@ -30,7 +30,7 @@
 #include "asterisk/timing.h"
 #include "asterisk/lock.h"
 
-AST_MUTEX_DEFINE_STATIC(lock);
+AST_RWLOCK_DEFINE_STATIC(lock);
 
 static struct ast_timing_functions timer_funcs;
 
@@ -38,6 +38,7 @@
 {
 	if (!funcs->timer_open ||
 	    !funcs->timer_close ||
+		!funcs->timer_set_rate ||
 	    !funcs->timer_ack ||
 	    !funcs->timer_get_event ||
 	    !funcs->timer_enable_continuous ||
@@ -45,94 +46,113 @@
 		return NULL;
 	}
 
-	ast_mutex_lock(&lock);
+	ast_rwlock_wrlock(&lock);
 
 	if (timer_funcs.timer_open) {
-		ast_mutex_unlock(&lock);
+		ast_rwlock_unlock(&lock);
+		ast_log(LOG_NOTICE, "Multiple timing modules are loaded.  You should only load one.\n");
 		return NULL;
 	}
 	
 	timer_funcs = *funcs;
 
-	ast_mutex_unlock(&lock);
+	ast_rwlock_unlock(&lock);
 
 	return &timer_funcs;
 }
 
 void ast_uninstall_timing_functions(void *handle)
 {
-	ast_mutex_lock(&lock);
+	ast_rwlock_wrlock(&lock);
 
 	if (handle != &timer_funcs) {
-		ast_mutex_unlock(&lock);
+		ast_rwlock_unlock(&lock);
 		return;
 	}
 
 	memset(&timer_funcs, 0, sizeof(timer_funcs));
 
-	ast_mutex_unlock(&lock);
+	ast_rwlock_unlock(&lock);
 }
 
-int ast_timer_open(unsigned int rate)
+int ast_timer_open(void)
 {
 	int timer;
 
-	ast_mutex_lock(&lock);
+	ast_rwlock_rdlock(&lock);
 
 	if (!timer_funcs.timer_open) {
-		ast_mutex_unlock(&lock);
+		ast_rwlock_unlock(&lock);
 		return -1;
 	}
 
-	timer = timer_funcs.timer_open(rate);
+	timer = timer_funcs.timer_open();
 
-	ast_mutex_unlock(&lock);
+	ast_rwlock_unlock(&lock);
 
 	return timer;
 }
 
 void ast_timer_close(int timer)
 {
-	ast_mutex_lock(&lock);
+	ast_rwlock_rdlock(&lock);
 
 	if (!timer_funcs.timer_close) {
-		ast_mutex_unlock(&lock);
+		ast_rwlock_unlock(&lock);
 		return;
 	}
 
 	timer_funcs.timer_close(timer);
 
-	ast_mutex_unlock(&lock);
+	ast_rwlock_unlock(&lock);
+}
+
+int ast_timer_set_rate(int handle, unsigned int rate)
+{
+	int res;
+
+	ast_rwlock_rdlock(&lock);
+
+	if (!timer_funcs.timer_set_rate) {
+		ast_rwlock_unlock(&lock);
+		return -1;
+	}
+
+	res = timer_funcs.timer_set_rate(handle, rate);
+
+	ast_rwlock_unlock(&lock);
+
+	return res;
 }
 
 void ast_timer_ack(int handle, unsigned int quantity)
 {
-	ast_mutex_lock(&lock);
+	ast_rwlock_rdlock(&lock);
 
 	if (!timer_funcs.timer_ack) {
-		ast_mutex_unlock(&lock);
+		ast_rwlock_unlock(&lock);
 		return;
 	}
 
 	timer_funcs.timer_ack(handle, quantity);
 
-	ast_mutex_unlock(&lock);
+	ast_rwlock_unlock(&lock);
 }
 
 int ast_timer_enable_continuous(int handle)
 {
 	int result;
 
-	ast_mutex_lock(&lock);
+	ast_rwlock_rdlock(&lock);
 
 	if (!timer_funcs.timer_enable_continuous) {
-		ast_mutex_unlock(&lock);
+		ast_rwlock_unlock(&lock);
 		return -1;
 	}
 
 	result = timer_funcs.timer_enable_continuous(handle);
 
-	ast_mutex_unlock(&lock);
+	ast_rwlock_unlock(&lock);
 
 	return result;
 }
@@ -141,16 +161,16 @@
 {
 	int result;
 
-	ast_mutex_lock(&lock);
+	ast_rwlock_rdlock(&lock);
 
 	if (!timer_funcs.timer_disable_continuous) {
-		ast_mutex_unlock(&lock);
+		ast_rwlock_unlock(&lock);
 		return -1;
 	}
 
 	result = timer_funcs.timer_disable_continuous(handle);
 
-	ast_mutex_unlock(&lock);
+	ast_rwlock_unlock(&lock);
 
 	return result;
 }
@@ -159,16 +179,16 @@
 {
 	enum ast_timing_event result;
 
-	ast_mutex_lock(&lock);
+	ast_rwlock_rdlock(&lock);
 
 	if (!timer_funcs.timer_get_event) {
-		ast_mutex_unlock(&lock);
+		ast_rwlock_unlock(&lock);
 		return -1;
 	}
 
 	result = timer_funcs.timer_get_event(handle);
 
-	ast_mutex_unlock(&lock);
+	ast_rwlock_unlock(&lock);
 
 	return result;
 }

Modified: team/seanbright/resolve-shadow-warnings/res/res_config_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/seanbright/resolve-shadow-warnings/res/res_config_pgsql.c?view=diff&rev=122724&r1=122723&r2=122724
==============================================================================
--- team/seanbright/resolve-shadow-warnings/res/res_config_pgsql.c (original)
+++ team/seanbright/resolve-shadow-warnings/res/res_config_pgsql.c Fri Jun 13 17:19:09 2008
@@ -123,7 +123,7 @@
 	ast_debug(1, "Table '%s' not found in cache, querying now\n", tablename);
 
 	/* Not found, scan the table */
-	ast_str_set(&sql, 0, "SELECT a.attname, t.typname, a.attlen, a.attnotnull, d.adsrc FROM pg_class c, pg_type t, pg_attribute a LEFT OUTER JOIN pg_attrdef d ON a.atthasdef AND d.adrelid = a.attrelid AND d.adnum = a.attnum WHERE c.oid = a.attrelid AND a.atttypid = t.oid AND (a.attnum > 0) AND c.relname = '%s' ORDER BY c.relname, attnum", tablename);
+	ast_str_set(&sql, 0, "SELECT a.attname, t.typname, a.attlen, a.attnotnull, d.adsrc, a.atttypmod FROM pg_class c, pg_type t, pg_attribute a LEFT OUTER JOIN pg_attrdef d ON a.atthasdef AND d.adrelid = a.attrelid AND d.adnum = a.attnum WHERE c.oid = a.attrelid AND a.atttypid = t.oid AND (a.attnum > 0) AND c.relname = '%s' ORDER BY c.relname, attnum", tablename);
 	result = PQexec(pgsqlConn, sql->str);
 	ast_debug(1, "Query of table structure complete.  Now retrieving results.\n");
 	if (PQresultStatus(result) != PGRES_TUPLES_OK) {
@@ -159,7 +159,14 @@
 			return NULL;
 		}
 
-		sscanf(flen, "%d", &column->len);
+		if (strcmp(flen, "-1") == 0) {
+			/* Some types, like chars, have the length stored in a different field */
+			flen = PQgetvalue(result, i, 5);
+			sscanf(flen, "%d", &column->len);
+			column->len -= 4;
+		} else {
+			sscanf(flen, "%d", &column->len);
+		}
 		column->name = (char *)column + sizeof(*column);
 		column->type = (char *)column + sizeof(*column) + strlen(fname) + 1;
 		strcpy(column->name, fname);
@@ -954,7 +961,14 @@
 						ast_log(LOG_WARNING, "Column '%s' may not be large enough for the required data length: %d\n", column->name, size);
 						res = -1;
 					} else if (type == RQ_CHAR || type == RQ_DATETIME || type == RQ_FLOAT || type == RQ_DATE) {
-						ast_log(LOG_WARNING, "Column '%s' is of the incorrect type: (need %s(%d) but saw %s)\n", column->name, type == RQ_CHAR ? "char" : type == RQ_DATETIME ? "datetime" : type == RQ_DATE ? "date" : type == RQ_FLOAT ? "float" : "a rather stiff drink ", size, column->type);
+						ast_log(LOG_WARNING, "Column '%s' is of the incorrect type: (need %s(%d) but saw %s)\n",
+							column->name,
+								type == RQ_CHAR ? "char" :
+								type == RQ_DATETIME ? "datetime" :
+								type == RQ_DATE ? "date" :
+								type == RQ_FLOAT ? "float" :
+								"a rather stiff drink ",
+							size, column->type);
 						res = -1;
 					}
 				} else if (strncmp(column->type, "float", 5) == 0 && !ast_rq_is_int(type) && type != RQ_FLOAT) {




More information about the svn-commits mailing list