root/opal/threads/mutex.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. opal_mutex_construct
  2. opal_mutex_destruct
  3. opal_recursive_mutex_construct

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2007-2016 Los Alamos National Security, LLC.  All rights
  14  *                         reserved.
  15  * Copyright (c) 2015      Research Organization for Information Science
  16  *                         and Technology (RIST). All rights reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 #include "opal_config.h"
  25 
  26 #include "opal/threads/mutex.h"
  27 
  28 /*
  29  * Wait and see if some upper layer wants to use threads, if support
  30  * exists.
  31  */
  32 bool opal_uses_threads = false;
  33 
  34 static void opal_mutex_construct(opal_mutex_t *m)
  35 {
  36 #if OPAL_ENABLE_DEBUG
  37     pthread_mutexattr_t attr;
  38     pthread_mutexattr_init(&attr);
  39 
  40     /* set type to ERRORCHECK so that we catch recursive locks */
  41 #if OPAL_HAVE_PTHREAD_MUTEX_ERRORCHECK_NP
  42     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP);
  43 #elif OPAL_HAVE_PTHREAD_MUTEX_ERRORCHECK
  44     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
  45 #endif /* OPAL_HAVE_PTHREAD_MUTEX_ERRORCHECK_NP */
  46 
  47     pthread_mutex_init(&m->m_lock_pthread, &attr);
  48     pthread_mutexattr_destroy(&attr);
  49 
  50     m->m_lock_debug = 0;
  51     m->m_lock_file = NULL;
  52     m->m_lock_line = 0;
  53 #else
  54 
  55     /* Without debugging, choose the fastest available mutexes */
  56     pthread_mutex_init(&m->m_lock_pthread, NULL);
  57 
  58 #endif /* OPAL_ENABLE_DEBUG */
  59 
  60 #if OPAL_HAVE_ATOMIC_SPINLOCKS
  61     opal_atomic_lock_init( &m->m_lock_atomic, OPAL_ATOMIC_LOCK_UNLOCKED );
  62 #endif
  63 }
  64 
  65 static void opal_mutex_destruct(opal_mutex_t *m)
  66 {
  67     pthread_mutex_destroy(&m->m_lock_pthread);
  68 }
  69 
  70 OBJ_CLASS_INSTANCE(opal_mutex_t,
  71                    opal_object_t,
  72                    opal_mutex_construct,
  73                    opal_mutex_destruct);
  74 
  75 static void opal_recursive_mutex_construct(opal_recursive_mutex_t *m)
  76 {
  77     pthread_mutexattr_t attr;
  78     pthread_mutexattr_init(&attr);
  79 
  80 #if OPAL_ENABLE_DEBUG
  81     m->m_lock_debug = 0;
  82     m->m_lock_file = NULL;
  83     m->m_lock_line = 0;
  84 #endif
  85 
  86     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  87 
  88     pthread_mutex_init(&m->m_lock_pthread, &attr);
  89     pthread_mutexattr_destroy(&attr);
  90 
  91 #if OPAL_HAVE_ATOMIC_SPINLOCKS
  92     opal_atomic_lock_init( &m->m_lock_atomic, OPAL_ATOMIC_LOCK_UNLOCKED );
  93 #endif
  94 }
  95 
  96 OBJ_CLASS_INSTANCE(opal_recursive_mutex_t,
  97                    opal_object_t,
  98                    opal_recursive_mutex_construct,
  99                    opal_mutex_destruct);

/* [<][>][^][v][top][bottom][index][help] */