1 diff -Nru asterisk-1.6.1.0.org/configure asterisk-1.6.1.0/configure
2 --- asterisk-1.6.1.0.org/configure 2009-03-19 19:14:55.000000000 +0100
3 +++ asterisk-1.6.1.0/configure 2009-05-01 16:20:40.000000000 +0200
4 @@ -16790,6 +16790,70 @@
5 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
6 conftest$ac_exeext conftest.$ac_ext
8 +{ echo "$as_me:$LINENO: checking for pthread_rwlock_timedwrlock() in pthread.h" >&5
9 +echo $ECHO_N "checking for pthread_rwlock_timedwrlock() in pthread.h... $ECHO_C" >&6; }
10 +cat >conftest.$ac_ext <<_ACEOF
13 +cat confdefs.h >>conftest.$ac_ext
14 +cat >>conftest.$ac_ext <<_ACEOF
15 +/* end confdefs.h. */
21 +pthread_rwlock_t foo; struct timespec bar; pthread_rwlock_timedwrlock(&foo, &bar)
27 +rm -f conftest.$ac_objext conftest$ac_exeext
28 +if { (ac_try="$ac_link"
30 + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
31 + *) ac_try_echo=$ac_try;;
33 +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
34 + (eval "$ac_link") 2>conftest.er1
36 + grep -v '^ *+' conftest.er1 >conftest.err
38 + cat conftest.err >&5
39 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
40 + (exit $ac_status); } && {
41 + test -z "$ac_c_werror_flag" ||
42 + test ! -s conftest.err
43 + } && test -s conftest$ac_exeext &&
44 + $as_test_x conftest$ac_exeext; then
46 + { echo "$as_me:$LINENO: result: yes" >&5
47 +echo "${ECHO_T}yes" >&6; }
48 + ac_cv_pthread_rwlock_timedwrlock="yes"
51 + echo "$as_me: failed program was:" >&5
52 +sed 's/^/| /' conftest.$ac_ext >&5
55 + { echo "$as_me:$LINENO: result: no" >&5
56 +echo "${ECHO_T}no" >&6; }
57 + ac_cv_pthread_rwlock_timedwrlock="no"
62 +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
63 + conftest$ac_exeext conftest.$ac_ext
64 +if test "${ac_cv_pthread_rwlock_timedwrlock}" = "yes"; then
66 +cat >>confdefs.h <<\_ACEOF
67 +#define HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 1
73 if test "x${PBX_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}" != "x1"; then
74 { echo "$as_me:$LINENO: checking for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP in pthread.h" >&5
75 diff -Nru asterisk-1.6.1.0.org/configure.ac asterisk-1.6.1.0/configure.ac
76 --- asterisk-1.6.1.0.org/configure.ac 2009-03-19 19:14:55.000000000 +0100
77 +++ asterisk-1.6.1.0/configure.ac 2009-05-01 16:20:40.000000000 +0200
82 +AC_MSG_CHECKING(for pthread_rwlock_timedwrlock() in pthread.h)
85 + [#include <pthread.h>
87 + [pthread_rwlock_t foo; struct timespec bar; pthread_rwlock_timedwrlock(&foo, &bar)])
90 + ac_cv_pthread_rwlock_timedwrlock="yes"
93 + ac_cv_pthread_rwlock_timedwrlock="no"
96 +if test "${ac_cv_pthread_rwlock_timedwrlock}" = "yes"; then
97 + AC_DEFINE([HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK], 1, [Define if your system has pthread_rwlock_timedwrlock()])
100 AST_C_DEFINE_CHECK([PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [pthread.h])
102 #if test "${cross_compiling}" = "no";
103 diff -Nru asterisk-1.6.1.0.org/include/asterisk/autoconfig.h.in asterisk-1.6.1.0/include/asterisk/autoconfig.h.in
104 --- asterisk-1.6.1.0.org/include/asterisk/autoconfig.h.in 2009-03-19 19:14:55.000000000 +0100
105 +++ asterisk-1.6.1.0/include/asterisk/autoconfig.h.in 2009-05-01 16:20:40.000000000 +0200
108 #undef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
110 +/* Define if your system has pthread_rwlock_timedwrlock() */
111 +#undef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
113 /* Define to 1 if the system has the type `ptrdiff_t'. */
114 #undef HAVE_PTRDIFF_T
116 diff -Nru asterisk-1.6.1.0.org/include/asterisk/lock.h asterisk-1.6.1.0/include/asterisk/lock.h
117 --- asterisk-1.6.1.0.org/include/asterisk/lock.h 2009-04-10 05:56:37.000000000 +0200
118 +++ asterisk-1.6.1.0/include/asterisk/lock.h 2009-05-01 16:20:40.000000000 +0200
120 #define _ASTERISK_LOCK_H
124 #include <sys/param.h>
126 #include <execinfo.h>
129 +#ifndef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
130 +#include "asterisk/time.h"
132 #include "asterisk/logger.h"
134 /* internal macro to profile mutexes. Only computes the delay on
135 @@ -1395,7 +1400,23 @@
136 ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
139 +#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
140 res = pthread_rwlock_timedrdlock(&t->lock, abs_timeout);
143 + struct timeval _start = ast_tvnow(), _diff;
145 + if (!(res = pthread_rwlock_tryrdlock(&t->lock))) {
148 + _diff = ast_tvsub(ast_tvnow(), _start);
149 + if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
157 ast_reentrancy_lock(lt);
158 if (lt->reentrancy < AST_MAX_REENTRANCY) {
159 @@ -1474,7 +1495,23 @@
160 ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
163 +#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
164 res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout);
167 + struct timeval _start = ast_tvnow(), _diff;
169 + if (!(res = pthread_rwlock_trywrlock(&t->lock))) {
172 + _diff = ast_tvsub(ast_tvnow(), _start);
173 + if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
181 ast_reentrancy_lock(lt);
182 if (lt->reentrancy < AST_MAX_REENTRANCY) {
183 @@ -1762,7 +1799,23 @@
185 static inline int ast_rwlock_timedrdlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout)
187 - return pthread_rwlock_timedrdlock(prwlock, abs_timeout);
189 +#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
190 + res = pthread_rwlock_timedrdlock(prwlock, abs_timeout);
192 + struct timeval _start = ast_tvnow(), _diff;
194 + if (!(res = pthread_rwlock_tryrdlock(prwlock))) {
197 + _diff = ast_tvsub(ast_tvnow(), _start);
198 + if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
207 static inline int ast_rwlock_tryrdlock(ast_rwlock_t *prwlock)
208 @@ -1777,7 +1830,25 @@
210 static inline int ast_rwlock_timedwrlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout)
212 - return pthread_rwlock_timedwrlock(prwlock, abs_timeout);
214 +#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
215 + res = pthread_rwlock_timedwrlock(prwlock, abs_timeout);
218 + struct timeval _start = ast_tvnow(), _diff;
220 + if (!(res = pthread_rwlock_trywrlock(prwlock))) {
223 + _diff = ast_tvsub(ast_tvnow(), _start);
224 + if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
234 static inline int ast_rwlock_trywrlock(ast_rwlock_t *prwlock)