- smx_action_t act_sleep;
-
- DEBUG1("Wait semaphore %p", sem);
-
- if (sem->capacity == SMX_SEM_NOLIMIT)
- return; /* don't even decrease it if wide open */
-
- /* If capacity sufficient, decrease it */
- if (sem->capacity>0) {
- sem->capacity--;
- 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_process_self()->waiting_action = act_sleep;
- SIMIX_register_action_to_semaphore(act_sleep, sem);
- SIMIX_sem_block_onto(sem);
- SIMIX_process_self()->waiting_action = NULL;
- SIMIX_unregister_action_to_semaphore(act_sleep, sem);
- SIMIX_action_destroy(act_sleep);
- DEBUG1("End of Wait on semaphore %p", sem);
- sem->capacity++;