[asterisk-commits] tilghman: branch 1.4 r190092 - in /branches/1.4: ./ include/asterisk/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 22 16:35:13 CDT 2009
Author: tilghman
Date: Wed Apr 22 16:35:03 2009
New Revision: 190092
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=190092
Log:
Detect availability of pthread_rwlock_timedwrlock() before using it.
(closes issue #14930)
Reported by: tilghman
Patches:
20090420__bug14930.diff.txt uploaded by tilghman (license 14)
Tested by: mvanbaak, tilghman
Modified:
branches/1.4/configure
branches/1.4/configure.ac
branches/1.4/include/asterisk/autoconfig.h.in
branches/1.4/include/asterisk/lock.h
Modified: branches/1.4/configure.ac
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/configure.ac?view=diff&rev=190092&r1=190091&r2=190092
==============================================================================
--- branches/1.4/configure.ac (original)
+++ branches/1.4/configure.ac Wed Apr 22 16:35:03 2009
@@ -324,6 +324,27 @@
AC_DEFINE([HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP], 1, [Define to 1 if your system has PTHREAD_RWLOCK_PREFER_WRITER_NP.]),
AC_MSG_RESULT(no)
)
+
+AC_MSG_CHECKING(for pthread_rwlock_timedwrlock() in pthread.h)
+saved_LDFLAGS="${LDFLAGS}"
+LDFLAGS="${LDFLAGS} -lpthread"
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [#include <pthread.h>
+ #include <time.h>],
+ [pthread_rwlock_t foo; struct timespec bar; pthread_rwlock_timedwrlock(&foo, &bar)])
+ ],[
+ AC_MSG_RESULT(yes)
+ ac_cv_pthread_rwlock_timedwrlock="yes"
+ ],[
+ AC_MSG_RESULT(no)
+ ac_cv_pthread_rwlock_timedwrlock="no"
+ ]
+)
+LDFLAGS="${saved_LDFLAGS}"
+if test "${ac_cv_pthread_rwlock_timedwrlock}" = "yes"; then
+ AC_DEFINE([HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK], 1, [Define if your system has pthread_rwlock_timedwrlock()])
+fi
AC_MSG_CHECKING(for compiler atomic operations)
AC_LINK_IFELSE(
Modified: branches/1.4/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/include/asterisk/autoconfig.h.in?view=diff&rev=190092&r1=190091&r2=190092
==============================================================================
--- branches/1.4/include/asterisk/autoconfig.h.in (original)
+++ branches/1.4/include/asterisk/autoconfig.h.in Wed Apr 22 16:35:03 2009
@@ -312,6 +312,9 @@
/* Define to 1 if your system has PTHREAD_RWLOCK_PREFER_WRITER_NP. */
#undef HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NP
+
+/* Define if your system has pthread_rwlock_timedwrlock() */
+#undef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
/* Define to 1 if the system has the type `ptrdiff_t'. */
#undef HAVE_PTRDIFF_T
Modified: branches/1.4/include/asterisk/lock.h
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/include/asterisk/lock.h?view=diff&rev=190092&r1=190091&r2=190092
==============================================================================
--- branches/1.4/include/asterisk/lock.h (original)
+++ branches/1.4/include/asterisk/lock.h Wed Apr 22 16:35:03 2009
@@ -50,6 +50,9 @@
#include <time.h>
#include <sys/param.h>
+#ifndef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
+#include "asterisk/time.h"
+#endif
#include "asterisk/logger.h"
/* internal macro to profile mutexes. Only computes the delay on
@@ -1018,7 +1021,23 @@
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock);
+#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
res = pthread_rwlock_timedrdlock(lock, abs_timeout);
+#else
+ do {
+ struct timeval _start = ast_tvnow(), _diff;
+ for (;;) {
+ if (!(res = pthread_rwlock_tryrdlock(&t->lock))) {
+ break;
+ }
+ _diff = ast_tvsub(ast_tvnow(), _start);
+ if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
+ break;
+ }
+ usleep(1);
+ }
+ } while (0);
+#endif
if (!res)
ast_mark_lock_acquired(lock);
else
@@ -1051,7 +1070,23 @@
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock);
+#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
res = pthread_rwlock_timedwrlock(lock, abs_timeout);
+#else
+ do {
+ struct timeval _start = ast_tvnow(), _diff;
+ for (;;) {
+ if (!(res = pthread_rwlock_trywrlock(&t->lock))) {
+ break;
+ }
+ _diff = ast_tvsub(ast_tvnow(), _start);
+ if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
+ break;
+ }
+ usleep(1);
+ }
+ } while (0);
+#endif
if (!res)
ast_mark_lock_acquired(lock);
else
@@ -1160,7 +1195,23 @@
static inline int ast_rwlock_timedrdlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout)
{
- return pthread_rwlock_timedrdlock(prwlock, abs_timeout);
+ int res;
+#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
+ res = pthread_rwlock_timedrdlock(prwlock, abs_timeout);
+#else
+ struct timeval _start = ast_tvnow(), _diff;
+ for (;;) {
+ if (!(res = pthread_rwlock_tryrdlock(prwlock))) {
+ break;
+ }
+ _diff = ast_tvsub(ast_tvnow(), _start);
+ if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
+ break;
+ }
+ usleep(1);
+ }
+#endif
+ return res;
}
static inline int ast_rwlock_tryrdlock(ast_rwlock_t *prwlock)
@@ -1175,7 +1226,25 @@
static inline int ast_rwlock_timedwrlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout)
{
- return pthread_rwlock_timedwrlock(prwlock, abs_timeout);
+ int res;
+#ifdef HAVE_PTHREAD_RWLOCK_TIMEDWRLOCK
+ res = pthread_rwlock_timedwrlock(prwlock, abs_timeout);
+#else
+ do {
+ struct timeval _start = ast_tvnow(), _diff;
+ for (;;) {
+ if (!(res = pthread_rwlock_trywrlock(prwlock))) {
+ break;
+ }
+ _diff = ast_tvsub(ast_tvnow(), _start);
+ if (_diff.tv_sec > abs_timeout->tv_sec || (_diff.tv_sec == abs_timeout->tv_sec && _diff.tv_usec * 1000 > abs_timeout->tv_nsec)) {
+ break;
+ }
+ usleep(1);
+ }
+ } while (0);
+#endif
+ return res;
}
static inline int ast_rwlock_trywrlock(ast_rwlock_t *prwlock)
More information about the asterisk-commits
mailing list