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-2016 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 Cisco Systems, Inc. All rights reserved. 14 * Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights 15 * reserved. 16 * Copyright (c) 2007 Voltaire. All rights reserved. 17 * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. 18 * 19 * Copyright (c) 2017 Intel, Inc. All rights reserved. 20 * $COPYRIGHT$ 21 * 22 * Additional copyrights may follow 23 * 24 * $HEADER$ 25 */ 26 27 #ifndef PMIX_MUTEX_H 28 #define PMIX_MUTEX_H 1 29 30 #include "pmix_config.h" 31 32 #include "src/threads/thread_usage.h" 33 34 BEGIN_C_DECLS 35 36 /** 37 * @file: 38 * 39 * Mutual exclusion functions. 40 * 41 * Functions for locking of critical sections. 42 */ 43 44 /** 45 * Opaque mutex object 46 */ 47 typedef struct pmix_mutex_t pmix_mutex_t; 48 typedef struct pmix_mutex_t pmix_recursive_mutex_t; 49 50 /** 51 * Try to acquire a mutex. 52 * 53 * @param mutex Address of the mutex. 54 * @return 0 if the mutex was acquired, 1 otherwise. 55 */ 56 static inline int pmix_mutex_trylock(pmix_mutex_t *mutex); 57 58 59 /** 60 * Acquire a mutex. 61 * 62 * @param mutex Address of the mutex. 63 */ 64 static inline void pmix_mutex_lock(pmix_mutex_t *mutex); 65 66 67 /** 68 * Release a mutex. 69 * 70 * @param mutex Address of the mutex. 71 */ 72 static inline void pmix_mutex_unlock(pmix_mutex_t *mutex); 73 74 75 /** 76 * Try to acquire a mutex using atomic operations. 77 * 78 * @param mutex Address of the mutex. 79 * @return 0 if the mutex was acquired, 1 otherwise. 80 */ 81 static inline int pmix_mutex_atomic_trylock(pmix_mutex_t *mutex); 82 83 84 /** 85 * Acquire a mutex using atomic operations. 86 * 87 * @param mutex Address of the mutex. 88 */ 89 static inline void pmix_mutex_atomic_lock(pmix_mutex_t *mutex); 90 91 92 /** 93 * Release a mutex using atomic operations. 94 * 95 * @param mutex Address of the mutex. 96 */ 97 static inline void pmix_mutex_atomic_unlock(pmix_mutex_t *mutex); 98 99 END_C_DECLS 100 101 #include "mutex_unix.h" 102 103 #endif /* PMIX_MUTEX_H */