New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Ticket #20211: 20090420__bug14930.diff

File 20090420__bug14930.diff, 7.1 KB (added by stefan.van.der.eijk@…, 4 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; }
     
    461461AC_MSG_RESULT(no) 
    462462) 
    463463 
     464AC_MSG_CHECKING(for pthread_rwlock_timedwrlock() in pthread.h) 
     465AC_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) 
     478if test "${ac_cv_pthread_rwlock_timedwrlock}" = "yes"; then 
     479  AC_DEFINE([HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK], 1, [Define if your system has pthread_rwlock_timedwrlock()]) 
     480fi 
     481 
    464482AST_C_DEFINE_CHECK([PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [pthread.h]) 
    465483 
    466484#if test "${cross_compiling}" = "no"; 
  • include/asterisk/lock.h

     
    4949#define _ASTERISK_LOCK_H 
    5050 
    5151#include <pthread.h> 
     52#include <time.h> 
    5253#include <sys/param.h> 
    5354#ifdef HAVE_BKTR 
    5455#include <execinfo.h> 
    5556#endif 
     57 
     58#ifndef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 
     59#include "asterisk/time.h" 
     60#endif 
    5661#include "asterisk/logger.h" 
    5762 
    5863/* internal macro to profile mutexes. Only computes the delay on 
     
    13951400                ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t); 
    13961401#endif 
    13971402        } 
     1403#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 
    13981404        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 
    13991420        if (!res) { 
    14001421                ast_reentrancy_lock(lt); 
    14011422                if (lt->reentrancy < AST_MAX_REENTRANCY) { 
     
    14741495                ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t); 
    14751496#endif 
    14761497        } 
     1498#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 
    14771499        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 
    14781515        if (!res) { 
    14791516                ast_reentrancy_lock(lt); 
    14801517                if (lt->reentrancy < AST_MAX_REENTRANCY) { 
     
    17621799 
    17631800static inline int ast_rwlock_timedrdlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout) 
    17641801{ 
    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; 
    17661819} 
    17671820 
    17681821static inline int ast_rwlock_tryrdlock(ast_rwlock_t *prwlock) 
     
    17771830 
    17781831static inline int ast_rwlock_timedwrlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout) 
    17791832{ 
    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; 
    17811852} 
    17821853 
    17831854static inline int ast_rwlock_trywrlock(ast_rwlock_t *prwlock) 
  • include/asterisk/autoconfig.h.in

     
    704704   pthread.h */ 
    705705#undef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP 
    706706 
     707/* Define if your system has pthread_rwlock_timedwrlock() */ 
     708#undef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK 
     709 
    707710/* Define to 1 if the system has the type `ptrdiff_t'. */ 
    708711#undef HAVE_PTRDIFF_T 
    709712