- various enhancements
This commit is contained in:
13
fsm.c
13
fsm.c
@@ -6,6 +6,7 @@ a finite state machine within sics
|
||||
M. Zolliker, Aug 2004
|
||||
---------------------------------------------------------------------------- */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
@@ -28,12 +29,12 @@ struct Fsm {
|
||||
int pause;
|
||||
int sp;
|
||||
StackItem stack[MAXSTACK];
|
||||
Statistics *stat;
|
||||
};
|
||||
|
||||
|
||||
static Fsm *fsm = NULL;
|
||||
static FsmFunc callFunc = NULL;
|
||||
static Statistics *taskStat = NULL;
|
||||
|
||||
void FsmWait(long delay) {
|
||||
assert(fsm);
|
||||
@@ -49,10 +50,7 @@ int FsmTaskHandler(Fsm *task) {
|
||||
long line;
|
||||
Statistics *old;
|
||||
|
||||
if (taskStat == NULL) {
|
||||
taskStat=StatisticsNew("<fsm>");
|
||||
}
|
||||
old = StatisticsBegin(taskStat);
|
||||
old = StatisticsBegin(task->stat);
|
||||
if (task->pause) {
|
||||
task->handler(task->obj);
|
||||
StatisticsEnd(old);
|
||||
@@ -110,12 +108,15 @@ void FsmRestartTask(Fsm *task, FsmFunc func) {
|
||||
task->till = 0;
|
||||
}
|
||||
|
||||
Fsm *FsmStartTask(void *obj, FsmHandler handler, FsmFunc func) {
|
||||
Fsm *FsmStartTask(void *obj, FsmHandler handler, FsmFunc func, char *name) {
|
||||
Fsm *task;
|
||||
char fsmName[80];
|
||||
|
||||
task=malloc(sizeof *task);
|
||||
task->obj = obj;
|
||||
task->handler = handler;
|
||||
snprintf(fsmName, sizeof fsmName, "fsm %s", name);
|
||||
task->stat = StatisticsNew(fsmName);
|
||||
FsmRestartTask(task, func);
|
||||
return task;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user