/* ******************************** Syncro ************************************ */
- typedef struct s_smx_mutex *smx_mutex_t;
- typedef struct s_smx_cond *smx_cond_t;
- typedef struct s_smx_sem *smx_sem_t;
+ typedef struct s_smx_mutex {
+ xbt_swag_t sleeping; /* list of sleeping process */
+ int refcount;
+ } s_smx_mutex_t;
+ typedef s_smx_mutex_t *smx_mutex_t;
+
+ typedef struct s_smx_cond {
+ xbt_swag_t sleeping; /* list of sleeping process */
+ smx_mutex_t mutex;
+ xbt_fifo_t actions; /* list of actions */
+ } s_smx_cond_t;
+ typedef s_smx_cond_t *smx_cond_t;
+
+ typedef struct s_smx_sem {
+ xbt_fifo_t sleeping; /* list of sleeping process */
+ int capacity;
+ xbt_fifo_t actions; /* list of actions */
+ } s_smx_sem_t;
+ typedef s_smx_sem_t *smx_sem_t;
/********************************** Action *************************************/
typedef struct s_smx_action *smx_action_t;
ex_ctx_t *SIMIX_process_get_exception(void);
void SIMIX_process_exception_terminate(xbt_ex_t * e);
-/*************************** Mutex and Conditional ****************************/
-
-typedef struct s_smx_mutex {
-
- /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
- xbt_swag_t sleeping; /* list of sleeping process */
- int refcount;
- /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
-
-} s_smx_mutex_t;
-
-typedef struct s_smx_cond {
-
- /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
- xbt_swag_t sleeping; /* list of sleeping process */
- smx_mutex_t mutex;
- xbt_fifo_t actions; /* list of actions */
- /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */
-
-} s_smx_cond_t;
-
-typedef struct s_smx_sem {
- /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_sem */
- xbt_swag_t sleeping; /* list of sleeping process */
- int capacity;
- xbt_fifo_t actions; /* list of actions */
- /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_sem */
-
-} s_smx_sem_t;
-
/******************************* Networking ***********************************/
/** @brief Rendez-vous point datatype */
/** @brief Initialize a semaphore */
smx_sem_t SIMIX_sem_init(int capacity) {
smx_sem_t sem = xbt_new0(s_smx_sem_t, 1);
- s_smx_process_t p;
- sem->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup));
+ sem->sleeping = xbt_fifo_new();
sem->actions = xbt_fifo_new();
sem->capacity = capacity;
return sem;
if (sem == NULL)
return;
- xbt_assert0(xbt_swag_size(sem->sleeping) == 0,
+ xbt_assert0(xbt_fifo_size(sem->sleeping) == 0,
"Cannot destroy semaphore since someone is still using it");
- xbt_swag_free(sem->sleeping);
+ xbt_fifo_free(sem->sleeping);
DEBUG1("%d actions registered", xbt_fifo_size(sem->actions));
while((action=xbt_fifo_pop(sem->actions)))
* If no one was blocked, the semaphore capacity is increased by 1.
* */
void SIMIX_sem_release(smx_sem_t sem) {
- DEBUG1("Sem release semaphore %p", sem);
- if (xbt_swag_size(sem->sleeping) >= 1) {
- smx_process_t proc = xbt_swag_extract(sem->sleeping);
+ smx_process_t proc;
+
+ DEBUG1("Sem release semaphore %p", sem);
+ if ((proc = xbt_fifo_shift(sem->sleeping)) != NULL) {
xbt_swag_insert(proc, simix_global->process_to_run);
} else if (sem->capacity != SMX_SEM_NOLIMIT) {
sem->capacity++;
* There is no way to reset the semaphore to a more regular state afterward.
* */
void SIMIX_sem_release_forever(smx_sem_t sem) {
- smx_process_t proc = NULL;
- smx_process_t proc_next = NULL;
+ smx_process_t proc;
DEBUG1("Broadcast semaphore %p", sem);
- xbt_swag_foreach_safe(proc, proc_next, sem->sleeping) {
- xbt_swag_remove(proc, sem->sleeping);
+ while ((proc = xbt_fifo_shift(sem->sleeping)) != NULL) {
xbt_swag_insert(proc, simix_global->process_to_run);
}
sem->capacity = SMX_SEM_NOLIMIT;
/* process status */
self->sem = sem;
- xbt_swag_insert(self, sem->sleeping);
+ xbt_fifo_push (sem->sleeping, self);
SIMIX_process_yield();
self->sem = NULL;
while (self->suspended)
/* Get listed as member of all the provided semaphores */
self->sem = (smx_sem_t)sems; /* FIXME: we pass a pointer to dynar where a pointer to sem is expected...*/
xbt_dynar_foreach(sems,counter,sem) {
- xbt_swag_insert(self, sem->sleeping);
+ xbt_fifo_push(sem->sleeping, self);
}
SIMIX_process_yield();
self->sem = NULL;
/* one of the semaphore unsuspended us -- great, let's search which one (and get out of the others) */
xbt_dynar_foreach(sems,counter,sem) {
- if (xbt_swag_belongs(self,sem->sleeping))
- xbt_swag_remove(self,sem->sleeping);
- else {
- xbt_assert0(result==-1,"More than one semaphore unlocked us. Dunno what to do");
+ if (!xbt_fifo_remove(sem->sleeping, self)) {
+ xbt_assert1(result == -1, "You're trying to wait more than once on semaphore %p, don't you ?", sem);
result = counter;
}
}
/****** mutex related functions ******/
struct s_xbt_mutex_ {
-
- /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_mutex */
- xbt_swag_t sleeping; /* list of sleeping process */
- int refcount;
- /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_mutex */
-
+ s_smx_mutex_t mutex;
};
xbt_mutex_t xbt_mutex_init(void)
/***** condition related functions *****/
struct s_xbt_cond_ {
-
- /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_cond */
- xbt_swag_t sleeping; /* list of sleeping process */
- smx_mutex_t mutex;
- xbt_fifo_t actions; /* list of actions */
- /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_cond */
-
+ s_smx_cond_t cond;
};
xbt_cond_t xbt_cond_init(void)