Ticket #20211: 20090420__bug14930.diff
File 20090420__bug14930.diff, 7.1 KB (added by stefan.van.der.eijk@…, 15 years ago) |
---|
-
configure
-
configure.ac
#@@ -1,5 +1,5 @@ # #! /bin/sh #-# From configure.ac Revision: 183242 . #+# From configure.ac Revision: 188342 . # # Guess values for system-dependent variables and create Makefiles. # # Generated by GNU Autoconf 2.61 for asterisk 1.6. # # @@ -17256,7 +17256,71 @@ rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ conftest$ac_exeext conftest.$ac_ext +{ echo "$as_me:$LINENO: checking for pthread_rwlock_timedwrlock() in pthread.h" >&5 +echo $ECHO_N "checking for pthread_rwlock_timedwrlock() in pthread.h... $ECHO_C" >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <pthread.h> + #include <time.h> +int +main () +{ +pthread_rwlock_t foo; struct timespec bar; pthread_rwlock_timedwrlock(&foo, &bar) + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + ac_cv_pthread_rwlock_timedwrlock="yes" + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + ac_cv_pthread_rwlock_timedwrlock="no" + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +if test "${ac_cv_pthread_rwlock_timedwrlock}" = "yes"; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 1 +_ACEOF + +fi + + if test "x${PBX_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP}" != "x1"; then { echo "$as_me:$LINENO: checking for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP in pthread.h" >&5 echo $ECHO_N "checking for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP in pthread.h... $ECHO_C" >&6; }
461 461 AC_MSG_RESULT(no) 462 462 ) 463 463 464 AC_MSG_CHECKING(for pthread_rwlock_timedwrlock() in pthread.h) 465 AC_LINK_IFELSE( 466 [AC_LANG_PROGRAM( 467 [#include <pthread.h> 468 #include <time.h>], 469 [pthread_rwlock_t foo; struct timespec bar; pthread_rwlock_timedwrlock(&foo, &bar)]) 470 ],[ 471 AC_MSG_RESULT(yes) 472 ac_cv_pthread_rwlock_timedwrlock="yes" 473 ],[ 474 AC_MSG_RESULT(no) 475 ac_cv_pthread_rwlock_timedwrlock="no" 476 ] 477 ) 478 if test "${ac_cv_pthread_rwlock_timedwrlock}" = "yes"; then 479 AC_DEFINE([HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK], 1, [Define if your system has pthread_rwlock_timedwrlock()]) 480 fi 481 464 482 AST_C_DEFINE_CHECK([PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [pthread.h]) 465 483 466 484 #if test "${cross_compiling}" = "no"; -
include/asterisk/lock.h
49 49 #define _ASTERISK_LOCK_H 50 50 51 51 #include <pthread.h> 52 #include <time.h> 52 53 #include <sys/param.h> 53 54 #ifdef HAVE_BKTR 54 55 #include <execinfo.h> 55 56 #endif 57 58 #ifndef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 59 #include "asterisk/time.h" 60 #endif 56 61 #include "asterisk/logger.h" 57 62 58 63 /* internal macro to profile mutexes. Only computes the delay on … … 1395 1400 ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t); 1396 1401 #endif 1397 1402 } 1403 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 1398 1404 res = pthread_rwlock_timedrdlock(&t->lock, abs_timeout); 1405 #else 1406 do { 1407 struct timeval _start = ast_tvnow(), _diff; 1408 for (;;) { 1409 if (!(res = pthread_rwlock_tryrdlock(&t->lock))) { 1410 break; 1411 } 1412 _diff = ast_tvsub(ast_tvnow(), _start); 1413 if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) { 1414 break; 1415 } 1416 usleep(1); 1417 } 1418 } while (0); 1419 #endif 1399 1420 if (!res) { 1400 1421 ast_reentrancy_lock(lt); 1401 1422 if (lt->reentrancy < AST_MAX_REENTRANCY) { … … 1474 1495 ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t); 1475 1496 #endif 1476 1497 } 1498 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 1477 1499 res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout); 1500 #else 1501 do { 1502 struct timeval _start = ast_tvnow(), _diff; 1503 for (;;) { 1504 if (!(res = pthread_rwlock_trywrlock(&t->lock))) { 1505 break; 1506 } 1507 _diff = ast_tvsub(ast_tvnow(), _start); 1508 if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) { 1509 break; 1510 } 1511 usleep(1); 1512 } 1513 } while (0); 1514 #endif 1478 1515 if (!res) { 1479 1516 ast_reentrancy_lock(lt); 1480 1517 if (lt->reentrancy < AST_MAX_REENTRANCY) { … … 1762 1799 1763 1800 static inline int ast_rwlock_timedrdlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout) 1764 1801 { 1765 return pthread_rwlock_timedrdlock(prwlock, abs_timeout); 1802 int res; 1803 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 1804 res = pthread_rwlock_timedrdlock(prwlock, abs_timeout); 1805 #else 1806 struct timeval _start = ast_tvnow(), _diff; 1807 for (;;) { 1808 if (!(res = pthread_rwlock_tryrdlock(prwlock))) { 1809 break; 1810 } 1811 _diff = ast_tvsub(ast_tvnow(), _start); 1812 if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) { 1813 break; 1814 } 1815 usleep(1); 1816 } 1817 #endif 1818 return res; 1766 1819 } 1767 1820 1768 1821 static inline int ast_rwlock_tryrdlock(ast_rwlock_t *prwlock) … … 1777 1830 1778 1831 static inline int ast_rwlock_timedwrlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout) 1779 1832 { 1780 return pthread_rwlock_timedwrlock(prwlock, abs_timeout); 1833 int res; 1834 #ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 1835 res = pthread_rwlock_timedwrlock(prwlock, abs_timeout); 1836 #else 1837 do { 1838 struct timeval _start = ast_tvnow(), _diff; 1839 for (;;) { 1840 if (!(res = pthread_rwlock_trywrlock(prwlock))) { 1841 break; 1842 } 1843 _diff = ast_tvsub(ast_tvnow(), _start); 1844 if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) { 1845 break; 1846 } 1847 usleep(1); 1848 } 1849 } while (0); 1850 #endif 1851 return res; 1781 1852 } 1782 1853 1783 1854 static inline int ast_rwlock_trywrlock(ast_rwlock_t *prwlock) -
include/asterisk/autoconfig.h.in
704 704 pthread.h */ 705 705 #undef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP 706 706 707 /* Define if your system has pthread_rwlock_timedwrlock() */ 708 #undef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 709 707 710 /* Define to 1 if the system has the type `ptrdiff_t'. */ 708 711 #undef HAVE_PTRDIFF_T 709 712