1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define _GNU_SOURCE
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <time.h>
31 #include <pthread.h>
32
33 #include <pmix_common.h>
34
35 typedef struct {
36 pthread_mutex_t mutex;
37 pthread_cond_t cond;
38 volatile bool active;
39 pmix_status_t status;
40 int count;
41 size_t evhandler_ref;
42 } mylock_t;
43
44 #define DEBUG_CONSTRUCT_LOCK(l) \
45 do { \
46 pthread_mutex_init(&(l)->mutex, NULL); \
47 pthread_cond_init(&(l)->cond, NULL); \
48 (l)->active = true; \
49 (l)->status = PMIX_SUCCESS; \
50 (l)->count = 0; \
51 (l)->evhandler_ref = 0; \
52 } while(0)
53
54 #define DEBUG_DESTRUCT_LOCK(l) \
55 do { \
56 pthread_mutex_destroy(&(l)->mutex); \
57 pthread_cond_destroy(&(l)->cond); \
58 } while(0)
59
60 #define DEBUG_WAIT_THREAD(lck) \
61 do { \
62 pthread_mutex_lock(&(lck)->mutex); \
63 while ((lck)->active) { \
64 pthread_cond_wait(&(lck)->cond, &(lck)->mutex); \
65 } \
66 pthread_mutex_unlock(&(lck)->mutex); \
67 } while(0)
68
69 #define DEBUG_WAKEUP_THREAD(lck) \
70 do { \
71 pthread_mutex_lock(&(lck)->mutex); \
72 (lck)->active = false; \
73 pthread_cond_broadcast(&(lck)->cond); \
74 pthread_mutex_unlock(&(lck)->mutex); \
75 } while(0)
76
77
78
79 typedef struct {
80 mylock_t lock;
81 pmix_info_t *info;
82 size_t ninfo;
83 } myquery_data_t;
84
85 #define DEBUG_CONSTRUCT_MYQUERY(q) \
86 do { \
87 DEBUG_CONSTRUCT_LOCK(&((q)->lock)); \
88 (q)->info = NULL; \
89 (q)->ninfo = 0; \
90 } while(0)
91
92 #define DEBUG_DESTRUCT_MYQUERY(q) \
93 do { \
94 DEBUG_DESTRUCT_LOCK(&((q)->lock)); \
95 if (NULL != (q)->info) { \
96 PMIX_INFO_FREE((q)->info, (q)->ninfo); \
97 } \
98 } while(0)
99
100
101
102 typedef struct {
103 mylock_t lock;
104 char *nspace;
105 int exit_code;
106 bool exit_code_given;
107 } myrel_t;
108
109
110 #define DEBUG_CONSTRUCT_MYREL(r) \
111 do { \
112 DEBUG_CONSTRUCT_LOCK(&((r)->lock)); \
113 (r)->nspace = NULL; \
114 (r)->exit_code = 0; \
115 (r)->exit_code_given = false; \
116 } while(0)
117
118 #define DEBUG_DESTRUCT_MYREL(r) \
119 do { \
120 DEBUG_DESTRUCT_LOCK(&((r)->lock)); \
121 if (NULL != (r)->nspace) { \
122 free((r)->nspace); \
123 } \
124 } while(0)