From 954f038683247f1e21f94c45ad2f449ffb83b1e5 Mon Sep 17 00:00:00 2001 From: mquinson Date: Wed, 17 Mar 2010 10:03:24 +0000 Subject: [PATCH] add a SIMIX_sem_get_capacity() function git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7256 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 2 ++ src/include/simix/simix.h | 1 + src/simix/smx_synchro.c | 12 ++++++++++++ 3 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 237b6ef11e..f89a88594b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,8 @@ SimGrid (3.3.5-svn) unstable; urgency=low and call MSG_action_trace_run(NULL) You can still have one merged file for each processes. * Kill the MSG_paje_output() function. It's a noop since 2 years. + SIMIX: + * add a SIMIX_sem_get_capacity() function -- Da SimGrid team diff --git a/src/include/simix/simix.h b/src/include/simix/simix.h index 631ab6881b..97eb4d0834 100644 --- a/src/include/simix/simix.h +++ b/src/include/simix/simix.h @@ -150,6 +150,7 @@ XBT_PUBLIC(void) SIMIX_sem_block_onto(smx_sem_t sem); XBT_PUBLIC(void) SIMIX_sem_acquire(smx_sem_t sem); XBT_PUBLIC(void) SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration); XBT_PUBLIC(unsigned int) SIMIX_sem_acquire_any(xbt_dynar_t sems); +XBT_PUBLIC(int) SIMIX_sem_get_capacity(smx_sem_t sem); /************************** Action handling ************************************/ diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index b740deaaaa..92ddf2778e 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -433,6 +433,14 @@ XBT_INLINE int SIMIX_sem_would_block(smx_sem_t sem) { return (sem->capacity>0); } +/** @brief Returns the current capacity of the semaphore + * + * If it's negative, that's the amount of processes locked on the semaphore + */ +int SIMIX_sem_get_capacity(smx_sem_t sem){ + return sem->capacity; +} + /** * \brief Waits on a semaphore * @@ -455,6 +463,7 @@ void SIMIX_sem_acquire(smx_sem_t sem) { return; } + sem->capacity--; /* Always create an action null in case there is a host failure */ act_sleep = SIMIX_action_sleep(SIMIX_host_self(), -1); SIMIX_action_set_name(act_sleep,bprintf("Locked in semaphore %p", sem)); @@ -465,6 +474,7 @@ void SIMIX_sem_acquire(smx_sem_t sem) { SIMIX_unregister_action_to_semaphore(act_sleep, sem); SIMIX_action_destroy(act_sleep); DEBUG1("End of Wait on semaphore %p", sem); + sem->capacity++; } /** * \brief Tries to acquire a semaphore before a timeout @@ -486,6 +496,7 @@ void SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration) { } if (max_duration >= 0) { + sem->capacity--; act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration); SIMIX_action_set_name(act_sleep,bprintf("Timed wait semaphore %p (max_duration:%f)", sem,max_duration)); SIMIX_register_action_to_semaphore(act_sleep, sem); @@ -499,6 +510,7 @@ void SIMIX_sem_acquire_timeout(smx_sem_t sem, double max_duration) { } else { SIMIX_action_destroy(act_sleep); } + sem->capacity++; } else SIMIX_sem_acquire(sem); -- 2.20.1