aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-16 10:30:58 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-16 11:08:27 +0100
commitbc40773cfa75a993f09a80e438bfa54d6e51c4ae (patch)
tree131b53f1e6c58a1723af1f8799c40cc1e8a0ffd8
parent0b402802e8482ae2c426d3c0dac7fdb8e4a430df (diff)
downloadpaludis-bc40773cfa75a993f09a80e438bfa54d6e51c4ae.tar.gz
paludis-bc40773cfa75a993f09a80e438bfa54d6e51c4ae.tar.xz
Let timed_wait wait for <1s
-rw-r--r--paludis/util/condition_variable.cc13
-rw-r--r--paludis/util/condition_variable.hh8
2 files changed, 16 insertions, 5 deletions
diff --git a/paludis/util/condition_variable.cc b/paludis/util/condition_variable.cc
index efabd1c..f659309 100644
--- a/paludis/util/condition_variable.cc
+++ b/paludis/util/condition_variable.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -66,11 +66,20 @@ ConditionVariable::wait(Mutex & m)
}
bool
-ConditionVariable::timed_wait(Mutex & m, const unsigned n)
+ConditionVariable::timed_wait(Mutex & m, const unsigned n, const unsigned ms)
{
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
+
t.tv_sec += n;
+ t.tv_nsec += (1000000 * ms);
+
+ if (t.tv_nsec >= 1000000000)
+ {
+ t.tv_nsec -= 1000000000;
+ t.tv_sec += 1;
+ }
+
int r(pthread_cond_timedwait(_cond, m.posix_mutex(), &t));
if (0 == r)
diff --git a/paludis/util/condition_variable.hh b/paludis/util/condition_variable.hh
index 87ee150..4b6197a 100644
--- a/paludis/util/condition_variable.hh
+++ b/paludis/util/condition_variable.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2010 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -84,9 +84,11 @@ namespace paludis
/**
* Wait, using the specified Mutex for synchronisation,
- * but return false if more than n seconds elapse.
+ * but return false if more than n seconds m ms elapse.
+ *
+ * \since 0.49 for ms argument
*/
- bool timed_wait(Mutex &, const unsigned n);
+ bool timed_wait(Mutex &, const unsigned n, const unsigned m = 0);
};
}