OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

mutex_windows.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2007 Los Alamos National Security, LLC. All rights
13 * reserved.
14 * $COPYRIGHT$
15 *
16 * Additional copyrights may follow
17 *
18 * $HEADER$
19 */
20
21 #ifndef OPAL_MUTEX_WINDOWS_H
22 #define OPAL_MUTEX_WINDOWS_H 1
23
24 /**
25 * @file:
26 *
27 * Mutual exclusion functions: Windows implementation.
28 *
29 * Functions for locking of critical sections.
30 *
31 * On Windows, base everything on InterlockedExchange().
32 */
33
34 #include "opal_config.h"
35 #include "opal/class/opal_object.h"
36 #include "opal/sys/atomic.h"
37
38 BEGIN_C_DECLS
39
40 struct opal_mutex_t {
41 opal_object_t super;
42 volatile LONG m_lock;
43
44 #if OPAL_ENABLE_DEBUG
45 int m_lock_debug;
46 const char *m_lock_file;
47 int m_lock_line;
48 #endif
49 };
50
51 OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
52
53
54 static inline int opal_mutex_trylock(opal_mutex_t *m)
55 {
56 return (0 == InterlockedExchange(&m->m_lock, 1) ? 1 : 0);
57 }
58
59
60 static inline void opal_mutex_lock(opal_mutex_t *m)
61 {
62 while (InterlockedExchange(&m->m_lock, 1)) {
63 while (m->m_lock == 1) {
64 /* spin */;
65 }
66 }
67 }
68
69
70 static inline void opal_mutex_unlock(opal_mutex_t *m)
71 {
72 InterlockedExchange(&m->m_lock, 0);
73 }
74
75
76 static inline int opal_mutex_atomic_trylock(opal_mutex_t *m)
77 {
78 return opal_mutex_trylock(m);
79 }
80
81
82 static inline void opal_mutex_atomic_lock(opal_mutex_t *m)
83 {
84 opal_mutex_lock(m);
85 }
86
87
88 static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
89 {
90 opal_mutex_unlock(m);
91 }
92
93 END_C_DECLS
94
95 #endif /* OPAL_MUTEX_WINDOWS_H */
opal_mutex_lock
static void opal_mutex_lock(opal_mutex_t *mutex)
Acquire a mutex.
opal_mutex_atomic_trylock
static int opal_mutex_atomic_trylock(opal_mutex_t *mutex)
Try to acquire a mutex using atomic operations.
opal_mutex_atomic_unlock
static void opal_mutex_atomic_unlock(opal_mutex_t *mutex)
Release a mutex using atomic operations.
opal_mutex_t
Definition: mutex_unix.h:53
opal_mutex_trylock
static int opal_mutex_trylock(opal_mutex_t *mutex)
Try to acquire a mutex.
opal_mutex_unlock
static void opal_mutex_unlock(opal_mutex_t *mutex)
Release a mutex.
opal_object_t
Base object.
Definition: opal_object.h:182
atomic.h
Atomic operations.
opal_object.h
A simple C-language object-oriented system with single inheritance and ownership-based memory managem...
opal_mutex_atomic_lock
static void opal_mutex_atomic_lock(opal_mutex_t *mutex)
Acquire a mutex using atomic operations.
OBJ_CLASS_DECLARATION
#define OBJ_CLASS_DECLARATION(NAME)
Declaration for class descriptor.
Definition: opal_object.h:236