From: Frederic Suter Date: Wed, 13 Feb 2019 10:10:46 +0000 (+0100) Subject: more SemaphoreImpl cleanups X-Git-Tag: v3_22~341 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/27b8391954e453abb4e3e904b6663678163a0a26 more SemaphoreImpl cleanups --- diff --git a/src/kernel/activity/SemaphoreImpl.cpp b/src/kernel/activity/SemaphoreImpl.cpp index 8d74f2cb0e..29e92657b6 100644 --- a/src/kernel/activity/SemaphoreImpl.cpp +++ b/src/kernel/activity/SemaphoreImpl.cpp @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/kernel/activity/SemaphoreImpl.hpp" +#include "src/simix/smx_synchro_private.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_semaphore, simix_synchro, "Semaphore kernel-space implementation"); @@ -11,6 +12,21 @@ namespace simgrid { namespace kernel { namespace activity { +void SemaphoreImpl::acquire(smx_actor_t issuer, double timeout) +{ + smx_activity_t synchro = nullptr; + + XBT_DEBUG("Wait semaphore %p (timeout:%f)", this, timeout); + if (value_ <= 0) { + synchro = SIMIX_synchro_wait(issuer->host_, timeout); + synchro->simcalls_.push_front(&issuer->simcall); + issuer->waiting_synchro = synchro; + sleeping_.push_back(*issuer); + } else { + value_--; + SIMIX_simcall_answer(&issuer->simcall); + } +} void SemaphoreImpl::release() { XBT_DEBUG("Sem release semaphore %p", this); @@ -28,3 +44,21 @@ void SemaphoreImpl::release() } // namespace activity } // namespace kernel } // namespace simgrid + +// Simcall handlers: +/** + * @brief Handles a sem acquire simcall without timeout. + */ +void simcall_HANDLER_sem_acquire(smx_simcall_t simcall, smx_sem_t sem) +{ + sem->acquire(simcall->issuer, -1); +} + +/** + * @brief Handles a sem acquire simcall with timeout. + */ +void simcall_HANDLER_sem_acquire_timeout(smx_simcall_t simcall, smx_sem_t sem, double timeout) +{ + simcall_sem_acquire_timeout__set__result(simcall, 0); // default result, will be set to 1 on timeout + sem->acquire(simcall->issuer, timeout); +} diff --git a/src/kernel/activity/SemaphoreImpl.hpp b/src/kernel/activity/SemaphoreImpl.hpp index 6053af5561..913d761a11 100644 --- a/src/kernel/activity/SemaphoreImpl.hpp +++ b/src/kernel/activity/SemaphoreImpl.hpp @@ -24,6 +24,7 @@ public: SemaphoreImpl(SemaphoreImpl const&) = delete; SemaphoreImpl& operator=(SemaphoreImpl const&) = delete; + void acquire(smx_actor_t issuer, double timeout); void release(); bool would_block() { return (value_ <= 0); } unsigned int get_capacity() { return value_; } diff --git a/src/simix/smx_synchro.cpp b/src/simix/smx_synchro.cpp index 25f766451b..2aaa5b3a31 100644 --- a/src/simix/smx_synchro.cpp +++ b/src/simix/smx_synchro.cpp @@ -77,45 +77,3 @@ void SIMIX_synchro_finish(smx_activity_t synchro) } XBT_OUT(); } - -/******************************** Semaphores **********************************/ - -static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_actor_t issuer, - smx_simcall_t simcall) -{ - XBT_IN("(%p, %f, %p, %p)",sem,timeout,issuer,simcall); - smx_activity_t synchro = nullptr; - - XBT_DEBUG("Wait semaphore %p (timeout:%f)", sem, timeout); - if (sem->value_ <= 0) { - synchro = SIMIX_synchro_wait(issuer->host_, timeout); - synchro->simcalls_.push_front(simcall); - issuer->waiting_synchro = synchro; - sem->sleeping_.push_back(*issuer); - } else { - sem->value_--; - SIMIX_simcall_answer(simcall); - } - XBT_OUT(); -} - -/** - * @brief Handles a sem acquire simcall without timeout. - */ -void simcall_HANDLER_sem_acquire(smx_simcall_t simcall, smx_sem_t sem) -{ - XBT_IN("(%p)",simcall); - _SIMIX_sem_wait(sem, -1, simcall->issuer, simcall); - XBT_OUT(); -} - -/** - * @brief Handles a sem acquire simcall with timeout. - */ -void simcall_HANDLER_sem_acquire_timeout(smx_simcall_t simcall, smx_sem_t sem, double timeout) -{ - XBT_IN("(%p)",simcall); - simcall_sem_acquire_timeout__set__result(simcall, 0); // default result, will be set to 1 on timeout - _SIMIX_sem_wait(sem, timeout, simcall->issuer, simcall); - XBT_OUT(); -}