| 42 | | trc_recv_messages( ID, max_count, status ) |
| 43 | | TRC_ID ID; |
| 44 | | int max_count; |
| 45 | | int *status; |
| 46 | | { |
| 47 | | static int *tids = (int *) NULL;
|
| 48 | | static int ntids = 0; |
| 49 | | |
| 50 | | TRC_HOST H; |
| 51 | | |
| 52 | | TRC_ID DEAD_ID_last; |
| | | ... |
| 61 | | int mid; |
| 62 | | int num; |
| 63 | | int tid; |
| 64 | | int src; |
| 65 | | int tmp; |
| 66 | | int cc; |
| 67 | | int i; |
| 68 | | |
| 69 | | |
| 70 | | |
| 71 | | if ( TRC_HOST_ADD_NOTIFY_CODE == -1 |
| 72 | | || TRC_HOST_DEL_NOTIFY_CODE == -1 |
| 73 | | #ifndef USE_PVM_33 |
| 74 | | || ID->event_ctx == -1 || ID->output_ctx == -1 |
| 75 | | #endif |
| 76 | | || ID->event_tag == -1 || ID->output_tag == -1 ) |
| 77 | | { |
| 78 | | printf( "Error: Message Codes Not Set - %d %d %d %d %d %d\n", |
| 79 | | TRC_HOST_ADD_NOTIFY_CODE, TRC_HOST_DEL_NOTIFY_CODE, |
| 80 | | ID->event_ctx, ID->output_ctx, |
| 81 | | ID->event_tag, ID->output_tag ); |
| 82 | | |
| 83 | | return( -1 ); |
| 84 | | } |
| 85 | | |
| 86 | | |
| 87 | | |
| 88 | | if ( status != NULL )
|
| 89 | | *status = TRC_MSG_STATUS_NONE;
|
| 90 | | |
| 91 | | |
| 92 | | |
| 93 | | ecnt = 0; |
| 94 | | |
| 95 | | |
| 96 | | |
| 97 | | ecnt += trc_check_host_sync( ID ); |
| 98 | | |
| 99 | | |
| 100 | | |
| 101 | | cnt = 0; |
| 102 | | |
| 103 | | while ( cnt < max_count |
| 104 | | && (mid = trc_get_msg( ID, &len, &msgtag, &src, &others )) > 0 ) |
| 105 | | { |
| 106 | | |
| 107 | | |
| 108 | | if ( status != NULL )
|
| 109 | | *status |= TRC_MSG_STATUS_ACTIVE;
|
| 110 | | |
| 111 | | |
| 112 | | |
| 113 | | if ( msgtag == TRC_HOST_ADD_NOTIFY_CODE && src == 0x80000000 ) |
| 114 | | { |
| 115 | | cc = pvm_upkint( &num, 1, 1 ); |
| 116 | | |
| 117 | | if ( cc < 0 ) |
| 118 | | pvm_perror( "Error Unpacking Host Add Notify" ); |
| 119 | | |
| 120 | | else |
| 121 | | { |
| 122 | | if ( num > ntids ) |
| 123 | | { |
| 124 | | ntids = num * 2; |
| 125 | | |
| 126 | | if ( tids ) |
| 127 | | free( tids ); |
| 128 | | |
| 129 | | tids = (int *) malloc( (unsigned) ntids |
| 130 | | * sizeof(int) ); |
| 131 | | trc_memcheck( tids, "Host Add Notify Tids Array" ); |
| 132 | | } |
| 133 | | |
| 134 | | cc = pvm_upkint( tids, num, 1 ); |
| 135 | | |
| 136 | | if ( cc < 0 ) |
| 137 | | pvm_perror( "Error Unpacking Host Add TIDs" ); |
| 138 | | |
| 139 | | else |
| 140 | | { |
| 141 | | pvm_notify( PvmHostDelete,
|
| 142 | | TRC_HOST_DEL_NOTIFY_CODE, num, tids ); |
| 143 | | |
| 144 | | ecnt += trc_handle_host_add_notify( ID, tids, num ); |
| 145 | | } |
| 146 | | } |
| 147 | | } |
| 148 | | |
| 149 | | |
| 150 | | |
| 151 | | else if ( msgtag == TRC_HOST_DEL_NOTIFY_CODE |
| 152 | | && src == 0x80000000 ) |
| 153 | | { |
| 154 | | cc = pvm_upkint( &tid, 1, 1 ); |
| 155 | | |
| 156 | | if ( cc < 0 ) |
| 157 | | pvm_perror( "Error Unpacking Host Delete Notify" ); |
| 158 | | |
| 159 | | else |
| 160 | | ecnt += trc_handle_host_del_notify( ID, tid ); |
| 161 | | } |
| 162 | | |
| 163 | | |
| 164 | | |
| 165 | | else if ( msgtag == ID->event_tag ) |
| 166 | | { |
| 167 | | ecnt += trc_handle_trace_message( ID, src ); |
| 168 | | |
| 169 | | if ( status != NULL )
|
| 170 | | { |
| 171 | | if ( ecnt ) |
| 172 | | *status |= TRC_MSG_STATUS_OVERWRITE;
|
| 173 | | |
| 174 | | else |
| 175 | | *status |= TRC_MSG_STATUS_CLEANUP;
|
| 176 | | } |
| 177 | | } |
| 178 | | |
| 179 | | |
| 180 | | |
| 181 | | else if ( msgtag == ID->output_tag ) |
| 182 | | { |
| 183 | | ecnt += trc_handle_output_message( ID ); |
| 184 | | |
| 185 | | if ( status != NULL )
|
| 186 | | { |
| 187 | | if ( ecnt ) |
| 188 | | *status |= TRC_MSG_STATUS_OVERWRITE;
|
| 189 | | |
| 190 | | else |
| 191 | | *status |= TRC_MSG_STATUS_CLEANUP;
|
| 192 | | } |
| 193 | | } |
| 194 | | |
| 195 | | |
| 196 | | |
| 197 | | else |
| 198 | | { |
| 199 | | fprintf( stderr, |
| 200 | | "Tracer: msg from 0x%x code %d len %d ?\n", |
| 201 | | src, msgtag, len ); |
| 202 | | } |
| 203 | | |
| 204 | | if ( pvm_freebuf( mid ) < 0 ) |
| 205 | | pvm_perror( "Error Freeing Message Buffer" ); |
| 206 | | |
| 207 | | cnt++; |
| 208 | | } |
| 209 | | |
| 210 | | if ( mid < 0 ) |
| 211 | | { |
| 212 | | pvm_perror( "PVM System Failure" ); |
| 213 | | |
| 214 | | printf( "Tracer exiting...\n" ); |
| 215 | | |
| 216 | | return( -1 ); |
| 217 | | } |
| 218 | | |
| 219 | | if ( status != NULL )
|
| 220 | | { |
| 221 | | if ( cnt == max_count ) |
| 222 | | *status |= TRC_MSG_STATUS_MORE;
|
| 223 | | } |
| 224 | | |
| 225 | | |
| 226 | | |
| 227 | | if ( others ) |
| 228 | | { |
| 229 | | DEAD_ID = TRC_DEAD_ID_LIST; |
| 230 | | |
| 231 | | DEAD_ID_last = (TRC_ID ) NULL;
|
| 232 | | |
| 233 | | while ( DEAD_ID != NULL )
|
| 234 | | { |
| 235 | | trc_recv_messages( DEAD_ID, 1, &tmp ); |
| 236 | | |
| 237 | | if ( status != NULL )
|
| 238 | | *status |= tmp; |
| 239 | | |
| 240 | | if ( trc_tevtasks_dead( DEAD_ID ) ) |
| 241 | | { |
| 242 | | DEAD_ID_next = DEAD_ID->next; |
| 243 | | |
| 244 | | if ( DEAD_ID_last != NULL )
|
| 245 | | DEAD_ID_last->next = DEAD_ID_next; |
| 246 | | |
| 247 | | else |
| 248 | | TRC_DEAD_ID_LIST = DEAD_ID_next; |
| 249 | | |
| 250 | | trc_free_tracer_id( &DEAD_ID ); |
| 251 | | |
| 252 | | DEAD_ID = DEAD_ID_next; |
| 253 | | } |
| 254 | | |
| 255 | | else |
| 256 | | { |
| 257 | | DEAD_ID_last = DEAD_ID; |
| 258 | | |
| 259 | | DEAD_ID = DEAD_ID->next; |
| 260 | | } |
| 261 | | } |
| 262 | | } |
| 263 | | |
| 264 | | return( ecnt ); |
| 265 | | } |