A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[s4u] Actor::forPid()
[simgrid.git]
/
include
/
simgrid
/
s4u
/
conditionVariable.hpp
diff --git
a/include/simgrid/s4u/conditionVariable.hpp
b/include/simgrid/s4u/conditionVariable.hpp
index
f29a26d
..
0c34c92
100644
(file)
--- a/
include/simgrid/s4u/conditionVariable.hpp
+++ b/
include/simgrid/s4u/conditionVariable.hpp
@@
-18,6
+18,12
@@
namespace s4u {
class Mutex;
class Mutex;
+/** A condition variable
+ *
+ * This is based on std::condition_variable and should respect the same
+ * semantic. But we currently use (only) double for both durations and
+ * timestamp timeouts.
+ */
XBT_PUBLIC_CLASS ConditionVariable {
public:
XBT_PUBLIC_CLASS ConditionVariable {
public:
@@
-48,34
+54,36
@@
public:
return cond_ != nullptr;
}
return cond_ != nullptr;
}
- /**
- * Wait functions
- */
+ // Wait functions:
+
void wait(std::unique_lock<Mutex>& lock);
void wait(std::unique_lock<Mutex>& lock);
- // TODO, return std::cv_status
+ std::cv_status wait_until(std::unique_lock<Mutex>& lock, double timeout_time);
std::cv_status wait_for(std::unique_lock<Mutex>& lock, double duration);
std::cv_status wait_for(std::unique_lock<Mutex>& lock, double duration);
- // TODO, wait_until
- /** Variant which takes a predice */
+ // Variants which takes a predicate:
+
template<class P>
void wait(std::unique_lock<Mutex>& lock, P pred)
{
while (!pred())
wait(lock);
}
template<class P>
void wait(std::unique_lock<Mutex>& lock, P pred)
{
while (!pred())
wait(lock);
}
-
- // TODO, return std::cv_status
template<class P>
template<class P>
-
std::cv_status wait_for(std::unique_lock<Mutex>& lock, double duration
, P pred)
+
bool wait_until(std::unique_lock<Mutex>& lock, double timeout_time
, P pred)
{
while (!pred())
{
while (!pred())
- wait_for(lock, duration);
+ if (this->wait_until(lock, timeout_time) == std::cv_status::timeout)
+ return pred();
+ return true;
}
}
- // TODO,wait_until
+ template<class P>
+ bool wait_for(std::unique_lock<Mutex>& lock, double duration, P pred)
+ {
+ return this->wait_until(lock, SIMIX_get_clock() + duration, std::move(pred));
+ }
+
+ // Notify functions
- /**
- * Notify functions
- */
void notify();
void notify_all();
void notify();
void notify_all();