SimGrid  3.13
Versatile Simulation of Distributed Systems
smx_synchro.cpp File Reference
#include "src/surf/surf_interface.hpp"
#include "smx_private.h"
#include "xbt/log.h"

Macros

#define SMX_SEM_NOLIMIT   99999
 

Functions

 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (simix_synchro, simix,"SIMIX Synchronization (mutex, semaphores and conditions)")
 
static smx_synchro_t SIMIX_synchro_wait (sg_host_t smx_host, double timeout)
 
static void SIMIX_synchro_finish (smx_synchro_t synchro)
 
static void _SIMIX_cond_wait (smx_cond_t cond, smx_mutex_t mutex, double timeout, smx_process_t issuer, smx_simcall_t simcall)
 
static void _SIMIX_sem_wait (smx_sem_t sem, double timeout, smx_process_t issuer, smx_simcall_t simcall)
 
void SIMIX_synchro_stop_waiting (smx_process_t process, smx_simcall_t simcall)
 
void SIMIX_synchro_destroy (smx_synchro_t synchro)
 
void SIMIX_post_synchro (smx_synchro_t synchro)
 
smx_mutex_t simcall_HANDLER_mutex_init (smx_simcall_t simcall)
 
smx_mutex_t SIMIX_mutex_init (void)
 Initialize a mutex. More...
 
void simcall_HANDLER_mutex_lock (smx_simcall_t simcall, smx_mutex_t mutex)
 Handles a mutex lock simcall. More...
 
int simcall_HANDLER_mutex_trylock (smx_simcall_t simcall, smx_mutex_t mutex)
 
int SIMIX_mutex_trylock (smx_mutex_t mutex, smx_process_t issuer)
 Tries to lock a mutex. More...
 
void simcall_HANDLER_mutex_unlock (smx_simcall_t simcall, smx_mutex_t mutex)
 
void SIMIX_mutex_unlock (smx_mutex_t mutex, smx_process_t issuer)
 Unlocks a mutex. More...
 
void SIMIX_mutex_destroy (smx_mutex_t mutex)
 Destroys a mutex. More...
 
smx_cond_t SIMIX_cond_init (void)
 Initialize a condition. More...
 
void simcall_HANDLER_cond_wait (smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex)
 Handle a condition waiting simcall without timeouts. More...
 
void simcall_HANDLER_cond_wait_timeout (smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex, double timeout)
 Handle a condition waiting simcall with timeouts. More...
 
void SIMIX_cond_signal (smx_cond_t cond)
 Signalizes a condition. More...
 
void SIMIX_cond_broadcast (smx_cond_t cond)
 Broadcasts a condition. More...
 
void SIMIX_cond_destroy (smx_cond_t cond)
 Destroys a condition. More...
 
smx_sem_t SIMIX_sem_init (unsigned int value)
 Initialize a semaphore. More...
 
void SIMIX_sem_destroy (smx_sem_t sem)
 Destroys a semaphore. More...
 
void simcall_HANDLER_sem_release (smx_simcall_t simcall, smx_sem_t sem)
 
void SIMIX_sem_release (smx_sem_t sem)
 release the semaphore More...
 
int SIMIX_sem_would_block (smx_sem_t sem)
 Returns true if acquiring this semaphore would block. More...
 
int simcall_HANDLER_sem_get_capacity (smx_simcall_t simcall, smx_sem_t sem)
 
int SIMIX_sem_get_capacity (smx_sem_t sem)
 Returns the current capacity of the semaphore. More...
 
void simcall_HANDLER_sem_acquire (smx_simcall_t simcall, smx_sem_t sem)
 Handles a sem acquire simcall without timeout. More...
 
void simcall_HANDLER_sem_acquire_timeout (smx_simcall_t simcall, smx_sem_t sem, double timeout)
 Handles a sem acquire simcall with timeout. More...
 
int simcall_HANDLER_sem_would_block (smx_simcall_t simcall, smx_sem_t sem)
 

Macro Definition Documentation

#define SMX_SEM_NOLIMIT   99999

Function Documentation

XBT_LOG_NEW_DEFAULT_SUBCATEGORY ( simix_synchro  ,
simix  ,
"SIMIX Synchronization (mutex, semaphores and conditions)"   
)
static smx_synchro_t SIMIX_synchro_wait ( sg_host_t  smx_host,
double  timeout 
)
static
static void SIMIX_synchro_finish ( smx_synchro_t  synchro)
static
static void _SIMIX_cond_wait ( smx_cond_t  cond,
smx_mutex_t  mutex,
double  timeout,
smx_process_t  issuer,
smx_simcall_t  simcall 
)
static
static void _SIMIX_sem_wait ( smx_sem_t  sem,
double  timeout,
smx_process_t  issuer,
smx_simcall_t  simcall 
)
static
void SIMIX_synchro_stop_waiting ( smx_process_t  process,
smx_simcall_t  simcall 
)
void SIMIX_synchro_destroy ( smx_synchro_t  synchro)
void SIMIX_post_synchro ( smx_synchro_t  synchro)
smx_mutex_t simcall_HANDLER_mutex_init ( smx_simcall_t  simcall)
smx_mutex_t SIMIX_mutex_init ( void  )

