summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2012-08-27 16:56:56 +0000
committerDavid M. Lee <dlee@digium.com>2012-08-27 16:56:56 +0000
commit05fd2ef0a6494a76b59a92198a9f7a33dafe51db (patch)
tree661d7846f73829ad0f6bcd6af4b6f79781922ff3
parente13db61695d48c68adfbc45249ba1789a0c9ad9d (diff)
Fixes ast_rwlock_timed[rd|wr]lock for BSD and variants.
The original implementations simply wrap pthread functions, which take absolute time as an argument. The spinlock version for systems without those functions treated the argument as a delta. This patch fixes the spinlock version to be consistent with the pthread version. (closes issue ASTERISK-20240) Reported by: Egor Gorlin Patches: lock.c.patch uploaded by Egor Gorlin (license 6416) ........ Merged revisions 371718 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 371720 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@371721 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--main/lock.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/main/lock.c b/main/lock.c
index b954977b1..eef5d8621 100644
--- a/main/lock.c
+++ b/main/lock.c
@@ -1141,13 +1141,13 @@ int __ast_rwlock_timedrdlock(const char *filename, int line, const char *func, a
res = pthread_rwlock_timedrdlock(&t->lock, abs_timeout);
#else
do {
- struct timeval _start = ast_tvnow(), _diff;
+ struct timeval _now;
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)) {
+ _now = ast_tvnow();
+ if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
break;
}
usleep(1);
@@ -1244,13 +1244,13 @@ int __ast_rwlock_timedwrlock(const char *filename, int line, const char *func, a
res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout);
#else
do {
- struct timeval _start = ast_tvnow(), _diff;
+ struct timeval _now;
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)) {
+ _now = ast_tvnow();
+ if (_now.tv_sec > abs_timeout->tv_sec || (_now.tv_sec == abs_timeout->tv_sec && _now.tv_usec * 1000 > abs_timeout->tv_nsec)) {
break;
}
usleep(1);