Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SIMIX_sem_would_block() was blatantly wrong; missing {} in SIMIX_sem_acquire_any...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 24 Jun 2010 09:17:37 +0000 (09:17 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 24 Jun 2010 09:17:37 +0000 (09:17 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7927 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/simix/smx_synchro.c

index 5de5313..8cee3bc 100644 (file)
@@ -428,7 +428,7 @@ void SIMIX_sem_block_onto(smx_sem_t sem) {
 
 /** @brief Returns true if acquiring this semaphore would block */
 XBT_INLINE int SIMIX_sem_would_block(smx_sem_t sem) {
 
 /** @brief Returns true if acquiring this semaphore would block */
 XBT_INLINE int SIMIX_sem_would_block(smx_sem_t sem) {
-  return (sem->capacity>0);
+  return (sem->capacity<=0);
 }
 
 /** @brief Returns the current capacity of the semaphore
 }
 
 /** @brief Returns the current capacity of the semaphore
@@ -452,11 +452,14 @@ void SIMIX_sem_acquire(smx_sem_t sem) {
 
   DEBUG1("Wait semaphore %p", sem);
 
 
   DEBUG1("Wait semaphore %p", sem);
 
-  if (sem->capacity == SMX_SEM_NOLIMIT)
+  if (sem->capacity == SMX_SEM_NOLIMIT) {
+    DEBUG1("semaphore %p wide open", sem);
     return; /* don't even decrease it if wide open */
     return; /* don't even decrease it if wide open */
+  }
 
   /* If capacity sufficient, decrease it */
   if (sem->capacity>0) {
 
   /* If capacity sufficient, decrease it */
   if (sem->capacity>0) {
+    DEBUG1("semaphore %p has enough capacity", sem);
     sem->capacity--;
     return;
   }
     sem->capacity--;
     return;
   }
@@ -529,12 +532,14 @@ unsigned int SIMIX_sem_acquire_any(xbt_dynar_t sems) {
 
   xbt_assert0(xbt_dynar_length(sems),
       "I refuse to commit sucide by locking on an **empty** set of semaphores!!");
 
   xbt_assert0(xbt_dynar_length(sems),
       "I refuse to commit sucide by locking on an **empty** set of semaphores!!");
-  DEBUG1("Wait on semaphore set %p", sems);
+  DEBUG2("Wait on semaphore set %p (containing %ld semaphores)", sems,xbt_dynar_length(sems));
 
   xbt_dynar_foreach(sems,counter,sem) {
 
   xbt_dynar_foreach(sems,counter,sem) {
-    if (!SIMIX_sem_would_block(sem))
+    if (!SIMIX_sem_would_block(sem)) {
+      DEBUG1("Semaphore %p wouldn't block; get it without waiting",sem);
       SIMIX_sem_acquire(sem);
       SIMIX_sem_acquire(sem);
-    return counter;
+      return counter;
+    }
   }
 
   /* Always create an action null in case there is a host failure */
   }
 
   /* Always create an action null in case there is a host failure */