[Asterisk-cvs] asterisk Makefile,1.95,1.96 asterisk.c,1.95,1.96 cli.c,1.42,1.43 manager.c,1.55,1.56 pbx.c,1.127,1.128 sched.c,1.11,1.12 utils.c,1.7,1.8
markster at lists.digium.com
markster at lists.digium.com
Tue Jun 22 13:56:18 CDT 2004
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv21170
Modified Files:
Makefile asterisk.c cli.c manager.c pbx.c sched.c utils.c
Log Message:
Merge major BSD mutex and symbol conflict patches (bug #1816) (link patch still pending)
Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/Makefile,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- Makefile 13 Jun 2004 21:25:09 -0000 1.95
+++ Makefile 22 Jun 2004 17:42:13 -0000 1.96
@@ -26,15 +26,12 @@
#PROC=athlon
OPTIONS+=-m64
endif
-else
-ifeq (${OSARCH},FreeBSD)
-PROC=$(shell uname -m)
-else
-ifeq (${OSARCH},OpenBSD)
-PROC=$(shell uname -m)
-endif
endif
+
+ifeq ($(findstring BSD,${OSARCH}),BSD)
+PROC=$(shell uname -m)
endif
+
# Pentium Pro Optimize
#PROC=i686
@@ -120,10 +117,15 @@
CFLAGS+=$(OPTIMIZE)
CFLAGS+=$(shell if $(CC) -march=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=$(PROC)"; fi)
CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi)
+
ifeq (${OSARCH},FreeBSD)
-CFLAGS+=-pthread
+OSVERSION=$(shell make -V OSVERSION -f /usr/share/mk/bsd.port.subdir.mk)
+CFLAGS+=$(if ${OSVERSION}<500016,-D_THREAD_SAFE)
+LIBS+=$(if ${OSVERSION}<502102,-lc_r,-pthread)
INCLUDE+=-I/usr/local/include
-endif
+CFLAGS+=$(shell if [ -d /usr/local/include/spandsp ]; then echo "-I/usr/local/include/spandsp"; fi)
+endif # FreeBSD
+
ifeq (${OSARCH},OpenBSD)
CFLAGS+=-pthread
endif
@@ -161,14 +163,6 @@
ifeq (${OSARCH},Linux)
LIBS=-ldl -lpthread
endif
-ifeq (${OSARCH},OpenBSD)
-LIBS=-pthread
-else
-ifeq (${OSARCH},FreeBSD)
-LIBS=-pthread
-else
-endif
-endif
LIBS+=-lncurses -lm
ifeq (${OSARCH},Linux)
LIBS+=-lresolv #-lnjamd
Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- asterisk.c 21 Jun 2004 19:12:20 -0000 1.95
+++ asterisk.c 22 Jun 2004 17:42:13 -0000 1.96
@@ -49,6 +49,7 @@
#include "asterisk.h"
#include <asterisk/config.h>
#include <asterisk/config_pvt.h>
+#include <sys/resource.h>
#if defined(__FreeBSD__)
#include <netdb.h>
@@ -1561,6 +1562,11 @@
term_init();
printf(term_end());
fflush(stdout);
+
+ /* Test recursive mutex locking. */
+ if(test_for_thread_safety())
+ ast_verbose("Warning! Asterisk is not thread safe.\n");
+
if (option_console && !option_verbose)
ast_verbose("[ Reading Master Configuration ]");
ast_readconfig();
Index: cli.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cli.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- cli.c 11 Jun 2004 00:18:30 -0000 1.42
+++ cli.c 22 Jun 2004 17:42:13 -0000 1.43
@@ -181,8 +181,8 @@
char timestr[256];
int pos = 0;
#define SECOND (1)
-#define MIN (SECOND*60)
-#define HOUR (MIN*60)
+#define MINUTE (SECOND*60)
+#define HOUR (MINUTE*60)
#define DAY (HOUR*24)
#define WEEK (DAY*7)
#define YEAR (DAY*365)
@@ -222,9 +222,9 @@
else
pos += sprintf(timestr + pos, "1 hour, ");
}
- if (timeval > MIN) {
- mins = (timeval / MIN);
- timeval -= (mins * MIN);
+ if (timeval > MINUTE) {
+ mins = (timeval / MINUTE);
+ timeval -= (mins * MINUTE);
if (mins > 1)
pos += sprintf(timestr + pos, "%d minutes, ", mins);
else if (mins > 0)
Index: manager.c
===================================================================
RCS file: /usr/cvsroot/asterisk/manager.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- manager.c 9 Jun 2004 01:45:07 -0000 1.55
+++ manager.c 22 Jun 2004 17:42:13 -0000 1.56
@@ -220,6 +220,7 @@
sessions = cur->next;
if (s->fd > -1)
close(s->fd);
+ ast_mutex_destroy(&s->lock);
free(s);
} else
ast_log(LOG_WARNING, "Trying to delete non-existant session %p?\n", s);
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -d -r1.127 -r1.128
--- pbx.c 22 Jun 2004 03:51:34 -0000 1.127
+++ pbx.c 22 Jun 2004 17:42:13 -0000 1.128
@@ -4173,6 +4173,7 @@
e = e->next;
destroy_exten(el);
}
+ ast_mutex_destroy(&tmp->lock);
free(tmp);
if (!con) {
/* Might need to get another one -- restart */
Index: sched.c
===================================================================
RCS file: /usr/cvsroot/asterisk/sched.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- sched.c 21 Nov 2003 22:05:08 -0000 1.11
+++ sched.c 22 Jun 2004 17:42:13 -0000 1.12
@@ -22,6 +22,7 @@
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>
+#include <string.h>
#include <asterisk/sched.h>
#include <asterisk/logger.h>
@@ -63,6 +64,7 @@
struct sched_context *tmp;
tmp = malloc(sizeof(struct sched_context));
if (tmp) {
+ memset(tmp, 0, sizeof(struct sched_context));
ast_mutex_init(&tmp->lock);
tmp->eventcnt = 1;
tmp->schedcnt = 0;
@@ -97,6 +99,7 @@
}
/* And the context */
ast_mutex_unlock(&con->lock);
+ ast_mutex_destroy(&con->lock);
free(con);
}
Index: utils.c
===================================================================
RCS file: /usr/cvsroot/asterisk/utils.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- utils.c 12 Jun 2004 14:53:53 -0000 1.7
+++ utils.c 22 Jun 2004 17:42:13 -0000 1.8
@@ -11,6 +11,8 @@
#include <ctype.h>
#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
#include <asterisk/lock.h>
#include <asterisk/utils.h>
@@ -22,9 +24,9 @@
AST_MUTEX_DEFINE_STATIC(__mutex);
-int gethostbyname_r (const char *name, struct hostent *ret, char *buf,
- size_t buflen, struct hostent **result,
- int *h_errnop)
+static int gethostbyname_r (const char *name, struct hostent *ret, char *buf,
+ size_t buflen, struct hostent **result,
+ int *h_errnop)
{
int hsave;
struct hostent *ph;
@@ -143,3 +145,60 @@
return NULL;
return &hp->hp;
}
+
+
+/* This is a regression test for recursive mutexes.
+ test_for_thread_safety() will return 0 if recursive mutex locks are
+ working properly, and non-zero if they are not working properly. */
+
+AST_MUTEX_DEFINE_STATIC(test_lock);
+AST_MUTEX_DEFINE_STATIC(test_lock2);
+static pthread_t test_thread;
+static int lock_count = 0;
+static int test_errors = 0;
+
+static void *test_thread_body(void *data)
+{
+ ast_mutex_lock(&test_lock);
+ lock_count += 10;
+ if(lock_count != 10) test_errors++;
+ ast_mutex_lock(&test_lock);
+ lock_count += 10;
+ if(lock_count != 20) test_errors++;
+ ast_mutex_lock(&test_lock2);
+ ast_mutex_unlock(&test_lock);
+ lock_count -= 10;
+ if(lock_count != 10) test_errors++;
+ ast_mutex_unlock(&test_lock);
+ lock_count -= 10;
+ ast_mutex_unlock(&test_lock2);
+ if(lock_count != 0) test_errors++;
+ return NULL;
+}
+
+int test_for_thread_safety(void)
+{
+ ast_mutex_lock(&test_lock2);
+ ast_mutex_lock(&test_lock);
+ lock_count += 1;
+ ast_mutex_lock(&test_lock);
+ lock_count += 1;
+ pthread_create(&test_thread, NULL, test_thread_body, NULL);
+ pthread_yield();
+ usleep(100);
+ if(lock_count != 2) test_errors++;
+ ast_mutex_unlock(&test_lock);
+ lock_count -= 1;
+ pthread_yield();
+ usleep(100);
+ if(lock_count != 1) test_errors++;
+ ast_mutex_unlock(&test_lock);
+ lock_count -= 1;
+ if(lock_count != 0) test_errors++;
+ ast_mutex_unlock(&test_lock2);
+ pthread_yield();
+ usleep(100);
+ if(lock_count != 0) test_errors++;
+ pthread_join(test_thread, NULL);
+ return(test_errors); /* return 0 on success. */
+}
More information about the svn-commits
mailing list