aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2008-11-25 19:30:02 +0000
committerTobias Brunner <tobias@strongswan.org>2008-11-25 19:30:02 +0000
commit6df2731e7847d65f3aceef2a24c6e8548839b5e8 (patch)
tree405d66d1e0be1621d7731776c02937c358aa76d7 /src/libstrongswan
parented6146ffbe3c798a49ff178d4448548240cbeb38 (diff)
downloadstrongswan-6df2731e7847d65f3aceef2a24c6e8548839b5e8.tar.bz2
strongswan-6df2731e7847d65f3aceef2a24c6e8548839b5e8.tar.xz
replacing the pthread_mutex in scheduler_t with the wrapped implementation.
added a method to condvar_t which allows to wait for an absolute timeout.
Diffstat (limited to 'src/libstrongswan')
-rw-r--r--src/libstrongswan/utils/mutex.c48
-rw-r--r--src/libstrongswan/utils/mutex.h12
2 files changed, 44 insertions, 16 deletions
diff --git a/src/libstrongswan/utils/mutex.c b/src/libstrongswan/utils/mutex.c
index 3dc274e8c..cb6940d3f 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
*
@@ -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;
diff --git a/src/libstrongswan/utils/mutex.h b/src/libstrongswan/utils/mutex.h
index a0a198024..1aadb71ad 100644
--- a/src/libstrongswan/utils/mutex.h
+++ b/src/libstrongswan/utils/mutex.h
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2008 Tobias Brunner
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
@@ -11,6 +12,8 @@
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
+ *
+ * $Id$
*/
/**
@@ -99,6 +102,15 @@ struct condvar_t {
bool (*timed_wait)(condvar_t *this, mutex_t *mutex, u_int timeout);
/**
+ * Wait on a condvar until it gets signalized, or times out.
+ *
+ * @param mutex mutex to release while waiting
+ * @param time absolute time until timeout
+ * @return TRUE if timed out, FALSE otherwise
+ */
+ bool (*timed_wait_abs)(condvar_t *this, mutex_t *mutex, timeval_t timeout);
+
+ /**
* Wake up a single thread in a condvar.
*/
void (*signal)(condvar_t *this);