root/opal/mca/pmix/pmix4x/pmix/src/threads/mutex.c

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

DEFINITIONS

This source file includes following definitions.
  1. pmix_mutex_construct
  2. pmix_mutex_destruct
  3. pmix_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 (c) 2017-2018 Intel, Inc. All rights reserved.
  18  * $COPYRIGHT$
  19  *
  20  * Additional copyrights may follow
  21  *
  22  * $HEADER$
  23  */
  24 
  25 #include "pmix_config.h"
  26 
  27 #include "src/threads/mutex.h"
  28 
  29 static void pmix_mutex_construct(pmix_mutex_t *m)
  30 {
  31 #if PMIX_ENABLE_DEBUG
  32     pthread_mutexattr_t attr;
  33     pthread_mutexattr_init(&attr);
  34 
  35     /* set type to ERRORCHECK so that we catch recursive locks */
  36 #if PMIX_HAVE_PTHREAD_MUTEX_ERRORCHECK_NP
  37     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP);
  38 #elif PMIX_HAVE_PTHREAD_MUTEX_ERRORCHECK
  39     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
  40 #endif /* PMIX_HAVE_PTHREAD_MUTEX_ERRORCHECK_NP */
  41 
  42     pthread_mutex_init(&m->m_lock_pthread, &attr);
  43     pthread_mutexattr_destroy(&attr);
  44 
  45     m->m_lock_debug = 0;
  46     m->m_lock_file = NULL;
  47     m->m_lock_line = 0;
  48 #else
  49 
  50     /* Without debugging, choose the fastest available mutexes */
  51     pthread_mutex_init(&m->m_lock_pthread, NULL);
  52 
  53 #endif /* PMIX_ENABLE_DEBUG */
  54 
  55 #if PMIX_HAVE_ATOMIC_SPINLOCKS
  56     pmix_atomic_lock_init( &m->m_lock_atomic, PMIX_ATOMIC_LOCK_UNLOCKED );
  57 #endif
  58 }
  59 
  60 static void pmix_mutex_destruct(pmix_mutex_t *m)
  61 {
  62     pthread_mutex_destroy(&m->m_lock_pthread);
  63 }
  64 
  65 PMIX_CLASS_INSTANCE(pmix_mutex_t,
  66                    pmix_object_t,
  67                    pmix_mutex_construct,
  68                    pmix_mutex_destruct);
  69 
  70 static void pmix_recursive_mutex_construct(pmix_recursive_mutex_t *m)
  71 {
  72     pthread_mutexattr_t attr;
  73     pthread_mutexattr_init(&attr);
  74 
  75 #if PMIX_ENABLE_DEBUG
  76     m->m_lock_debug = 0;
  77     m->m_lock_file = NULL;
  78     m->m_lock_line = 0;
  79 #endif
  80 
  81     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  82 
  83     pthread_mutex_init(&m->m_lock_pthread, &attr);
  84     pthread_mutexattr_destroy(&attr);
  85 
  86 #if PMIX_HAVE_ATOMIC_SPINLOCKS
  87     pmix_atomic_lock_init( &m->m_lock_atomic, PMIX_ATOMIC_LOCK_UNLOCKED );
  88 #endif
  89 }
  90 
  91 PMIX_CLASS_INSTANCE(pmix_recursive_mutex_t,
  92                    pmix_object_t,
  93                    pmix_recursive_mutex_construct,
  94                    pmix_mutex_destruct);

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