Add the potential for doing some basic error checking on mutexes during
single threaded builds. In its default configuration, all this does is ensure that there's at least a good chance of threads building based on non-threaded development (since the variable names will be checked). There is also code to make sure that a "mutex" is never "double locked" when using the conditional macro mutex operations. This is off by default because there are a number of places in both ORTE and OMPI where this alarm spews mega bytes of errors on a simple test. So we have some work to do on our path towards thread support. Also removed the macro versions of the non-conditional thread locks, as the only places they were used, the author of the code intended to use the conditional thread locks. So now you have upper-case macros for conditional thread locks and lowercase functions for non-conditional locks. Simple, right? :). This commit was SVN r15011.
Этот коммит содержится в:
родитель
4e8081ed1e
Коммит
84d1512fba
@ -406,7 +406,6 @@ static opal_hash_table_t *keyval_hash;
|
||||
static ompi_bitmap_t *key_bitmap;
|
||||
static unsigned int int_pos = 12345;
|
||||
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
/*
|
||||
* Have one lock protect all access to any attribute stuff (keyval
|
||||
* hash, key bitmap, attribute hashes on MPI objects, etc.).
|
||||
@ -416,7 +415,6 @@ static unsigned int int_pos = 12345;
|
||||
* So why bother?
|
||||
*/
|
||||
static opal_mutex_t alock;
|
||||
#endif /* OMPI_HAVE_THREAD_SUPPORT */
|
||||
|
||||
|
||||
/*
|
||||
@ -498,9 +496,7 @@ int ompi_attr_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
OBJ_CONSTRUCT(&alock, opal_mutex_t);
|
||||
#endif
|
||||
|
||||
if (OMPI_SUCCESS != (ret = opal_hash_table_init(keyval_hash,
|
||||
ATTR_TABLE_SIZE))) {
|
||||
|
@ -10,6 +10,7 @@
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2006 University of Houston. All rights reserved.
|
||||
* Copyright (c) 2007 Cisco, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -103,9 +104,7 @@ OBJ_CLASS_INSTANCE (ompi_comm_reg_t,
|
||||
ompi_comm_reg_constructor,
|
||||
ompi_comm_reg_destructor );
|
||||
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
static opal_mutex_t ompi_cid_lock;
|
||||
#endif /* OMPI_HAVE_THREAD_SUPPORT */
|
||||
static opal_list_t ompi_registered_comms;
|
||||
|
||||
int ompi_comm_nextcid ( ompi_communicator_t* newcomm,
|
||||
|
@ -9,6 +9,7 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Cisco, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -31,9 +32,7 @@
|
||||
#include "orte/mca/gpr/gpr.h"
|
||||
#include "orte/mca/rml/rml_types.h"
|
||||
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
static opal_mutex_t ompi_port_lock;
|
||||
#endif /* OMPI_HAVE_THREAD_SUPPORT */
|
||||
|
||||
#define OMPI_COMM_PORT_KEY "ompi-port-name"
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Cisco, Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -28,9 +29,7 @@
|
||||
*/
|
||||
static bool initialized = false;
|
||||
static opal_list_t components_in_use;
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
static opal_mutex_t mutex;
|
||||
#endif /* OMPI_HAVE_THREAD_SUPPORT */
|
||||
|
||||
struct component_item_t {
|
||||
opal_list_item_t super;
|
||||
|
@ -9,7 +9,7 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2006 Los Alamos National Security, LLC. All rights
|
||||
* Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
@ -443,19 +443,19 @@ mca_pml_base_modex_subscribe(orte_process_name_t * name)
|
||||
};
|
||||
|
||||
/* check for an existing subscription */
|
||||
OPAL_LOCK(&mca_pml_base_modex_lock);
|
||||
OPAL_THREAD_LOCK(&mca_pml_base_modex_lock);
|
||||
if (!opal_list_is_empty(&mca_pml_base_modex_subscriptions)) {
|
||||
for (item = opal_list_get_first(&mca_pml_base_modex_subscriptions);
|
||||
item != opal_list_get_end(&mca_pml_base_modex_subscriptions);
|
||||
item = opal_list_get_next(item)) {
|
||||
subscription = (mca_pml_base_modex_subscription_t *) item;
|
||||
if (subscription->jobid == name->jobid) {
|
||||
OPAL_UNLOCK(&mca_pml_base_modex_lock);
|
||||
OPAL_THREAD_UNLOCK(&mca_pml_base_modex_lock);
|
||||
return OMPI_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
OPAL_UNLOCK(&mca_pml_base_modex_lock);
|
||||
OPAL_THREAD_UNLOCK(&mca_pml_base_modex_lock);
|
||||
|
||||
/* otherwise - subscribe to get this jobid's contact info */
|
||||
jobid = name->jobid;
|
||||
@ -521,11 +521,11 @@ mca_pml_base_modex_subscribe(orte_process_name_t * name)
|
||||
free(segment);
|
||||
|
||||
/* add this jobid to our list of subscriptions */
|
||||
OPAL_LOCK(&mca_pml_base_modex_lock);
|
||||
OPAL_THREAD_LOCK(&mca_pml_base_modex_lock);
|
||||
subscription = OBJ_NEW(mca_pml_base_modex_subscription_t);
|
||||
subscription->jobid = name->jobid;
|
||||
opal_list_append(&mca_pml_base_modex_subscriptions, &subscription->item);
|
||||
OPAL_UNLOCK(&mca_pml_base_modex_lock);
|
||||
OPAL_THREAD_UNLOCK(&mca_pml_base_modex_lock);
|
||||
return OMPI_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -102,10 +104,16 @@ int mca_pml_ob1_recv(void *addr,
|
||||
ompi_request_waiting--;
|
||||
opal_mutex_unlock(&ompi_request_lock);
|
||||
} else {
|
||||
#if OMPI_ENABLE_DEBUG && !OMPI_HAVE_THREAD_SUPPORT
|
||||
OPAL_THREAD_LOCK(&ompi_request_lock);
|
||||
#endif
|
||||
ompi_request_waiting++;
|
||||
while (recvreq->req_recv.req_base.req_ompi.req_complete == false)
|
||||
opal_condition_wait(&ompi_request_cond, &ompi_request_lock);
|
||||
ompi_request_waiting--;
|
||||
#if OMPI_ENABLE_DEBUG && !OMPI_HAVE_THREAD_SUPPORT
|
||||
OPAL_THREAD_UNLOCK(&ompi_request_lock);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -123,10 +125,16 @@ int mca_pml_ob1_send(void *buf,
|
||||
ompi_request_waiting--;
|
||||
opal_mutex_unlock(&ompi_request_lock);
|
||||
} else {
|
||||
#if OMPI_ENABLE_DEBUG && !OMPI_HAVE_THREAD_SUPPORT
|
||||
OPAL_THREAD_LOCK(&ompi_request_lock);
|
||||
#endif
|
||||
ompi_request_waiting++;
|
||||
while (sendreq->req_send.req_base.req_ompi.req_complete == false)
|
||||
opal_condition_wait(&ompi_request_cond, &ompi_request_lock);
|
||||
ompi_request_waiting--;
|
||||
#if OMPI_ENABLE_DEBUG && !OMPI_HAVE_THREAD_SUPPORT
|
||||
OPAL_THREAD_UNLOCK(&ompi_request_lock);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "opal/util/output.h"
|
||||
#include "opal/util/show_help.h"
|
||||
#include "opal/mca/base/mca_base_param.h"
|
||||
#include "opal/threads/mutex.h"
|
||||
|
||||
int opal_register_params(void)
|
||||
{
|
||||
@ -75,9 +76,21 @@ int opal_register_params(void)
|
||||
}
|
||||
|
||||
#if OMPI_ENABLE_DEBUG
|
||||
|
||||
|
||||
mca_base_param_reg_int_name("opal", "progress_debug",
|
||||
"Set to non-zero to debug progress engine features",
|
||||
false, false, 0, NULL);
|
||||
|
||||
{
|
||||
int value;
|
||||
mca_base_param_reg_int_name("opal", "debug_locks",
|
||||
"Debug mutex usage within Open MPI. On a "
|
||||
"non-threaded build, this enables integer counters and "
|
||||
"warning messages when double-locks are detected.",
|
||||
false, false, 0, &value);
|
||||
if (value) opal_mutex_check_locks = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OPAL_SUCCESS;
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -35,9 +37,7 @@
|
||||
|
||||
#include "opal/runtime/opal_cr.h"
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
BEGIN_C_DECLS
|
||||
|
||||
/*
|
||||
* Combine pthread support w/ polled progress to allow run-time selection
|
||||
@ -61,6 +61,14 @@ static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m)
|
||||
{
|
||||
int rc = 0;
|
||||
c->c_waiting++;
|
||||
|
||||
#if OMPI_ENABLE_DEBUG && !OMPI_HAVE_THREAD_SUPPORT
|
||||
if (1 != m->m_lock_debug) { \
|
||||
opal_output(0, "Warning -- mutex not locked in condition_wait"); \
|
||||
} \
|
||||
m->m_lock_debug--;
|
||||
#endif
|
||||
|
||||
if (opal_using_threads()) {
|
||||
#if OMPI_HAVE_POSIX_THREADS && OMPI_ENABLE_PROGRESS_THREADS
|
||||
rc = pthread_cond_wait(&c->c_cond, &m->m_lock_pthread);
|
||||
@ -84,6 +92,11 @@ static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m)
|
||||
OPAL_CR_TEST_CHECKPOINT_READY_STALL();
|
||||
}
|
||||
}
|
||||
|
||||
#if OMPI_ENABLE_DEBUG && !OMPI_HAVE_THREAD_SUPPORT
|
||||
m->m_lock_debug++;
|
||||
#endif
|
||||
|
||||
c->c_signaled--;
|
||||
c->c_waiting--;
|
||||
return rc;
|
||||
@ -97,6 +110,13 @@ static inline int opal_condition_timedwait(opal_condition_t *c,
|
||||
struct timeval absolute;
|
||||
int rc = 0;
|
||||
|
||||
#if OMPI_ENABLE_DEBUG && !OMPI_HAVE_THREAD_SUPPORT
|
||||
if (1 != m->m_lock_debug) { \
|
||||
opal_output(0, "Warning -- mutex not locked in condition_wait"); \
|
||||
} \
|
||||
m->m_lock_debug--;
|
||||
#endif
|
||||
|
||||
c->c_waiting++;
|
||||
if (opal_using_threads()) {
|
||||
#if OMPI_HAVE_POSIX_THREADS && OMPI_ENABLE_PROGRESS_THREADS
|
||||
@ -125,6 +145,11 @@ static inline int opal_condition_timedwait(opal_condition_t *c,
|
||||
gettimeofday(&tv,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#if OMPI_ENABLE_DEBUG && !OMPI_HAVE_THREAD_SUPPORT
|
||||
m->m_lock_debug++;
|
||||
#endif
|
||||
|
||||
c->c_signaled--;
|
||||
c->c_waiting--;
|
||||
return rc;
|
||||
@ -160,8 +185,7 @@ static inline int opal_condition_broadcast(opal_condition_t *c)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
END_C_DECLS
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -25,6 +27,7 @@
|
||||
* Otherwise, wait and see if some upper layer wants to use threads.
|
||||
*/
|
||||
bool opal_uses_threads = (bool) OMPI_ENABLE_PROGRESS_THREADS;
|
||||
bool opal_mutex_check_locks = false;
|
||||
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
@ -34,6 +37,11 @@ bool opal_uses_threads = (bool) OMPI_ENABLE_PROGRESS_THREADS;
|
||||
static void opal_mutex_construct(opal_mutex_t *m)
|
||||
{
|
||||
InterlockedExchange(&m->m_lock, 0);
|
||||
#if OMPI_ENABLE_DEBUG
|
||||
m->m_lock_debug = 0;
|
||||
m->m_lock_file = NULL;
|
||||
m->m_lock_line = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void opal_mutex_destruct(opal_mutex_t *m)
|
||||
@ -67,12 +75,16 @@ static void opal_mutex_construct(opal_mutex_t *m)
|
||||
|
||||
#endif /* OMPI_ENABLE_DEBUG */
|
||||
|
||||
#endif /* OMPI_HAVE_POSIX_THREADS */
|
||||
|
||||
#if OMPI_HAVE_SOLARIS_THREADS
|
||||
#elif OMPI_HAVE_SOLARIS_THREADS
|
||||
mutex_init(&m->m_lock_solaris, USYNC_THREAD, NULL);
|
||||
#endif
|
||||
|
||||
#if OMPI_ENABLE_DEBUG
|
||||
m->m_lock_debug = 0;
|
||||
m->m_lock_file = NULL;
|
||||
m->m_lock_line = 0;
|
||||
#endif
|
||||
|
||||
#if OPAL_HAVE_ATOMIC_SPINLOCKS
|
||||
opal_atomic_init( &m->m_lock_atomic, OPAL_ATOMIC_UNLOCKED );
|
||||
#endif
|
||||
@ -82,6 +94,8 @@ static void opal_mutex_destruct(opal_mutex_t *m)
|
||||
{
|
||||
#if OMPI_HAVE_POSIX_THREADS
|
||||
pthread_mutex_destroy(&m->m_lock_pthread);
|
||||
#elif OMPI_HAVE_SOLARIS_THREADS
|
||||
mutex_destory(&m->m_lock_solaris);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,9 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Cisco, Inc. All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -23,11 +26,12 @@
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
#include "opal/sys/atomic.h"
|
||||
#endif /* OMPI_HAVE_THREAD_SUPPORT */
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if OMPI_ENABLE_DEBUG
|
||||
#include "opal/util/output.h"
|
||||
#endif
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* @file:
|
||||
*
|
||||
@ -35,11 +39,16 @@ extern "C" {
|
||||
*
|
||||
* Functions for locking of critical sections.
|
||||
*/
|
||||
|
||||
/*
|
||||
* declaring this here so that CL does not complain
|
||||
*/
|
||||
OPAL_DECLSPEC extern bool opal_uses_threads;
|
||||
|
||||
#if OMPI_ENABLE_DEBUG
|
||||
OPAL_DECLSPEC extern bool opal_mutex_check_locks;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Opaque mutex object
|
||||
*/
|
||||
@ -95,6 +104,15 @@ static inline void opal_mutex_atomic_lock(opal_mutex_t *mutex);
|
||||
*/
|
||||
static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include "mutex_windows.h"
|
||||
#else
|
||||
#include "mutex_unix.h"
|
||||
#endif
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
/**
|
||||
* Check and see if the process is using multiple threads.
|
||||
@ -183,14 +201,68 @@ static inline bool opal_set_using_threads(bool have)
|
||||
opal_mutex_lock(mutex); \
|
||||
} \
|
||||
} while (0)
|
||||
#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)
|
||||
#else
|
||||
#define OPAL_THREAD_LOCK(mutex)
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
#define OPAL_THREAD_TRYLOCK(mutex) (opal_using_threads() ? opal_mutex_trylock(mutex) : 0)
|
||||
#define OPAL_THREAD_TRYLOCK(mutex) (opal_using_threads() ? opal_mutex_trylock(mutex) : 0)
|
||||
#elif OMPI_ENABLE_DEBUG
|
||||
static inline int
|
||||
opal_thread_debug_trylock(opal_mutex_t *mutex, char *file, int line)
|
||||
{
|
||||
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__)
|
||||
#else
|
||||
#define OPAL_THREAD_TRYLOCK(mutex) 0
|
||||
#define OPAL_THREAD_TRYLOCK(mutex) 0
|
||||
#endif
|
||||
|
||||
|
||||
@ -207,7 +279,6 @@ static inline bool opal_set_using_threads(bool have)
|
||||
* If there is no possibility that multiple threads are running in the
|
||||
* process, return immediately without modifying the mutex.
|
||||
*/
|
||||
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
#define OPAL_THREAD_UNLOCK(mutex) \
|
||||
do { \
|
||||
@ -215,6 +286,21 @@ static inline bool opal_set_using_threads(bool have)
|
||||
opal_mutex_unlock(mutex); \
|
||||
} \
|
||||
} while (0)
|
||||
#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)
|
||||
#else
|
||||
#define OPAL_THREAD_UNLOCK(mutex)
|
||||
#endif
|
||||
@ -247,8 +333,22 @@ static inline bool opal_set_using_threads(bool have)
|
||||
(action); \
|
||||
} \
|
||||
} while (0)
|
||||
#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)
|
||||
#else
|
||||
#define OPAL_THREAD_SCOPED_LOCK(mutex,action) (action)
|
||||
#define OPAL_THREAD_SCOPED_LOCK(mutex, action) (action)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -258,79 +358,25 @@ static inline bool opal_set_using_threads(bool have)
|
||||
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
#define OPAL_THREAD_ADD32(x,y) \
|
||||
((OMPI_HAVE_THREAD_SUPPORT && opal_using_threads()) ? \
|
||||
opal_atomic_add_32(x,y) : (*x += y))
|
||||
(opal_using_threads() ? opal_atomic_add_32(x,y) : (*x += y))
|
||||
#else
|
||||
#define OPAL_THREAD_ADD32(x,y) (*x += y)
|
||||
#endif
|
||||
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
#define OPAL_THREAD_ADD64(x,y) \
|
||||
((OMPI_HAVE_THREAD_SUPPORT && opal_using_threads()) ? \
|
||||
opal_atomic_add_64(x,y) : (*x += y))
|
||||
(opal_using_threads() ? opal_atomic_add_64(x,y) : (*x += y))
|
||||
#else
|
||||
#define OPAL_THREAD_ADD64(x,y) (*x += y)
|
||||
#endif
|
||||
|
||||
#if OMPI_HAVE_THREAD_SUPPORT
|
||||
#define OPAL_THREAD_ADD_SIZE_T(x,y) \
|
||||
((OMPI_HAVE_THREAD_SUPPORT && opal_using_threads()) ? \
|
||||
opal_atomic_add_size_t(x,y) : (*x += y))
|
||||
(opal_using_threads() ? opal_atomic_add_size_t(x,y) : (*x += y))
|
||||
#else
|
||||
#define OPAL_THREAD_ADD_SIZE_T(x,y) (*x += y)
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Always locks a mutex (never compile- or run-time removed)
|
||||
*
|
||||
* @param mutex A pointer to a opal_mutex_t.
|
||||
*
|
||||
* Locks the mutex. This is the macro that you should use for mutexes
|
||||
* that should always be locked, regardless of whether the process has
|
||||
* multiple threads or not. This is useful, for example, with shared
|
||||
* memory.
|
||||
*/
|
||||
#define OPAL_LOCK(mutex) opal_mutex_atomic_lock(mutex)
|
||||
|
||||
/**
|
||||
* Always unlocks a mutex (never compile- or run-time removed)
|
||||
*
|
||||
* @param mutex A pointer to a opal_mutex_t.
|
||||
*
|
||||
* Unlocks the mutex. This is the macro that you should use for
|
||||
* mutexes that should always be unlocked, regardless of whether the
|
||||
* process has multiple threads or not. This is useful, for example,
|
||||
* with shared memory.
|
||||
*/
|
||||
#define OPAL_UNLOCK(mutex) opal_mutex_atomic_unlock(mutex)
|
||||
|
||||
|
||||
/**
|
||||
* Lock a mutex for the duration of the specified action.
|
||||
*
|
||||
* @param mutex Pointer to a opal_mutex_t to lock.
|
||||
* @param action A scope over which the lock is held.
|
||||
*
|
||||
* This is the macro that you should use for mutexes that should
|
||||
* always be locked, regardless of whether the process has multiple
|
||||
* threads or not. This is useful, for example, with shared memory.
|
||||
*/
|
||||
#define OPAL_SCOPED_LOCK(mutex, action) \
|
||||
do { \
|
||||
opal_mutex_lock(mutex); \
|
||||
(action); \
|
||||
opal_mutex_unlock(mutex); \
|
||||
} while (0)
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include "mutex_windows.h"
|
||||
#else
|
||||
#include "mutex_unix.h"
|
||||
#endif
|
||||
END_C_DECLS
|
||||
|
||||
#endif /* OPAL_MUTEX_H */
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -37,8 +39,7 @@
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#if OMPI_HAVE_SOLARIS_THREADS
|
||||
#elif OMPI_HAVE_SOLARIS_THREADS
|
||||
#include <thread.h>
|
||||
#include <synch.h>
|
||||
#endif
|
||||
@ -46,20 +47,25 @@
|
||||
#include "opal/class/opal_object.h"
|
||||
#include "opal/sys/atomic.h"
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
BEGIN_C_DECLS
|
||||
|
||||
struct opal_mutex_t {
|
||||
opal_object_t super;
|
||||
|
||||
#if OMPI_HAVE_POSIX_THREADS
|
||||
pthread_mutex_t m_lock_pthread;
|
||||
#endif
|
||||
#if OMPI_HAVE_SOLARIS_THREADS
|
||||
#elif OMPI_HAVE_SOLARIS_THREADS
|
||||
mutex_t m_lock_solaris;
|
||||
#endif
|
||||
|
||||
#if !OMPI_HAVE_THREAD_SUPPORT && OMPI_ENABLE_DEBUG
|
||||
int m_lock_debug;
|
||||
char *m_lock_file;
|
||||
int m_lock_line;
|
||||
#endif
|
||||
|
||||
opal_atomic_lock_t m_lock_atomic;
|
||||
};
|
||||
|
||||
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
|
||||
|
||||
/************************************************************************
|
||||
@ -217,7 +223,6 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
END_C_DECLS
|
||||
|
||||
#endif /* OPAL_MUTEX_UNIX_H */
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -32,12 +34,17 @@
|
||||
#include "opal/class/opal_object.h"
|
||||
#include "opal/sys/atomic.h"
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
BEGIN_C_DECLS
|
||||
|
||||
struct opal_mutex_t {
|
||||
opal_object_t super;
|
||||
volatile LONG m_lock;
|
||||
|
||||
#if !OMPI_HAVE_THREAD_SUPPORT && OMPI_ENABLE_DEBUG
|
||||
int m_lock_debug;
|
||||
char *m_lock_file;
|
||||
int m_lock_line;
|
||||
#endif
|
||||
};
|
||||
|
||||
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
|
||||
@ -82,8 +89,6 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
|
||||
opal_mutex_unlock(m);
|
||||
}
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
END_C_DECLS
|
||||
|
||||
#endif /* OPAL_MUTEX_WINDOWS_H */
|
||||
|
@ -111,9 +111,9 @@ int orte_gpr_proxy_exec_compound_cmd(void)
|
||||
ORTE_NAME_ARGS(orte_process_info.my_name));
|
||||
}
|
||||
|
||||
OPAL_THREAD_LOCK(&orte_gpr_proxy_globals.wait_for_compound_mutex);
|
||||
rc = ORTE_SUCCESS;
|
||||
|
||||
OPAL_THREAD_LOCK(&orte_gpr_proxy_globals.wait_for_compound_mutex);
|
||||
if (0 > orte_rml.send_buffer(orte_process_info.gpr_replica, orte_gpr_proxy_globals.compound_cmd, ORTE_RML_TAG_GPR, 0)) {
|
||||
ORTE_ERROR_LOG(ORTE_ERR_COMM_FAILURE);
|
||||
rc = ORTE_ERR_COMM_FAILURE;
|
||||
|
@ -1123,6 +1123,7 @@ int mca_oob_tcp_resolve(mca_oob_tcp_peer_t* peer)
|
||||
mca_oob_tcp_peer_resolved(peer, addr);
|
||||
return ORTE_SUCCESS;
|
||||
}
|
||||
OPAL_THREAD_UNLOCK(&mca_oob_tcp_component.tcp_lock);
|
||||
|
||||
/* if we don't know it, then report unknown - don't try to go get it */
|
||||
return ORTE_ERR_ADDRESSEE_UNKNOWN;
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -313,7 +315,7 @@ static int orte_rds_hostfile_parse(const char *hostfile, opal_list_t* existing,
|
||||
int token;
|
||||
int rc = ORTE_SUCCESS;
|
||||
|
||||
OPAL_LOCK(&mca_rds_hostfile_component.lock);
|
||||
OPAL_THREAD_LOCK(&mca_rds_hostfile_component.lock);
|
||||
|
||||
cur_hostfile_name = strdup(hostfile);
|
||||
|
||||
@ -366,7 +368,7 @@ unlock:
|
||||
cur_hostfile_name = NULL;
|
||||
}
|
||||
|
||||
OPAL_UNLOCK(&mca_rds_hostfile_component.lock);
|
||||
OPAL_THREAD_UNLOCK(&mca_rds_hostfile_component.lock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -236,7 +238,7 @@ int orte_rds_resfile_query(orte_jobid_t job)
|
||||
return ORTE_SUCCESS;
|
||||
}
|
||||
|
||||
OPAL_LOCK(&mca_rds_resfile_component.lock);
|
||||
OPAL_THREAD_LOCK(&mca_rds_resfile_component.lock);
|
||||
|
||||
orte_rds_resfile_queried = true;
|
||||
|
||||
@ -246,7 +248,7 @@ int orte_rds_resfile_query(orte_jobid_t job)
|
||||
|
||||
if (NULL == mca_rds_resfile_component.filename) { /* no resource file provided */
|
||||
/* DO NOT ORTE_ERROR_LOG OR RETURN AN ERROR - THIS IS NOT AN ERROR CONDITION */
|
||||
OPAL_UNLOCK(&mca_rds_resfile_component.lock);
|
||||
OPAL_THREAD_UNLOCK(&mca_rds_resfile_component.lock);
|
||||
return ORTE_SUCCESS;
|
||||
}
|
||||
|
||||
@ -254,7 +256,7 @@ int orte_rds_resfile_query(orte_jobid_t job)
|
||||
fp = fopen(mca_rds_resfile_component.filename, "r");
|
||||
if (NULL == fp) {
|
||||
ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND);
|
||||
OPAL_UNLOCK(&mca_rds_resfile_component.lock);
|
||||
OPAL_THREAD_UNLOCK(&mca_rds_resfile_component.lock);
|
||||
return ORTE_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
@ -299,7 +301,7 @@ CLEANUP:
|
||||
fclose(fp);
|
||||
OBJ_DESTRUCT(&orte_rds_resfile_resource_list);
|
||||
|
||||
OPAL_UNLOCK(&mca_rds_resfile_component.lock);
|
||||
OPAL_THREAD_UNLOCK(&mca_rds_resfile_component.lock);
|
||||
|
||||
return ORTE_SUCCESS;
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2007 Los Alamos National Security, LLC. All rights
|
||||
* reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
@ -508,7 +510,10 @@ trigger_callback(registered_cb_item_t *cb, pending_pids_item_t *pending)
|
||||
{
|
||||
assert(cb->pid == pending->pid);
|
||||
|
||||
OPAL_THREAD_UNLOCK(&mutex);
|
||||
cb->callback(cb->pid, pending->status, cb->data);
|
||||
OPAL_THREAD_LOCK(&mutex);
|
||||
|
||||
opal_list_remove_item(&pending_pids, (opal_list_item_t*) pending);
|
||||
opal_list_remove_item(®istered_cb, (opal_list_item_t*) cb);
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user