diff --git a/rewrite/main.c b/rewrite/main.c index 8bff0d0..c16e9c4 100644 --- a/rewrite/main.c +++ b/rewrite/main.c @@ -89,7 +89,7 @@ int main() { while(true) { nn_Exit e = nn_tick(c); - if(e != NN_OK) { + if(e != NN_OK && e != NN_EBUSY) { nn_setErrorFromExit(c, e); printf("error: %s\n", nn_getError(c)); goto cleanup; diff --git a/rewrite/neonucleus.c b/rewrite/neonucleus.c index a2aae1a..866e81d 100644 --- a/rewrite/neonucleus.c +++ b/rewrite/neonucleus.c @@ -1031,6 +1031,8 @@ nn_Exit nn_tick(nn_Computer *computer) { req.localState = computer->archState; req.action = NN_ARCH_TICK; err = computer->arch.handler(&req); + // dont crash on EBUSY because it just means go again + if(err == NN_EBUSY) return err; if(err) { computer->state = NN_CRASHED; nn_setErrorFromExit(computer, err); @@ -1338,6 +1340,7 @@ void nn_resetCallBudget(nn_Computer *computer) { } bool nn_componentsOverused(nn_Computer *computer) { + if(computer->totalCallBudget == 0) return false; return computer->callBudget == 0; } diff --git a/rewrite/neonucleus.h b/rewrite/neonucleus.h index 4828ae0..4032cd2 100644 --- a/rewrite/neonucleus.h +++ b/rewrite/neonucleus.h @@ -206,6 +206,8 @@ typedef enum nn_Exit { NN_EBADCALL, // bad state, the function was called at the wrong time NN_EBADSTATE, + // resource busy. If the result of nn_call, you should call it again later. + NN_EBUSY, } nn_Exit; // This stores necessary data between computers @@ -481,6 +483,7 @@ const char *nn_getComponentDoc(nn_Computer *computer, const char *address, const // this uses the call stack. // Component calls must not call other components, it just doesn't work. // The lack of an argument count is because the entire call stack is assumed to be the arguments. +// In the case of NN_EBUSY, you should call it again with the same arguments later. nn_Exit nn_call(nn_Computer *computer, const char *address, const char *method); // Sets the call budget. @@ -501,7 +504,7 @@ size_t nn_callBudgetRemaining(nn_Computer *computer); void nn_resetCallBudget(nn_Computer *computer); // returns whether there is no more call budget left. -// At this point, the architecture should exit from a yield. +// At this point, the architecture should exit with a yield. bool nn_componentsOverused(nn_Computer *computer); // call stack operations.