This source file includes following definitions.
- pmix_sync_wait_st
- pmix_wait_sync_update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #if !defined(PMIX_THREADS_WAIT_SYNC_H)
20 #define PMIX_THREADS_WAIT_SYNC_H
21
22 #include "src/include/prefetch.h"
23 #include "src/atomics/sys/atomic.h"
24 #include "src/threads/threads.h"
25 #include "src/util/error.h"
26 #include <pthread.h>
27
28 BEGIN_C_DECLS
29
30 typedef struct pmix_wait_sync_t {
31 pmix_atomic_int32_t count;
32 int32_t status;
33 pthread_cond_t condition;
34 pthread_mutex_t lock;
35 struct pmix_wait_sync_t *next;
36 struct pmix_wait_sync_t *prev;
37 volatile bool signaling;
38 } pmix_wait_sync_t;
39
40 #define REQUEST_PENDING (void*)0L
41 #define REQUEST_COMPLETED (void*)1L
42
43 #define PMIX_SYNC_WAIT(sync) pmix_sync_wait_mt (sync)
44
45
46
47
48
49
50
51
52
53 #define PMIX_WAIT_SYNC_RELEASE(sync) \
54 while ((sync)->signaling) { \
55 continue; \
56 } \
57 pthread_cond_destroy(&(sync)->condition); \
58 pthread_mutex_destroy(&(sync)->lock);
59
60 #define PMIX_WAIT_SYNC_RELEASE_NOWAIT(sync) \
61 pthread_cond_destroy(&(sync)->condition); \
62 pthread_mutex_destroy(&(sync)->lock);
63
64
65 #define PMIX_WAIT_SYNC_SIGNAL(sync) \
66 pthread_mutex_lock(&(sync->lock)); \
67 pthread_cond_signal(&sync->condition); \
68 pthread_mutex_unlock(&(sync->lock)); \
69 sync->signaling = false;
70
71 #define PMIX_WAIT_SYNC_SIGNALLED(sync){ \
72 (sync)->signaling = false; \
73 }
74
75 PMIX_EXPORT int pmix_sync_wait_mt(pmix_wait_sync_t *sync);
76 static inline int pmix_sync_wait_st (pmix_wait_sync_t *sync)
77 {
78 while (sync->count > 0) {
79 }
80
81 return sync->status;
82 }
83
84
85 #define PMIX_WAIT_SYNC_INIT(sync,c) \
86 do { \
87 (sync)->count = (c); \
88 (sync)->next = NULL; \
89 (sync)->prev = NULL; \
90 (sync)->status = 0; \
91 (sync)->signaling = (0 != (c)); \
92 pthread_cond_init (&(sync)->condition, NULL); \
93 pthread_mutex_init (&(sync)->lock, NULL); \
94 } while(0)
95
96
97
98
99
100
101
102 static inline void pmix_wait_sync_update(pmix_wait_sync_t *sync,
103 int updates, int status)
104 {
105 if( PMIX_LIKELY(PMIX_SUCCESS == status) ) {
106 if( 0 != (PMIX_THREAD_ADD_FETCH32(&sync->count, -updates)) ) {
107 return;
108 }
109 } else {
110
111 sync->status = PMIX_ERROR;
112 pmix_atomic_wmb ();
113 pmix_atomic_swap_32 (&sync->count, 0);
114 }
115 PMIX_WAIT_SYNC_SIGNAL(sync);
116 }
117
118 END_C_DECLS
119
120 #endif