2003-12-22 19:29:21 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-08-23 04:29:35 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2007-06-12 20:25:26 +04:00
|
|
|
* Copyright (c) 2007 Cisco, Inc. All rights reserved.
|
|
|
|
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2007-08-01 16:13:34 +04:00
|
|
|
* Copyright (c) 2007 Voltaire. All rights reserved.
|
|
|
|
*
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-07 21:39:35 +03:00
|
|
|
* $HEADER$
|
2003-12-22 19:29:21 +03:00
|
|
|
*/
|
2004-01-07 21:39:35 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
#ifndef OPAL_MUTEX_H
|
|
|
|
#define OPAL_MUTEX_H 1
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal_config.h"
|
2008-02-19 03:39:48 +03:00
|
|
|
|
2008-03-08 15:53:10 +03:00
|
|
|
/*
|
|
|
|
* Circumentvent problems in C++ compilers.
|
|
|
|
* For C++, we should not need the file, anyhow.
|
|
|
|
*/
|
|
|
|
#if defined(HAVE_STDBOOL_H) && !(defined(c_plusplus) || defined(__cplusplus))
|
2008-02-19 03:39:48 +03:00
|
|
|
#include <stdbool.h>
|
|
|
|
#endif
|
|
|
|
|
2006-08-23 04:29:35 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal/sys/atomic.h"
|
2006-08-23 04:29:35 +04:00
|
|
|
#endif /* OMPI_HAVE_THREAD_SUPPORT */
|
2007-06-12 20:25:26 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
#include "opal/util/output.h"
|
2004-10-21 02:31:03 +04:00
|
|
|
#endif
|
2006-08-20 19:54:04 +04:00
|
|
|
|
2007-06-12 20:25:26 +04:00
|
|
|
BEGIN_C_DECLS
|
|
|
|
|
2004-08-19 03:24:27 +04:00
|
|
|
/**
|
|
|
|
* @file:
|
|
|
|
*
|
|
|
|
* Mutual exclusion functions.
|
|
|
|
*
|
|
|
|
* Functions for locking of critical sections.
|
|
|
|
*/
|
2007-06-12 20:25:26 +04:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
/*
|
|
|
|
* declaring this here so that CL does not complain
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC extern bool opal_uses_threads;
|
2004-08-19 03:24:27 +04:00
|
|
|
|
2007-06-12 20:25:26 +04:00
|
|
|
#if OMPI_ENABLE_DEBUG
|
|
|
|
OPAL_DECLSPEC extern bool opal_mutex_check_locks;
|
|
|
|
#endif
|
|
|
|
|
2004-08-19 03:24:27 +04:00
|
|
|
/**
|
|
|
|
* Opaque mutex object
|
|
|
|
*/
|
2005-07-04 02:45:48 +04:00
|
|
|
typedef struct opal_mutex_t opal_mutex_t;
|
2004-08-19 03:24:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to acquire a mutex.
|
|
|
|
*
|
|
|
|
* @param mutex Address of the mutex.
|
|
|
|
* @return 0 if the mutex was acquired, 1 otherwise.
|
|
|
|
*/
|
2005-07-04 02:45:48 +04:00
|
|
|
static inline int opal_mutex_trylock(opal_mutex_t *mutex);
|
2004-08-19 03:24:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Acquire a mutex.
|
|
|
|
*
|
|
|
|
* @param mutex Address of the mutex.
|
|
|
|
*/
|
2005-07-04 02:45:48 +04:00
|
|
|
static inline void opal_mutex_lock(opal_mutex_t *mutex);
|
2004-08-19 03:24:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release a mutex.
|
|
|
|
*
|
|
|
|
* @param mutex Address of the mutex.
|
|
|
|
*/
|
2005-07-04 02:45:48 +04:00
|
|
|
static inline void opal_mutex_unlock(opal_mutex_t *mutex);
|
2004-08-19 03:24:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to acquire a mutex using atomic operations.
|
|
|
|
*
|
|
|
|
* @param mutex Address of the mutex.
|
|
|
|
* @return 0 if the mutex was acquired, 1 otherwise.
|
|
|
|
*/
|
2005-07-04 02:45:48 +04:00
|
|
|
static inline int opal_mutex_atomic_trylock(opal_mutex_t *mutex);
|
2004-08-19 03:24:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Acquire a mutex using atomic operations.
|
|
|
|
*
|
|
|
|
* @param mutex Address of the mutex.
|
|
|
|
*/
|
2005-07-04 02:45:48 +04:00
|
|
|
static inline void opal_mutex_atomic_lock(opal_mutex_t *mutex);
|
2004-08-19 03:24:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release a mutex using atomic operations.
|
|
|
|
*
|
|
|
|
* @param mutex Address of the mutex.
|
|
|
|
*/
|
2005-07-04 02:45:48 +04:00
|
|
|
static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex);
|
2004-08-19 03:24:27 +04:00
|
|
|
|
2007-06-12 20:25:26 +04:00
|
|
|
END_C_DECLS
|
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
#include "mutex_windows.h"
|
|
|
|
#else
|
|
|
|
#include "mutex_unix.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BEGIN_C_DECLS
|
2004-08-19 03:24:27 +04:00
|
|
|
|
2004-01-14 02:32:19 +03:00
|
|
|
/**
|
|
|
|
* Check and see if the process is using multiple threads.
|
|
|
|
*
|
|
|
|
* @retval true If the process may have more than one thread.
|
|
|
|
* @retval false If the process only has a single thread.
|
|
|
|
*
|
|
|
|
* The value that this function returns is influenced by:
|
|
|
|
*
|
2004-08-19 03:24:27 +04:00
|
|
|
* - how MPI_INIT or MPI_INIT_THREAD was invoked,
|
2004-01-14 02:32:19 +03:00
|
|
|
* - what the final MPI thread level was determined to be,
|
2004-06-07 19:33:53 +04:00
|
|
|
* - whether the OMPI or MPI libraries are multi-threaded (Jan 2003:
|
2004-01-14 02:32:19 +03:00
|
|
|
* they're not),
|
|
|
|
* - whether configure determined if we have thread support or not
|
|
|
|
*
|
2004-06-07 19:33:53 +04:00
|
|
|
* MPI_INIT and MPI_INIT_THREAD (specifically, back-end OMPI startup
|
2005-07-04 02:45:48 +04:00
|
|
|
* functions) invoke opal_set_using_threads() to influence the value of
|
2004-01-14 02:32:19 +03:00
|
|
|
* this function, depending on their situation. Some examples:
|
|
|
|
*
|
|
|
|
* - if configure determined that we do not have threads, then this
|
|
|
|
* value will always be false.
|
|
|
|
*
|
2004-08-06 18:30:18 +04:00
|
|
|
* - if MPI_INIT is invoked, and the ompi libraries are [still]
|
2004-01-14 02:32:19 +03:00
|
|
|
* 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.
|
|
|
|
*
|
2004-06-07 19:33:53 +04:00
|
|
|
* - if the process is a single-threaded OMPI executable (e.g., mpicc),
|
2004-01-14 02:32:19 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
2007-04-12 08:29:43 +04:00
|
|
|
#define opal_using_threads() opal_uses_threads
|
2004-01-14 07:00:15 +03:00
|
|
|
|
2004-01-14 02:32:19 +03:00
|
|
|
/**
|
|
|
|
* Set whether the process is using multiple threads or not.
|
|
|
|
*
|
|
|
|
* @param have Boolean indicating whether the process is using
|
|
|
|
* multiple threads or not.
|
|
|
|
*
|
2005-07-04 02:45:48 +04:00
|
|
|
* @retval opal_using_threads The new return value from
|
|
|
|
* opal_using_threads().
|
2004-01-14 02:32:19 +03:00
|
|
|
*
|
|
|
|
* This function is used to influence the return value of
|
2005-07-04 02:45:48 +04:00
|
|
|
* opal_using_threads(). If configure detected that we have thread
|
2004-01-14 02:32:19 +03:00
|
|
|
* support, the return value of future invocations of
|
2005-07-04 02:45:48 +04:00
|
|
|
* opal_using_threads() will be the parameter's value. If configure
|
2004-01-14 02:32:19 +03:00
|
|
|
* detected that we have no thread support, then the retuen from
|
2005-07-04 02:45:48 +04:00
|
|
|
* opal_using_threads() will always be false.
|
2004-01-11 01:22:50 +03:00
|
|
|
*/
|
2005-07-04 02:45:48 +04:00
|
|
|
static inline bool opal_set_using_threads(bool have)
|
2004-08-19 03:24:27 +04:00
|
|
|
{
|
2005-02-16 20:42:07 +03:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_uses_threads = have;
|
2004-01-14 02:32:19 +03:00
|
|
|
#else
|
2007-01-30 09:34:38 +03:00
|
|
|
have = have; /* just shut up the compiler */
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_uses_threads = false;
|
2004-01-14 02:32:19 +03:00
|
|
|
#endif
|
2005-07-04 02:45:48 +04:00
|
|
|
return opal_uses_threads;
|
2004-01-14 02:32:19 +03:00
|
|
|
}
|
2004-01-11 01:22:50 +03:00
|
|
|
|
2004-08-19 03:24:27 +04:00
|
|
|
|
2004-01-14 02:32:19 +03:00
|
|
|
/**
|
2005-07-04 02:45:48 +04:00
|
|
|
* Lock a mutex if opal_using_threads() says that multiple threads may
|
2004-01-14 02:32:19 +03:00
|
|
|
* be active in the process.
|
|
|
|
*
|
2005-07-04 02:45:48 +04:00
|
|
|
* @param mutex Pointer to a opal_mutex_t to lock.
|
2004-01-14 02:32:19 +03:00
|
|
|
*
|
|
|
|
* If there is a possibility that multiple threads are running in the
|
2005-07-04 02:45:48 +04:00
|
|
|
* process (as determined by opal_using_threads()), this function will
|
2004-01-14 02:32:19 +03:00
|
|
|
* block waiting to lock the mutex.
|
|
|
|
*
|
|
|
|
* If there is no possibility that multiple threads are running in the
|
|
|
|
* process, return immediately.
|
|
|
|
*/
|
2005-04-20 00:50:44 +04:00
|
|
|
|
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_LOCK(mutex) \
|
2004-08-19 03:24:27 +04:00
|
|
|
do { \
|
2005-07-04 02:45:48 +04:00
|
|
|
if (opal_using_threads()) { \
|
|
|
|
opal_mutex_lock(mutex); \
|
2004-08-19 03:24:27 +04:00
|
|
|
} \
|
|
|
|
} while (0)
|
2007-06-12 20:25:26 +04:00
|
|
|
#elif OMPI_ENABLE_DEBUG
|
|
|
|
#define OPAL_THREAD_LOCK(mutex) \
|
|
|
|
do { \
|
|
|
|
(mutex)->m_lock_debug++; \
|
|
|
|
if (opal_mutex_check_locks && 1 != (mutex)->m_lock_debug) { \
|
|
|
|
opal_output(0, "Warning -- mutex already locked at %s:%d," \
|
|
|
|
" now at %s:%d", \
|
|
|
|
(mutex)->m_lock_file, \
|
|
|
|
(mutex)->m_lock_line, \
|
|
|
|
__FILE__, __LINE__); \
|
|
|
|
} \
|
|
|
|
(mutex)->m_lock_file = __FILE__; \
|
|
|
|
(mutex)->m_lock_line = __LINE__; \
|
|
|
|
} while (0)
|
2005-04-20 00:50:44 +04:00
|
|
|
#else
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_LOCK(mutex)
|
2005-04-20 00:50:44 +04:00
|
|
|
#endif
|
2004-01-11 01:22:50 +03:00
|
|
|
|
2007-06-12 20:25:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to lock a mutex if opal_using_threads() says that multiple
|
|
|
|
* threads may be active in the process.
|
|
|
|
*
|
|
|
|
* @param mutex Pointer 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.
|
|
|
|
*/
|
2006-01-23 21:35:40 +03:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2007-06-12 20:25:26 +04:00
|
|
|
#define OPAL_THREAD_TRYLOCK(mutex) (opal_using_threads() ? opal_mutex_trylock(mutex) : 0)
|
|
|
|
#elif OMPI_ENABLE_DEBUG
|
|
|
|
static inline int
|
2007-11-06 13:56:06 +03:00
|
|
|
opal_thread_debug_trylock(opal_mutex_t *mutex, const char *file, int line)
|
2007-06-12 20:25:26 +04:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (0 == (mutex)->m_lock_debug) {
|
|
|
|
(mutex)->m_lock_debug++;
|
|
|
|
(mutex)->m_lock_file = file;
|
|
|
|
(mutex)->m_lock_line = line;
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
if (opal_mutex_check_locks) {
|
|
|
|
opal_output(0, "Warning -- during trylock, mutex already locked at %s:%d "
|
|
|
|
"now at %s:%d",
|
|
|
|
file, line,
|
|
|
|
(mutex)->m_lock_file,
|
|
|
|
(mutex)->m_lock_line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#define OPAL_THREAD_TRYLOCK(mutex) opal_thread_debug_trylock(mutex, __FILE__, __LINE__)
|
2006-01-23 21:35:40 +03:00
|
|
|
#else
|
2007-06-12 20:25:26 +04:00
|
|
|
#define OPAL_THREAD_TRYLOCK(mutex) 0
|
2006-01-23 21:35:40 +03:00
|
|
|
#endif
|
|
|
|
|
2005-04-12 23:51:29 +04:00
|
|
|
|
|
|
|
/**
|
2005-07-04 02:45:48 +04:00
|
|
|
* Unlock a mutex if opal_using_threads() says that multiple threads
|
2004-01-14 02:32:19 +03:00
|
|
|
* may be active in the process.
|
|
|
|
*
|
2005-07-04 02:45:48 +04:00
|
|
|
* @param mutex Pointer to a opal_mutex_t to unlock.
|
2004-01-14 02:32:19 +03:00
|
|
|
*
|
|
|
|
* If there is a possibility that multiple threads are running in the
|
2005-07-04 02:45:48 +04:00
|
|
|
* process (as determined by opal_using_threads()), this function will
|
2004-01-14 02:32:19 +03:00
|
|
|
* unlock the mutex.
|
|
|
|
*
|
|
|
|
* If there is no possibility that multiple threads are running in the
|
|
|
|
* process, return immediately without modifying the mutex.
|
2004-01-11 01:22:50 +03:00
|
|
|
*/
|
2005-04-20 00:50:44 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_UNLOCK(mutex) \
|
2004-08-19 03:24:27 +04:00
|
|
|
do { \
|
2005-07-04 02:45:48 +04:00
|
|
|
if (opal_using_threads()) { \
|
|
|
|
opal_mutex_unlock(mutex); \
|
2004-08-19 03:24:27 +04:00
|
|
|
} \
|
|
|
|
} while (0)
|
2007-06-12 20:25:26 +04:00
|
|
|
#elif OMPI_ENABLE_DEBUG
|
|
|
|
#define OPAL_THREAD_UNLOCK(mutex) \
|
|
|
|
do { \
|
|
|
|
(mutex)->m_lock_debug--; \
|
|
|
|
if (opal_mutex_check_locks && 0 > (mutex)->m_lock_debug) { \
|
|
|
|
opal_output(0, "Warning -- mutex was double locked from %s:%d", \
|
|
|
|
__FILE__, __LINE__); \
|
|
|
|
} else if (opal_mutex_check_locks && 0 > (mutex)->m_lock_debug) { \
|
|
|
|
opal_output(0, "Warning -- mutex not locked from %s:%d", \
|
|
|
|
__FILE__, __LINE__); \
|
|
|
|
} else { \
|
|
|
|
(mutex)->m_lock_file = NULL; \
|
|
|
|
(mutex)->m_lock_line = 0; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2005-04-20 00:50:44 +04:00
|
|
|
#else
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_UNLOCK(mutex)
|
2005-04-20 00:50:44 +04:00
|
|
|
#endif
|
|
|
|
|
2004-08-19 03:24:27 +04:00
|
|
|
|
|
|
|
/**
|
2005-07-04 02:45:48 +04:00
|
|
|
* Lock a mutex if opal_using_threads() says that multiple threads may
|
2004-08-19 03:24:27 +04:00
|
|
|
* be active in the process for the duration of the specified action.
|
|
|
|
*
|
2005-07-04 02:45:48 +04:00
|
|
|
* @param mutex Pointer to a opal_mutex_t to lock.
|
2004-08-19 03:24:27 +04:00
|
|
|
* @param action A scope over which the lock is held.
|
|
|
|
*
|
|
|
|
* If there is a possibility that multiple threads are running in the
|
2005-07-04 02:45:48 +04:00
|
|
|
* process (as determined by opal_using_threads()), this function will
|
2004-08-19 03:24:27 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2005-04-20 00:50:44 +04:00
|
|
|
|
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \
|
2004-08-19 03:24:27 +04:00
|
|
|
do { \
|
2005-07-04 02:45:48 +04:00
|
|
|
if(opal_using_threads()) { \
|
|
|
|
opal_mutex_lock(mutex); \
|
2004-08-19 03:24:27 +04:00
|
|
|
(action); \
|
2005-07-04 02:45:48 +04:00
|
|
|
opal_mutex_unlock(mutex); \
|
2004-08-19 03:24:27 +04:00
|
|
|
} else { \
|
|
|
|
(action); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2007-06-12 20:25:26 +04:00
|
|
|
#elif OMPI_ENABLE_DEBUG
|
|
|
|
#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \
|
|
|
|
do { \
|
|
|
|
if (0 != (mutex)->m_lock_debug) { \
|
|
|
|
opal_output(0, "scoped_lock: Warning -- mutex already " \
|
|
|
|
"locked at %s:%d, now at %s:%d", \
|
|
|
|
__FILE__, __LINE__, \
|
|
|
|
(mutex)->m_lock_file, \
|
|
|
|
(mutex)->m_lock_line); \
|
|
|
|
} \
|
|
|
|
(mutex)->m_lock_debug--; \
|
|
|
|
(action); \
|
|
|
|
(mutex)->m_lock_debug++; \
|
|
|
|
} while (0)
|
2005-04-20 00:50:44 +04:00
|
|
|
#else
|
2007-06-12 20:25:26 +04:00
|
|
|
#define OPAL_THREAD_SCOPED_LOCK(mutex, action) (action)
|
2005-04-20 00:50:44 +04:00
|
|
|
#endif
|
2004-08-19 03:24:27 +04:00
|
|
|
|
2004-11-11 18:41:07 +03:00
|
|
|
/**
|
2005-07-04 02:45:48 +04:00
|
|
|
* Use an atomic operation for increment/decrement if opal_using_threads()
|
2004-11-11 18:41:07 +03:00
|
|
|
* indicates that threads are in use by the application or library.
|
|
|
|
*/
|
|
|
|
|
2005-04-20 00:50:44 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_ADD32(x,y) \
|
2007-06-12 20:25:26 +04:00
|
|
|
(opal_using_threads() ? opal_atomic_add_32(x,y) : (*x += y))
|
2005-04-20 00:50:44 +04:00
|
|
|
#else
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_ADD32(x,y) (*x += y)
|
2005-04-20 00:50:44 +04:00
|
|
|
#endif
|
2004-11-11 18:41:07 +03:00
|
|
|
|
2005-04-20 00:50:44 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_ADD64(x,y) \
|
2007-06-12 20:25:26 +04:00
|
|
|
(opal_using_threads() ? opal_atomic_add_64(x,y) : (*x += y))
|
2005-04-20 00:50:44 +04:00
|
|
|
#else
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_ADD64(x,y) (*x += y)
|
2005-04-20 00:50:44 +04:00
|
|
|
#endif
|
|
|
|
|
2005-06-29 00:15:01 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_ADD_SIZE_T(x,y) \
|
2007-06-12 20:25:26 +04:00
|
|
|
(opal_using_threads() ? opal_atomic_add_size_t(x,y) : (*x += y))
|
2005-06-29 00:15:01 +04:00
|
|
|
#else
|
2005-07-04 02:45:48 +04:00
|
|
|
#define OPAL_THREAD_ADD_SIZE_T(x,y) (*x += y)
|
2005-06-29 00:15:01 +04:00
|
|
|
#endif
|
|
|
|
|
2007-09-09 12:00:16 +04:00
|
|
|
#define OPAL_CMPSET(x, y, z) ((*(x) == (y)) ? ((*(x) = (z)), 1) : 0)
|
|
|
|
|
2007-08-01 16:13:34 +04:00
|
|
|
#if OMPI_HAVE_THREAD_SUPPORT
|
|
|
|
# if OPAL_HAVE_ATOMIC_CMPSET_32
|
|
|
|
# define OPAL_ATOMIC_CMPSET_32(x, y, z) \
|
2007-09-09 12:00:16 +04:00
|
|
|
(opal_using_threads() ? opal_atomic_cmpset_32(x, y, z) : OPAL_CMPSET(x, y, z))
|
2007-08-01 16:13:34 +04:00
|
|
|
# endif
|
|
|
|
# if OPAL_HAVE_ATOMIC_CMPSET_64
|
|
|
|
# define OPAL_ATOMIC_CMPSET_64(x, y, z) \
|
2007-09-09 12:00:16 +04:00
|
|
|
(opal_using_threads() ? opal_atomic_cmpset_64(x, y, z) : OPAL_CMPSET(x, y, z))
|
2007-08-01 16:13:34 +04:00
|
|
|
# endif
|
|
|
|
# if OPAL_HAVE_ATOMIC_CMPSET_32 || OPAL_HAVE_ATOMIC_CMPSET_64
|
|
|
|
# define OPAL_ATOMIC_CMPSET(x, y, z) \
|
2007-09-09 12:00:16 +04:00
|
|
|
(opal_using_threads() ? opal_atomic_cmpset(x, y, z) : OPAL_CMPSET(x, y, z))
|
2007-08-01 16:13:34 +04:00
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# if OPAL_HAVE_ATOMIC_CMPSET_32
|
2007-09-09 12:00:16 +04:00
|
|
|
# define OPAL_ATOMIC_CMPSET_32(x, y, z) OPAL_CMPSET(x, y, z)
|
2007-08-01 16:13:34 +04:00
|
|
|
# endif
|
|
|
|
# if OPAL_HAVE_ATOMIC_CMPSET_64
|
2007-09-09 12:00:16 +04:00
|
|
|
# define OPAL_ATOMIC_CMPSET_64(x, y, z) OPAL_CMPSET(x, y, z)
|
2007-08-01 16:13:34 +04:00
|
|
|
# endif
|
|
|
|
# if OPAL_HAVE_ATOMIC_CMPSET_32 || OPAL_HAVE_ATOMIC_CMPSET_64
|
2007-09-09 12:00:16 +04:00
|
|
|
# define OPAL_ATOMIC_CMPSET(x, y, z) OPAL_CMPSET(x, y, z)
|
2007-08-01 16:13:34 +04:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2007-06-12 20:25:26 +04:00
|
|
|
END_C_DECLS
|
2003-12-22 19:29:21 +03:00
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
#endif /* OPAL_MUTEX_H */
|