OpenMPI  0.1.1
mutex.h File Reference

Mutual exclusion functions. More...

#include "opal_config.h"
#include "mutex_unix.h"

Go to the source code of this file.

Macros

#define opal_using_threads()   opal_uses_threads
 Check and see if the process is using multiple threads. More...
 
#define OPAL_THREAD_LOCK(mutex)
 Lock a mutex if opal_using_threads() says that multiple threads may be active in the process. More...
 
#define OPAL_THREAD_TRYLOCK(mutex)   0
 Try to lock a mutex if opal_using_threads() says that multiple threads may be active in the process. More...
 
#define OPAL_THREAD_UNLOCK(mutex)
 Unlock a mutex if opal_using_threads() says that multiple threads may be active in the process. More...
 
#define OPAL_THREAD_SCOPED_LOCK(mutex, action)   (action)
 Lock a mutex if opal_using_threads() says that multiple threads may be active in the process for the duration of the specified action. More...
 
#define OPAL_THREAD_ADD32(x, y)   (*x += y)
 Use an atomic operation for increment/decrement if opal_using_threads() indicates that threads are in use by the application or library.
 
#define OPAL_THREAD_ADD64(x, y)   (*x += y)
 
#define OPAL_THREAD_ADD_SIZE_T(x, y)   (*x += y)
 
#define OPAL_CMPSET(x, y, z)   ((*(x) == (y)) ? ((*(x) = (z)), 1) : 0)
 

Typedefs

typedef struct opal_mutex_t opal_mutex_t
 Opaque mutex object.
 

Functions

static int opal_mutex_trylock (opal_mutex_t *mutex)
 Try to acquire a mutex. More...
 
static void opal_mutex_lock (opal_mutex_t *mutex)
 Acquire a mutex. More...
 
static void opal_mutex_unlock (opal_mutex_t *mutex)
 Release a mutex. More...
 
static int opal_mutex_atomic_trylock (opal_mutex_t *mutex)
 Try to acquire a mutex using atomic operations. More...
 
static void opal_mutex_atomic_lock (opal_mutex_t *mutex)
 Acquire a mutex using atomic operations. More...
 
static void opal_mutex_atomic_unlock (opal_mutex_t *mutex)
 Release a mutex using atomic operations. More...
 
static bool opal_set_using_threads (bool have)
 Set whether the process is using multiple threads or not. More...
 

Variables

OPAL_DECLSPEC bool opal_uses_threads
 

Detailed Description

Mutual exclusion functions.

Functions for locking of critical sections.

Macro Definition Documentation

#define OPAL_THREAD_LOCK (   mutex)

Lock a mutex if opal_using_threads() says that multiple threads may be active in the process.

Parameters
mutexPointer to a opal_mutex_t to lock.

If there is a possibility that multiple threads are running in the process (as determined by opal_using_threads()), this function will block waiting to lock the mutex.

If there is no possibility that multiple threads are running in the process, return immediately.

Referenced by mca_allocator_basic_alloc(), mca_allocator_basic_free(), mca_allocator_bucket_alloc(), mca_allocator_bucket_alloc_align(), mca_allocator_bucket_cleanup(), mca_allocator_bucket_free(), mca_btl_elan_component_progress(), mca_btl_gm_add_procs(), mca_btl_gm_component_init(), mca_btl_gm_component_progress(), mca_btl_gm_finalize(), mca_btl_gm_get(), mca_btl_gm_put(), mca_btl_gm_send(), mca_btl_mx_add_procs(), mca_btl_sctp_add_procs(), mca_btl_tcp_add_procs(), mca_btl_template_add_procs(), mca_btl_ud_add_procs(), mca_btl_ud_component_progress(), mca_btl_udapl_add_procs(), mca_btl_udapl_component_progress(), mca_btl_udapl_put(), mca_mpool_base_tree_find(), mca_mpool_grdma_deregister(), mca_mpool_grdma_finalize(), mca_mpool_grdma_find(), mca_mpool_grdma_register(), mca_mpool_grdma_release_memory(), mca_mpool_rdma_deregister(), mca_mpool_rdma_finalize(), mca_mpool_rdma_find(), mca_mpool_rdma_register(), mca_mpool_rdma_release_memory(), mca_mpool_rgpusm_deregister(), mca_mpool_rgpusm_finalize(), mca_mpool_rgpusm_find(), mca_mpool_rgpusm_register(), mca_oob_tcp_fini(), mca_oob_tcp_msg_complete(), mca_oob_tcp_peer_accept(), mca_oob_tcp_peer_lookup(), mca_oob_tcp_peer_resolved(), mca_oob_tcp_peer_send(), mca_oob_tcp_recv_cancel(), mca_oob_tcp_recv_nb(), mca_oob_tcp_resolve(), mca_oob_tcp_set_addr(), mca_pml_bfo_error_pending_packets(), mca_pml_bfo_recv_frag_callback_match(), mca_pml_bfo_recv_frag_match(), mca_pml_bfo_recv_req_start(), mca_pml_bfo_send_request_restart(), mca_pml_bfo_start(), mca_pml_csum_recv_frag_callback_match(), mca_pml_csum_recv_frag_match(), mca_pml_csum_recv_req_start(), mca_pml_csum_start(), mca_pml_ob1_recv_frag_callback_match(), mca_pml_ob1_recv_frag_match(), mca_pml_ob1_recv_req_start(), mca_pml_ob1_start(), ompi_attr_copy_all(), ompi_attr_delete(), ompi_attr_delete_all(), ompi_attr_free_keyval(), ompi_proc_all(), ompi_proc_complete_init(), ompi_proc_find(), ompi_proc_pack(), ompi_proc_refresh(), ompi_proc_world(), ompi_request_wait_completion(), opal_output_close(), opal_pointer_array_add(), opal_pointer_array_get_item(), opal_pointer_array_remove_all(), opal_pointer_array_set_item(), opal_pointer_array_set_size(), opal_pointer_array_test_and_set_item(), opal_util_keyval_parse(), orte_odls_base_default_signal_local_procs(), orte_plm_submit_launch(), and recv_request_pml_complete().