Initialize a mutex.

Allocs and creates the data for the mutex.

Returns
A mutex
void simcall_HANDLER_mutex_lock ( smx_simcall_t  simcall,
smx_mutex_t  mutex 
)

Handles a mutex lock simcall.

Parameters
simcallthe simcall
int simcall_HANDLER_mutex_trylock ( smx_simcall_t  simcall,
smx_mutex_t  mutex 
)
int SIMIX_mutex_trylock ( smx_mutex_t  mutex,
smx_process_t  issuer 
)

Tries to lock a mutex.

Tries to lock a mutex, return 1 if the mutex is unlocked, else 0. This function does not block and wait for the mutex to be unlocked.

Parameters
mutexThe mutex
issuerThe process that tries to acquire the mutex
Returns
1 - mutex free, 0 - mutex used
void simcall_HANDLER_mutex_unlock ( smx_simcall_t  simcall,
smx_mutex_t  mutex 
)
void SIMIX_mutex_unlock ( smx_mutex_t  mutex,
smx_process_t  issuer 
)

Unlocks a mutex.

Unlocks the mutex and gives it to a process waiting for it. If the unlocker is not the owner of the mutex nothing happens. If there are no process waiting, it sets the mutex as free.

Parameters
mutexThe mutex
issuerThe process trying to unlock the mutex
void SIMIX_mutex_destroy ( smx_mutex_t  mutex)

Destroys a mutex.

Destroys and frees the mutex's memory.

Parameters
mutexA mutex
smx_cond_t SIMIX_cond_init ( void  )

Initialize a condition.

Allocates and creates the data for the condition. It have to be called before the use of the condition.

Returns
A condition
void simcall_HANDLER_cond_wait ( smx_simcall_t  simcall,
smx_cond_t  cond,
smx_mutex_t  mutex 
)

Handle a condition waiting simcall without timeouts.

Parameters
simcallthe simcall
void simcall_HANDLER_cond_wait_timeout ( smx_simcall_t  simcall,
smx_cond_t  cond,
smx_mutex_t  mutex,
double  timeout 
)

Handle a condition waiting simcall with timeouts.

Parameters
simcallthe simcall
void SIMIX_cond_signal ( smx_cond_t  cond)

Signalizes a condition.

Signalizes a condition and wakes up a sleeping process. If there are no process sleeping, no action is done.

Parameters
condA condition
void SIMIX_cond_broadcast ( smx_cond_t  cond)

Broadcasts a condition.

Signal ALL processes waiting on a condition. If there are no process waiting, no action is done.

Parameters
condA condition
void SIMIX_cond_destroy ( smx_cond_t  cond)

Destroys a condition.

Destroys and frees the condition's memory.

Parameters
condA condition
smx_sem_t SIMIX_sem_init ( unsigned int  value)

Initialize a semaphore.

void SIMIX_sem_destroy ( smx_sem_t  sem)

Destroys a semaphore.

void simcall_HANDLER_sem_release ( smx_simcall_t  simcall,
smx_sem_t  sem 
)
void SIMIX_sem_release ( smx_sem_t  sem)

release the semaphore

Unlock a process waiting on the semaphore. If no one was blocked, the semaphore capacity is increased by 1.

int SIMIX_sem_would_block ( smx_sem_t  sem)

Returns true if acquiring this semaphore would block.

int simcall_HANDLER_sem_get_capacity ( smx_simcall_t  simcall,
smx_sem_t  sem 
)
int SIMIX_sem_get_capacity ( smx_sem_t  sem)

Returns the current capacity of the semaphore.

void simcall_HANDLER_sem_acquire ( smx_simcall_t  simcall,
smx_sem_t  sem 
)

Handles a sem acquire simcall without timeout.

Parameters
simcallthe simcall
void simcall_HANDLER_sem_acquire_timeout ( smx_simcall_t  simcall,
smx_sem_t  sem,
double  timeout 
)

Handles a sem acquire simcall with timeout.

Parameters
simcallthe simcall
int simcall_HANDLER_sem_would_block ( smx_simcall_t  simcall,
smx_sem_t  sem 
)