X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/29379a85ce9802fd3174f4237b57d240a704cb45..b5c0093dd3fb7d66ec6e1f72963ba7b9faa45fe7:/src/s4u/s4u_ConditionVariable.cpp diff --git a/src/s4u/s4u_ConditionVariable.cpp b/src/s4u/s4u_ConditionVariable.cpp index 4d053aed3f..1656d7f43f 100644 --- a/src/s4u/s4u_ConditionVariable.cpp +++ b/src/s4u/s4u_ConditionVariable.cpp @@ -1,8 +1,10 @@ -/* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2006-2019. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "simgrid/cond.h" +#include "simgrid/forward.h" #include "simgrid/s4u/ConditionVariable.hpp" #include "simgrid/simix.h" #include "src/kernel/activity/ConditionVariableImpl.hpp" @@ -16,7 +18,8 @@ namespace s4u { ConditionVariablePtr ConditionVariable::create() { - smx_cond_t cond = simcall_cond_init(); + kernel::activity::ConditionVariableImpl* cond = + simix::simcall([] { return new kernel::activity::ConditionVariableImpl(); }); return ConditionVariablePtr(&cond->cond_, false); } @@ -84,3 +87,38 @@ void intrusive_ptr_release(ConditionVariable* cond) } // namespace s4u } // namespace simgrid + +/* **************************** Public C interface *************************** */ +sg_cond_t sg_cond_init() +{ + simgrid::kernel::activity::ConditionVariableImpl* cond = + simgrid::simix::simcall([] { return new simgrid::kernel::activity::ConditionVariableImpl(); }); + + return new simgrid::s4u::ConditionVariable(cond); +} + +void sg_cond_wait(sg_cond_t cond, sg_mutex_t mutex) +{ + cond->wait(mutex); +} + +int sg_cond_wait_for(sg_cond_t cond, sg_mutex_t mutex, double delay) +{ + std::unique_lock lock(*mutex); + return cond->wait_for(lock, delay) == std::cv_status::timeout ? 1 : 0; +} + +void sg_cond_notify_one(sg_cond_t cond) +{ + cond->notify_one(); +} + +void sg_cond_notify_all(sg_cond_t cond) +{ + cond->notify_all(); +} + +void sg_cond_destroy(sg_cond_t cond) +{ + delete cond; +}