summaryrefslogtreecommitdiff
path: root/src/libstrongswan/utils/mutex.c
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2009-02-28 22:02:31 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2009-02-28 22:02:31 +0000
commit19364e11c66714324bd3d5d0dc9212db397085cb (patch)
treefe7f5e55f0474dad1d0c29ba7c0a6f4546c99c3a /src/libstrongswan/utils/mutex.c
parentc7f1b0530b85bc7654e68992f25ed8ced5d0a80d (diff)
downloadvyos-strongswan-19364e11c66714324bd3d5d0dc9212db397085cb.tar.gz
vyos-strongswan-19364e11c66714324bd3d5d0dc9212db397085cb.zip
[svn-upgrade] Integrating new upstream version, strongswan (4.2.12)
Diffstat (limited to 'src/libstrongswan/utils/mutex.c')
-rw-r--r--src/libstrongswan/utils/mutex.c52
1 files changed, 34 insertions, 18 deletions
diff --git a/src/libstrongswan/utils/mutex.c b/src/libstrongswan/utils/mutex.c
index ddb0d2df6..ba4b72b0c 100644
--- a/src/libstrongswan/utils/mutex.c
+++ b/src/libstrongswan/utils/mutex.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2008 Tobias Brunner
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -12,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: mutex.c 4591 2008-11-05 16:12:54Z martin $
+ * $Id: mutex.c 4803 2008-12-15 09:13:43Z martin $
*/
#define _GNU_SOURCE
@@ -76,7 +77,7 @@ static void profiler_cleanup(lock_profile_t *profile)
*/
static void profiler_init(lock_profile_t *profile)
{
- profile->backtrace = backtrace_create(3);
+ profile->backtrace = backtrace_create(2);
timerclear(&profile->waited);
}
@@ -332,28 +333,17 @@ static void wait(private_condvar_t *this, private_mutex_t *mutex)
}
/**
- * Implementation of condvar_t.timed_wait.
+ * Implementation of condvar_t.timed_wait_abs.
*/
-static bool timed_wait(private_condvar_t *this, private_mutex_t *mutex,
- u_int timeout)
+static bool timed_wait_abs(private_condvar_t *this, private_mutex_t *mutex,
+ timeval_t time)
{
struct timespec ts;
- struct timeval tv;
- u_int s, ms;
bool timed_out;
- gettimeofday(&tv, NULL);
-
- s = timeout / 1000;
- ms = timeout % 1000;
+ ts.tv_sec = time.tv_sec;
+ ts.tv_nsec = time.tv_usec * 1000;
- ts.tv_sec = tv.tv_sec + s;
- ts.tv_nsec = tv.tv_usec * 1000 + ms * 1000000;
- if (ts.tv_nsec > 1000000000 /* 1s */)
- {
- ts.tv_nsec -= 1000000000;
- ts.tv_sec++;
- }
if (mutex->recursive)
{
private_r_mutex_t* recursive = (private_r_mutex_t*)mutex;
@@ -372,6 +362,31 @@ static bool timed_wait(private_condvar_t *this, private_mutex_t *mutex,
}
/**
+ * Implementation of condvar_t.timed_wait.
+ */
+static bool timed_wait(private_condvar_t *this, private_mutex_t *mutex,
+ u_int timeout)
+{
+ timeval_t tv;
+ u_int s, ms;
+
+ gettimeofday(&tv, NULL);
+
+ s = timeout / 1000;
+ ms = timeout % 1000;
+
+ tv.tv_sec += s;
+ tv.tv_usec += ms * 1000;
+
+ if (tv.tv_usec > 1000000 /* 1s */)
+ {
+ tv.tv_usec -= 1000000;
+ tv.tv_sec++;
+ }
+ return timed_wait_abs(this, mutex, tv);
+}
+
+/**
* Implementation of condvar_t.signal.
*/
static void signal(private_condvar_t *this)
@@ -410,6 +425,7 @@ condvar_t *condvar_create(condvar_type_t type)
this->public.wait = (void(*)(condvar_t*, mutex_t *mutex))wait;
this->public.timed_wait = (bool(*)(condvar_t*, mutex_t *mutex, u_int timeout))timed_wait;
+ this->public.timed_wait_abs = (bool(*)(condvar_t*, mutex_t *mutex, timeval_t time))timed_wait_abs;
this->public.signal = (void(*)(condvar_t*))signal;
this->public.broadcast = (void(*)(condvar_t*))broadcast;
this->public.destroy = (void(*)(condvar_t*))condvar_destroy;