vm_act_state set_node_state(Node n, vm_act_state state, int* error) { int result; vm_act_state state_set = state; *error = 0; if (n->type != ACTION) { STATE(n) = state_set; return state_set; } switch(state_set) { case ACT_READY: result = is_requires_true(n); if (result == -1) { *error = 1; return STATE(n); } if (!result) state_set = ACT_BLOCKED; break; case ACT_DONE: result = is_provides_true(n); if (result == -1) { *error = 1; return STATE(n); } if (!result) state_set = ACT_PENDING; break; } STATE(n) = state_set; return state_set; }
/* this function was earlier called handle_resource_change */ vm_exit_code update_process_state(int pid) { Graph g; Node n; int result; peos_context_t *context = peos_get_context(pid); if (context == NULL) { peos_error("update_process_state: cannot get context for pid=%d", pid); return VM_INTERNAL_ERROR; } g = context -> process_graph; if (g == NULL) { peos_error("update_process_state: cannot get graph for pid=%d", pid); return VM_INTERNAL_ERROR; } for (n = g->source->next; n != NULL; n = n->next) { if (n->type == ACTION) { result = is_requires_true(n); if (result == -1) return VM_INTERNAL_ERROR; if (result) { if (handle_resource_event(pid, n->name, REQUIRES_TRUE) == VM_INTERNAL_ERROR) { return VM_INTERNAL_ERROR; } } result = is_provides_true(n); if (result == -1) return VM_INTERNAL_ERROR; if (result) { if (handle_resource_event(pid, n->name, PROVIDES_TRUE) == VM_INTERNAL_ERROR) { return VM_INTERNAL_ERROR; } } } } return VM_CONTINUE; }
vm_exit_code update_process_state(int pid) { Graph g; Node n; int result; peos_context_t *context = peos_get_context(pid); if(context == NULL) { fprintf(stderr, "Handle Resource Change: Cannot Get Context\n"); return VM_INTERNAL_ERROR; } g = context -> process_graph; if(g == NULL) { fprintf(stderr, "Handle Resource Change Error: Cannot Get Graph\n"); return VM_INTERNAL_ERROR; } for(n = g->source->next; n != NULL; n = n->next) { if(n->type == ACTION) { result = is_requires_true(n); if (result == -1) return VM_INTERNAL_ERROR; if (result) { if(handle_resource_event(pid, n->name, REQUIRES_TRUE) == VM_INTERNAL_ERROR) { return VM_INTERNAL_ERROR; } } result = is_provides_true(n); if (result == -1) return VM_INTERNAL_ERROR; if (result) { if(handle_resource_event(pid, n->name, PROVIDES_TRUE) == VM_INTERNAL_ERROR) { return VM_INTERNAL_ERROR; } } } } return VM_CONTINUE; }