From f0a64cb33f808dabc745c8810bc371cc57575cd3 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 27 Mar 2009 17:25:09 +0000 Subject: [PATCH] Added some Tock support functions for allocating and freeing workspaces It turns out that we weren't freeing workspaces, and neither was CCSP, and hence in long-running programs we were leaking memory at a crazy rate. This fix works, but really this stuff should be in CCSP (Currently, it doesn't seem to have a ProcFree function...) --- support/tock_support_cif.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/support/tock_support_cif.h b/support/tock_support_cif.h index 7e5902c..517fb60 100644 --- a/support/tock_support_cif.h +++ b/support/tock_support_cif.h @@ -40,6 +40,31 @@ #include +//{{{ Process starting and stopping + +// This is a version of the CCSP function that uses malloc. We should replace this eventually, preferably using LightProcAlloc. +static inline Workspace TockProcAlloc (Workspace wptr, word args, word stack) +{ + Workspace ws; + word words = WORKSPACE_SIZE (args, stack); + + ws = malloc(words*sizeof(word)); + + ws += CIF_PROCESS_WORDS; + ws[BarrierPtr] = (word) NULL; + ws[StackPtr] = words - CIF_PROCESS_WORDS; + + return ws; +} + +//The corresponding version that frees the workspace +static inline void TockProcFree(Workspace wptr, Workspace ws) +{ + ws -= CIF_PROCESS_WORDS; + free(ws); +} +//}}} + //{{{ channel array initialisation static inline void tock_init_chan_array (Channel *, Channel **, int) occam_unused; static inline void tock_init_chan_array (Channel *pointTo, Channel **pointFrom, int count) {