2004-01-11 01:22:50 +03:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* 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.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-11 01:22:50 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-14 10:06:57 +03:00
|
|
|
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "threads/mutex.h"
|
2004-01-11 01:22:50 +03:00
|
|
|
|
2004-01-14 10:06:57 +03:00
|
|
|
/*
|
|
|
|
* Default to a safe value
|
|
|
|
*/
|
2005-02-16 20:42:07 +03:00
|
|
|
bool ompi_uses_threads = (bool) OMPI_HAVE_THREAD_SUPPORT;
|
2004-01-11 01:22:50 +03:00
|
|
|
|
2004-08-19 04:34:00 +04:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifdef WIN32
|
2004-08-19 04:34:00 +04:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
static void ompi_mutex_construct(ompi_mutex_t *m)
|
|
|
|
{
|
|
|
|
InterlockedExchange(&m->m_lock, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ompi_mutex_destruct(ompi_mutex_t *m)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static void ompi_mutex_construct(ompi_mutex_t *m)
|
|
|
|
{
|
|
|
|
#if OMPI_HAVE_POSIX_THREADS
|
2004-08-19 23:29:01 +04:00
|
|
|
pthread_mutex_init(&m->m_lock_pthread, 0);
|
2004-08-19 04:34:00 +04:00
|
|
|
#endif
|
2005-01-27 04:39:55 +03:00
|
|
|
#if OMPI_HAVE_ATOMIC_SPINLOCKS
|
2004-11-03 19:52:49 +03:00
|
|
|
ompi_atomic_init( &m->m_lock_atomic, OMPI_ATOMIC_UNLOCKED );
|
2004-08-19 04:34:00 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ompi_mutex_destruct(ompi_mutex_t *m)
|
|
|
|
{
|
|
|
|
#if OMPI_HAVE_POSIX_THREADS
|
2004-08-19 23:29:01 +04:00
|
|
|
pthread_mutex_destroy(&m->m_lock_pthread);
|
2004-08-19 04:34:00 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(ompi_mutex_t,
|
|
|
|
ompi_object_t,
|
|
|
|
ompi_mutex_construct,
|
|
|
|
ompi_mutex_destruct);
|