do_event() source code based on Contiki's source code
| Line# | Code |
| 245 | static void |
| 246 | do_event(void) |
| 247 | { |
| 248 | static process_event_t ev; |
| 249 | static process_data_t data; |
| 250 | static struct process *receiver; |
| 251 | static struct process *p; |
| 252 | |
| 253 | /* |
| 254 | * If there are any events in the queue, take the first one and walk |
| 255 | * through the list of processes to see if the event should be |
| 256 | * delivered to any of them. If so, we call the event handler |
| 257 | * function for the process. We only process one event at a time and |
| 258 | * call the poll handlers inbetween. |
| 259 | */ |
| 260 | |
| 261 | if(nevents > 0) { |
| 262 | |
| 263 | /* There are events that we should deliver. */ |
| 264 | ev = events[fevent].ev; |
| 265 | |
| 266 | data = events[fevent].data; |
| 267 | receiver = events[fevent].p; |
| 268 | |
| 269 | /* Since we have seen the new event, we move pointer upwards |
| 270 | and decrease the number of events. */ |
| 271 | fevent = (fevent + 1) % PROCESS_CONF_NUMEVENTS; |
| 272 | --nevents; |
| 273 | |
| 274 | /* If this is a broadcast event, we deliver it to all events, in |
| 275 | order of their priority. */ |
| 276 | if(receiver == PROCESS_BROADCAST) { |
| 277 | for(p = process_list; p != NULL; p = p->next) { |
| 278 | |
| 279 | /* If we have been requested to poll a process, we do this in |
| 280 | between processing the broadcast event. */ |
| 281 | if(poll_requested) { |
| 282 | do_poll(); |
| 283 | } |
| 284 | call_process(p, ev, data); |
| 285 | } |
| 286 | } else { |
| 287 | /* This is not a broadcast event, so we deliver it to the |
| 288 | specified process. */ |
| 289 | /* If the event was an INIT event, we should also update the |
| 290 | state of the process. */ |
| 291 | if(ev == PROCESS_EVENT_INIT) { |
| 292 | receiver->state = PROCESS_STATE_RUNNING; |
| 293 | } |
| 294 | |
| 295 | /* Make sure that the process actually is running. */ |
| 296 | call_process(receiver, ev, data); |
| 297 | } |
| 298 | } |
| 299 | } |