#define OPAL_THREAD_SCOPED_LOCK (   mutex,
  action 
)    (action)

Lock a mutex if opal_using_threads() says that multiple threads may be active in the process for the duration of the specified action.

Parameters
mutexPointer to a opal_mutex_t to lock.
actionA scope over which the lock is held.

If there is a possibility that multiple threads are running in the process (as determined by opal_using_threads()), this function will acquire the lock before invoking the specified action and release it on return.

If there is no possibility that multiple threads are running in the process, invoke the action without acquiring the lock.

#define OPAL_THREAD_TRYLOCK (   mutex)    0

Try to lock a mutex if opal_using_threads() says that multiple threads may be active in the process.

Parameters
mutexPointer to a opal_mutex_t to trylock

If there is a possibility that multiple threads are running in the process (as determined by opal_using_threads()), this function will trylock the mutex.

If there is no possibility that multiple threads are running in the process, return immediately without modifying the mutex.

Returns 0 if mutex was locked, non-zero otherwise.

Referenced by mca_btl_elan_component_progress().

#define OPAL_THREAD_UNLOCK (   mutex)

Unlock a mutex if opal_using_threads() says that multiple threads may be active in the process.

Parameters
mutexPointer to a opal_mutex_t to unlock.

If there is a possibility that multiple threads are running in the process (as determined by opal_using_threads()), this function will unlock the mutex.

If there is no possibility that multiple threads are running in the process, return immediately without modifying the mutex.

Referenced by mca_allocator_basic_alloc(), mca_allocator_basic_free(), mca_allocator_bucket_alloc(), mca_allocator_bucket_alloc_align(), mca_allocator_bucket_cleanup(), mca_allocator_bucket_free(), mca_btl_elan_component_progress(), mca_btl_gm_add_procs(), mca_btl_gm_component_init(), mca_btl_gm_component_progress(), mca_btl_gm_finalize(), mca_btl_gm_get(), mca_btl_gm_put(), mca_btl_gm_send(), mca_btl_mx_add_procs(), mca_btl_sctp_add_procs(), mca_btl_tcp_add_procs(), mca_btl_template_add_procs(), mca_btl_ud_add_procs(), mca_btl_ud_component_progress(), mca_btl_udapl_add_procs(), mca_btl_udapl_component_progress(), mca_btl_udapl_put(), mca_mpool_base_tree_find(), mca_mpool_grdma_deregister(), mca_mpool_grdma_finalize(), mca_mpool_grdma_find(), mca_mpool_grdma_register(), mca_mpool_grdma_release_memory(), mca_mpool_rdma_deregister(), mca_mpool_rdma_finalize(), mca_mpool_rdma_find(), mca_mpool_rdma_register(), mca_mpool_rdma_release_memory(), mca_mpool_rgpusm_deregister(), mca_mpool_rgpusm_finalize(), mca_mpool_rgpusm_find(), mca_mpool_rgpusm_register(), mca_oob_tcp_fini(), mca_oob_tcp_msg_complete(), mca_oob_tcp_peer_accept(), mca_oob_tcp_peer_close(), mca_oob_tcp_peer_lookup(), mca_oob_tcp_peer_resolved(), mca_oob_tcp_peer_send(), mca_oob_tcp_recv_cancel(), mca_oob_tcp_recv_nb(), mca_oob_tcp_resolve(), mca_oob_tcp_set_addr(), mca_pml_bfo_error_pending_packets(), mca_pml_bfo_recv_frag_callback_match(), mca_pml_bfo_recv_frag_match(), mca_pml_bfo_recv_req_start(), mca_pml_bfo_send_request_restart(), mca_pml_bfo_start(), mca_pml_csum_recv_frag_callback_match(), mca_pml_csum_recv_frag_match(), mca_pml_csum_recv_req_start(), mca_pml_csum_start(), mca_pml_ob1_recv_frag_callback_match(), mca_pml_ob1_recv_frag_match(), mca_pml_ob1_recv_req_start(), mca_pml_ob1_start(), ompi_attr_copy_all(), ompi_attr_delete(), ompi_attr_delete_all(), ompi_attr_free_keyval(), ompi_proc_all(), ompi_proc_complete_init(), ompi_proc_find(), ompi_proc_pack(), ompi_proc_refresh(), ompi_proc_world(), ompi_request_wait_completion(), opal_output_close(), opal_pointer_array_add(), opal_pointer_array_get_item(), opal_pointer_array_remove_all(), opal_pointer_array_set_item(), opal_pointer_array_set_size(), opal_pointer_array_test_and_set_item(), opal_util_keyval_parse(), orte_odls_base_default_signal_local_procs(), orte_plm_submit_launch(), and recv_request_pml_complete().

