-/* $Id$ */
-
-/* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
- All rights reserved. */
+/* Copyright (c) 2007, 2008, 2009, 2010. 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. */
}
/** @brief Destroys a semaphore */
void SIMIX_sem_destroy(smx_sem_t sem) {
+ smx_action_t action = NULL;
DEBUG1("Destroy semaphore %p", sem);
if (sem == NULL)
return;
- smx_action_t action = NULL;
-
xbt_assert0(xbt_swag_size(sem->sleeping) == 0,
"Cannot destroy semaphore since someone is still using it");
xbt_swag_free(sem->sleeping);
xbt_swag_remove(proc, sem->sleeping);
xbt_swag_insert(proc, simix_global->process_to_run);
}
+ sem->capacity = SMX_SEM_NOLIMIT;
}
/**
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
*
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));
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
}
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);
} else {
SIMIX_action_destroy(act_sleep);
}
+ sem->capacity++;
} else
SIMIX_sem_acquire(sem);
xbt_swag_insert(self, sem->sleeping);
}
SIMIX_process_yield();
+ self->sem = NULL;
while (self->suspended)
SIMIX_process_yield();
/* one of the semaphore unsuspended us -- great, let's search which one (and get out of the others) */
- self->sem = NULL;
xbt_dynar_foreach(sems,counter,sem) {
if (xbt_swag_belongs(self,sem->sleeping))
xbt_swag_remove(self,sem->sleeping);