aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-30 14:46:57 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-30 14:46:57 +0000
commitdfa80fc343e382e99e91304e9a058d582eaa841e (patch)
tree0083ac3ce26ad61b88969395c79383a01775a4ab
parent76feb1001094f013bba719b933b77d12e0b0d5af (diff)
use the ARRAY_LEN macro for indexing through the iaxs/iaxsl arrays so that the size of the arrays can be adjusted in one place, and change the size of the arrays from 32768 calls to 2048 calls when LOW_MEMORY is defined
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@114880 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--channels/chan_iax2.c45
-rw-r--r--channels/iax2.h5
2 files changed, 32 insertions, 18 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index a949a1c50..deec4c069 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -127,9 +127,6 @@ static int nochecksums = 0;
#define DEFAULT_RETRY_TIME 1000
#define MEMORY_SIZE 100
#define DEFAULT_DROP 3
-/* Flag to use with trunk calls, keeping these calls high up. It halves our effective use
- but keeps the division between trunked and non-trunked better. */
-#define TRUNK_CALL_START 0x4000
#define DEBUG_SUPPORT
@@ -151,8 +148,6 @@ static int maxauthreq = 3;
static int max_retries = 4;
static int ping_time = 21;
static int lagrq_time = 10;
-static int maxtrunkcall = TRUNK_CALL_START;
-static int maxnontrunkcall = 1;
static int maxjitterbuffer=1000;
static int resyncthreshold=1000;
static int maxjitterinterps=10;
@@ -811,8 +806,15 @@ static void jb_debug_output(const char *fmt, ...)
/* XXX We probably should use a mutex when working with this XXX */
static struct chan_iax2_pvt *iaxs[IAX_MAX_CALLS];
-static ast_mutex_t iaxsl[IAX_MAX_CALLS];
-static struct timeval lastused[IAX_MAX_CALLS];
+static ast_mutex_t iaxsl[ARRAY_LEN(iaxs)];
+static struct timeval lastused[ARRAY_LEN(iaxs)];
+
+/* Flag to use with trunk calls, keeping these calls high up. It halves our effective use
+ but keeps the division between trunked and non-trunked better. */
+#define TRUNK_CALL_START ARRAY_LEN(iaxs) / 2
+
+static int maxtrunkcall = TRUNK_CALL_START;
+static int maxnontrunkcall = 1;
static enum ast_bridge_result iax2_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
static int expire_registry(const void *data);
@@ -1263,11 +1265,14 @@ static void update_max_trunk(void)
{
int max = TRUNK_CALL_START;
int x;
+
/* XXX Prolly don't need locks here XXX */
- for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
- if (iaxs[x])
+ for (x = TRUNK_CALL_START; x < ARRAY_LEN(iaxs) - 1; x++) {
+ if (iaxs[x]) {
max = x + 1;
+ }
}
+
maxtrunkcall = max;
if (option_debug && iaxdebug)
ast_log(LOG_DEBUG, "New max trunk callno is %d\n", max);
@@ -1301,7 +1306,7 @@ static int make_trunk(unsigned short callno, int locked)
return -1;
}
gettimeofday(&now, NULL);
- for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
+ for (x = TRUNK_CALL_START; x < ARRAY_LEN(iaxs) - 1; x++) {
ast_mutex_lock(&iaxsl[x]);
if (!iaxs[x] && ((now.tv_sec - lastused[x].tv_sec) > MIN_REUSE_TIME)) {
iaxs[x] = iaxs[callno];
@@ -1321,7 +1326,7 @@ static int make_trunk(unsigned short callno, int locked)
}
ast_mutex_unlock(&iaxsl[x]);
}
- if (x >= IAX_MAX_CALLS - 1) {
+ if (x >= ARRAY_LEN(iaxs) - 1) {
ast_log(LOG_WARNING, "Unable to trunk call: Insufficient space\n");
return -1;
}
@@ -4696,7 +4701,7 @@ static int iax2_show_channels(int fd, int argc, char *argv[])
if (argc != 3)
return RESULT_SHOWUSAGE;
ast_cli(fd, FORMAT2, "Channel", "Peer", "Username", "ID (Lo/Rem)", "Seq (Tx/Rx)", "Lag", "Jitter", "JitBuf", "Format");
- for (x=0;x<IAX_MAX_CALLS;x++) {
+ for (x = 0; x < ARRAY_LEN(iaxs); x++) {
ast_mutex_lock(&iaxsl[x]);
if (iaxs[x]) {
int lag, jitter, localdelay;
@@ -4736,7 +4741,7 @@ static int ast_cli_netstats(struct mansession *s, int fd, int limit_fmt)
{
int x;
int numchans = 0;
- for (x=0;x<IAX_MAX_CALLS;x++) {
+ for (x = 0; x < ARRAY_LEN(iaxs); x++) {
ast_mutex_lock(&iaxsl[x]);
if (iaxs[x]) {
int localjitter, localdelay, locallost, locallosspct, localdropped, localooo;
@@ -10092,7 +10097,7 @@ static int cache_get_callno_locked(const char *data)
struct parsed_dial_string pds;
char *tmpstr;
- for (x=0; x<IAX_MAX_CALLS; x++) {
+ for (x = 0; x < ARRAY_LEN(iaxs); x++) {
/* Look for an *exact match* call. Once a call is negotiated, it can only
look up entries for a single context */
if (!ast_mutex_trylock(&iaxsl[x])) {
@@ -10844,9 +10849,11 @@ static int __unload_module(void)
ast_netsock_release(netsock);
ast_netsock_release(outsock);
- for (x=0;x<IAX_MAX_CALLS;x++)
- if (iaxs[x])
+ for (x = 0; x < ARRAY_LEN(iaxs); x++) {
+ if (iaxs[x]) {
iax2_destroy(x);
+ }
+ }
ast_manager_unregister( "IAXpeers" );
ast_manager_unregister( "IAXnetstats" );
ast_unregister_application(papp);
@@ -10860,8 +10867,9 @@ static int __unload_module(void)
ast_mutex_destroy(&waresl.lock);
- for (x = 0; x < IAX_MAX_CALLS; x++)
+ for (x = 0; x < ARRAY_LEN(iaxsl); x++) {
ast_mutex_destroy(&iaxsl[x]);
+ }
ao2_ref(peers, -1);
ao2_ref(users, -1);
@@ -10920,8 +10928,9 @@ static int load_module(void)
memset(iaxs, 0, sizeof(iaxs));
- for (x=0;x<IAX_MAX_CALLS;x++)
+ for (x = 0; x < ARRAY_LEN(iaxsl); x++) {
ast_mutex_init(&iaxsl[x]);
+ }
ast_cond_init(&sched_cond, NULL);
diff --git a/channels/iax2.h b/channels/iax2.h
index 2b0c8bb99..960dec8bb 100644
--- a/channels/iax2.h
+++ b/channels/iax2.h
@@ -17,7 +17,12 @@
/* Max version of IAX protocol we support */
#define IAX_PROTO_VERSION 2
+/* NOTE: IT IS CRITICAL THAT IAX_MAX_CALLS BE A POWER OF 2. */
+#if defined(LOW_MEMORY)
+#define IAX_MAX_CALLS 2048
+#else
#define IAX_MAX_CALLS 32768
+#endif
#define IAX_FLAG_FULL 0x8000