#define opal_using_threads ( )    opal_uses_threads

Check and see if the process is using multiple threads.

Return values
trueIf the process may have more than one thread.
falseIf the process only has a single thread.

The value that this function returns is influenced by:

  • how MPI_INIT or MPI_INIT_THREAD was invoked,
  • what the final MPI thread level was determined to be,
  • whether the OMPI or MPI libraries are multi-threaded (Jan 2003: they're not),
  • whether configure determined if we have thread support or not

MPI_INIT and MPI_INIT_THREAD (specifically, back-end OMPI startup functions) invoke opal_set_using_threads() to influence the value of this function, depending on their situation. Some examples:

  • if configure determined that we do not have threads, then this value will always be false.
  • if MPI_INIT is invoked, and the ompi libraries are [still] single-threaded, this value will be false.
  • if MPI_INIT_THREAD is invoked with MPI_THREAD_MULTIPLE, we have thread support, and the final thread level is determined to be MPI_THREAD_MULTIPLE, this value will be true.
  • if the process is a single-threaded OMPI executable (e.g., mpicc), this value will be false.

Hence, this function will return false if there is guaranteed to only be one thread in the process. If there is even the possibility that we may have multiple threads, true will be returned.

Referenced by mca_btl_sm_component_progress(), and mca_btl_smcuda_component_progress().

Function Documentation

static void opal_mutex_atomic_lock ( opal_mutex_t mutex)
inlinestatic

Acquire a mutex using atomic operations.

Parameters
mutexAddress of the mutex.
static int opal_mutex_atomic_trylock ( opal_mutex_t mutex)
inlinestatic

Try to acquire a mutex using atomic operations.

Parameters
mutexAddress of the mutex.
Returns
0 if the mutex was acquired, 1 otherwise.
static void opal_mutex_atomic_unlock ( opal_mutex_t mutex)
inlinestatic

Release a mutex using atomic operations.

Parameters
mutexAddress of the mutex.
static void opal_mutex_lock ( opal_mutex_t mutex)
inlinestatic

Acquire a mutex.

Parameters
mutexAddress of the mutex.

Referenced by opal_cmd_line_get_ninsts(), opal_cmd_line_get_param(), opal_cmd_line_get_tail(), opal_cmd_line_get_usage_msg(), and opal_cmd_line_parse().

static int opal_mutex_trylock ( opal_mutex_t mutex)
inlinestatic

Try to acquire a mutex.

Parameters
mutexAddress of the mutex.
Returns
0 if the mutex was acquired, 1 otherwise.
static void opal_mutex_unlock ( opal_mutex_t mutex)
inlinestatic

Release a mutex.

Parameters
mutexAddress of the mutex.

Referenced by opal_cmd_line_get_ninsts(), opal_cmd_line_get_param(), opal_cmd_line_get_tail(), opal_cmd_line_get_usage_msg(), and opal_cmd_line_parse().

static bool opal_set_using_threads ( bool  have)
inlinestatic

Set whether the process is using multiple threads or not.

Parameters
haveBoolean indicating whether the process is using multiple threads or not.
Return values
opal_using_threadsThe new return value from opal_using_threads().

This function is used to influence the return value of opal_using_threads(). If configure detected that we have thread support, the return value of future invocations of opal_using_threads() will be the parameter's value. If configure detected that we have no thread support, then the retuen from opal_using_threads() will always be false.

Referenced by ompi_mpi_init().