This source file includes following definitions.
- sync_wait_st
- wait_sync_update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #if !defined(OPAL_THREADS_WAIT_SYNC_H)
20 #define OPAL_THREADS_WAIT_SYNC_H
21
22 #include "opal/sys/atomic.h"
23 #include "opal/threads/condition.h"
24 #include <pthread.h>
25
26 BEGIN_C_DECLS
27
28 extern int opal_max_thread_in_progress;
29
30 typedef struct ompi_wait_sync_t {
31 opal_atomic_int32_t count;
32 int32_t status;
33 pthread_cond_t condition;
34 pthread_mutex_t lock;
35 struct ompi_wait_sync_t *next;
36 struct ompi_wait_sync_t *prev;
37 volatile bool signaling;
38 } ompi_wait_sync_t;
39
40 #define REQUEST_PENDING (void*)0L
41 #define REQUEST_COMPLETED (void*)1L
42
43 #define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync))
44
45
46
47
48
49
50
51
52
53 #define WAIT_SYNC_RELEASE(sync) \
54 if (opal_using_threads()) { \
55 while ((sync)->signaling) { \
56 continue; \
57 } \
58 pthread_cond_destroy(&(sync)->condition); \
59 pthread_mutex_destroy(&(sync)->lock); \
60 }
61
62 #define WAIT_SYNC_RELEASE_NOWAIT(sync) \
63 if (opal_using_threads()) { \
64 pthread_cond_destroy(&(sync)->condition); \
65 pthread_mutex_destroy(&(sync)->lock); \
66 }
67
68
69 #define WAIT_SYNC_SIGNAL(sync) \
70 if (opal_using_threads()) { \
71 pthread_mutex_lock(&(sync->lock)); \
72 pthread_cond_signal(&sync->condition); \
73 pthread_mutex_unlock(&(sync->lock)); \
74 sync->signaling = false; \
75 }
76
77 #define WAIT_SYNC_SIGNALLED(sync){ \
78 (sync)->signaling = false; \
79 }
80
81 OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync);
82 static inline int sync_wait_st (ompi_wait_sync_t *sync)
83 {
84 while (sync->count > 0) {
85 opal_progress();
86 }
87
88 return sync->status;
89 }
90
91
92 #define WAIT_SYNC_INIT(sync,c) \
93 do { \
94 (sync)->count = (c); \
95 (sync)->next = NULL; \
96 (sync)->prev = NULL; \
97 (sync)->status = 0; \
98 (sync)->signaling = (0 != (c)); \
99 if (opal_using_threads()) { \
100 pthread_cond_init (&(sync)->condition, NULL); \
101 pthread_mutex_init (&(sync)->lock, NULL); \
102 } \
103 } while(0)
104
105
106
107
108
109
110
111 static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, int status)
112 {
113 if( OPAL_LIKELY(OPAL_SUCCESS == status) ) {
114 if( 0 != (OPAL_THREAD_ADD_FETCH32(&sync->count, -updates)) ) {
115 return;
116 }
117 } else {
118
119 sync->status = OPAL_ERROR;
120 opal_atomic_wmb ();
121 opal_atomic_swap_32 (&sync->count, 0);
122 }
123 WAIT_SYNC_SIGNAL(sync);
124 }
125
126 END_C_DECLS
127
128 #endif