OpenMPI 0.1.1

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

- File List
- Globals

threads.h
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-2006 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) 2010 Cisco Systems, Inc. All rights reserved.
13 * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
14 * $COPYRIGHT$
15 *
16 * Additional copyrights may follow
17 *
18 * $HEADER$
19 */
20
21 #ifndef OPAL_THREAD_H
22 #define OPAL_THREAD_H 1
23
24 #include "opal_config.h"
25
26 #if OPAL_HAVE_POSIX_THREADS
27 #include <pthread.h>
28 #elif OPAL_HAVE_SOLARIS_THREADS
29 #include <thread.h>
30 #endif
31
32 #include "opal/class/opal_object.h"
33 #if OPAL_ENABLE_DEBUG
34 #include "opal/util/output.h"
35 #endif
36
37 #include "mutex.h"
38 #include "condition.h"
39
40 BEGIN_C_DECLS
41
42 typedef void *(*opal_thread_fn_t) (opal_object_t *);
43
44 #define OPAL_THREAD_CANCELLED ((void*)1);
45
46 struct opal_thread_t {
47 opal_object_t super;
48 opal_thread_fn_t t_run;
49 void* t_arg;
50 #ifdef __WINDOWS__
51 HANDLE t_handle;
52 #elif OPAL_HAVE_POSIX_THREADS
53 pthread_t t_handle;
54 #elif OPAL_HAVE_SOLARIS_THREADS
55 thread_t t_handle;
56 #endif
57 };
58
59 typedef struct opal_thread_t opal_thread_t;
60
61 #if OPAL_ENABLE_DEBUG
62 OPAL_DECLSPEC extern bool opal_debug_threads;
63 #endif
64
65
66 OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_thread_t);
67
68 #if OPAL_ENABLE_DEBUG
69 #define OPAL_ACQUIRE_THREAD(lck, cnd, act) \
70 do { \
71 OPAL_THREAD_LOCK((lck)); \
72 if (opal_debug_threads) { \
73 opal_output(0, "Waiting for thread %s:%d", \
74 __FILE__, __LINE__); \
75 } \
76 while (*(act)) { \
77 opal_condition_wait((cnd), (lck)); \
78 } \
79 if (opal_debug_threads) { \
80 opal_output(0, "Thread obtained %s:%d", \
81 __FILE__, __LINE__); \
82 } \
83 *(act) = true; \
84 } while(0);
85 #else
86 #define OPAL_ACQUIRE_THREAD(lck, cnd, act) \
87 do { \
88 OPAL_THREAD_LOCK((lck)); \
89 while (*(act)) { \
90 opal_condition_wait((cnd), (lck)); \
91 } \
92 *(act) = true; \
93 } while(0);
94 #endif
95
96
97 #if OPAL_ENABLE_DEBUG
98 #define OPAL_RELEASE_THREAD(lck, cnd, act) \
99 do { \
100 if (opal_debug_threads) { \
101 opal_output(0, "Releasing thread %s:%d", \
102 __FILE__, __LINE__); \
103 } \
104 *(act) = false; \
105 opal_condition_broadcast((cnd)); \
106 OPAL_THREAD_UNLOCK((lck)); \
107 } while(0);
108 #else
109 #define OPAL_RELEASE_THREAD(lck, cnd, act) \
110 do { \
111 *(act) = false; \
112 opal_condition_broadcast((cnd)); \
113 OPAL_THREAD_UNLOCK((lck)); \
114 } while(0);
115 #endif
116
117
118 #define OPAL_WAKEUP_THREAD(cnd, act) \
119 do { \
120 *(act) = false; \
121 opal_condition_broadcast((cnd)); \
122 } while(0);
123
124
125 OPAL_DECLSPEC int opal_thread_start(opal_thread_t *);
126 OPAL_DECLSPEC int opal_thread_join(opal_thread_t *, void **thread_return);
127 OPAL_DECLSPEC bool opal_thread_self_compare(opal_thread_t*);
128 OPAL_DECLSPEC opal_thread_t *opal_thread_get_self(void);
129 OPAL_DECLSPEC void opal_thread_kill(opal_thread_t *, int sig);
130
131 END_C_DECLS
132
133 #endif /* OPAL_THREAD_H */
output.h
OPAL output stream facility.
thread.h
Functions for multi-threaded applications using Libevent.
opal_object_t
Base object.
Definition: opal_object.h:182
opal_thread_t
Definition: threads.h:46
opal_object.h
A simple C-language object-oriented system with single inheritance and ownership-based memory managem...
OBJ_CLASS_DECLARATION
#define OBJ_CLASS_DECLARATION(NAME)
Declaration for class descriptor.
Definition: opal_object.h:236