diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-04-18 06:35:33 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-04-18 06:35:33 +0000 |
commit | ad5522be0fbfcad7b47bb9baca9a44dadb4b6461 (patch) | |
tree | 4e5622e0b5d1d0037406ac345d2a91e2c11e1bfc /sys/src/cmd/fossil/periodic.c | |
parent | a455c61024cab80bfc50c898d8686068cd8ea06a (diff) |
remove fossil
Diffstat (limited to 'sys/src/cmd/fossil/periodic.c')
-rw-r--r-- | sys/src/cmd/fossil/periodic.c | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/sys/src/cmd/fossil/periodic.c b/sys/src/cmd/fossil/periodic.c deleted file mode 100644 index 8a0c20843..000000000 --- a/sys/src/cmd/fossil/periodic.c +++ /dev/null @@ -1,84 +0,0 @@ -#include "stdinc.h" -#include "dat.h" -#include "fns.h" -#include "error.h" - -struct Periodic { - VtLock *lk; - int die; /* flag: quit if set */ - void (*f)(void*); /* call this each period */ - void *a; /* argument to f */ - int msec; /* period */ -}; - -static void periodicThread(void *a); - -Periodic * -periodicAlloc(void (*f)(void*), void *a, int msec) -{ - Periodic *p; - - p = vtMemAllocZ(sizeof(Periodic)); - p->lk = vtLockAlloc(); - p->f = f; - p->a = a; - p->msec = msec; - if(p->msec < 10) - p->msec = 10; - - vtThread(periodicThread, p); - return p; -} - -void -periodicKill(Periodic *p) -{ - if(p == nil) - return; - vtLock(p->lk); - p->die = 1; - vtUnlock(p->lk); -} - -static void -periodicFree(Periodic *p) -{ - vtLockFree(p->lk); - vtMemFree(p); -} - -static void -periodicThread(void *a) -{ - Periodic *p = a; - vlong t, ct, ts; /* times in ms. */ - - vtThreadSetName("periodic"); - - ct = nsec() / 1000000; - t = ct + p->msec; /* call p->f at or after this time */ - - for(;;){ - ts = t - ct; /* ms. to next cycle's start */ - if(ts > 1000) - ts = 1000; /* bound sleep duration */ - if(ts > 0) - sleep(ts); /* wait for cycle's start */ - - vtLock(p->lk); - if(p->die){ - vtUnlock(p->lk); - break; - } - ct = nsec() / 1000000; - if(t <= ct){ /* due to call p->f? */ - p->f(p->a); - ct = nsec() / 1000000; - while(t <= ct) /* advance t to future cycle start */ - t += p->msec; - } - vtUnlock(p->lk); - } - periodicFree(p); -} - |