/* ot.h - Orangetide's Tiny threads */ /* PUBLIC DOMAIN - Jon Mayo - August 23, 2005 */ #ifndef OT_H #define OT_H struct ot_state { unsigned line; }; #define OT_STATUS_WAITING 1 #define OT_STATUS_EXITED 0 #define OT_BEGIN(ots) switch((ots)->line) { case 0: #define OT_END(ots) } OT_EXIT(ots); #define OT_INITIALIZE(ots) ((ots)->line=0) #define OT_INITIALIZER {0} /* sets the state, on reentry the program will continue at this point */ #define OT_SET(ots) (ots)->line=__LINE__; case __LINE__: /* wait while condition cond is true */ #define OT_WAIT_WHILE(ots, cond) do { OT_SET(ots); if((cond)) { return OT_STATUS_WAITING; } } while(0) /* checks condition cond and continues if it's true */ #define OT_WAIT_UNTIL(ots, cond) do { OT_SET(ots); if(!(cond)) { return OT_STATUS_WAITING; } } while(0) /* restarts the state machine from the beginning */ #define OT_RESTART(ots) do { OT_INITIALIZE(ots); return OT_STATUS_WAITING; } while(0) #define OT_EXIT(ots) do { OT_INITIALIZE(ots); return OT_STATUS_EXITED; } while(0) /* use this for debugging, evalutes to the line number currently holding on */ #define OT_LINE(ots) ((ots)->line) #endif