X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/23529d55ccbfd0a851fdc86708320811ddda8ec4..bc691c290cd062a5c929b94d32b92f18ef5d235b:/communicator.cpp?ds=inline diff --git a/communicator.cpp b/communicator.cpp index 8adb258..90cf990 100644 --- a/communicator.cpp +++ b/communicator.cpp @@ -83,13 +83,26 @@ void communicator::send(const char* dest, message* msg) sent_comm.push_back(comm); } -bool communicator::recv(message*& msg, m_host_t& from, bool wait) +bool communicator::recv(message*& msg, m_host_t& from, double timeout) { - if (wait) { + if (timeout != 0) { + volatile double deadline = + timeout > 0 ? MSG_get_clock() + timeout : 0.0; xbt_mutex_acquire(mutex); - while (received.empty()) { + while (received.empty() && (!deadline || deadline > MSG_get_clock())) { + xbt_ex_t e; DEBUG0("waiting for a message to come"); - xbt_cond_wait(cond, mutex); + TRY { + if (deadline) + xbt_cond_timedwait(cond, mutex, deadline - MSG_get_clock()); + else + xbt_cond_wait(cond, mutex); + } + CATCH (e) { + if (e.category != timeout_error) + RETHROW; + xbt_ex_free(e); + } } xbt_mutex_release(mutex); }