This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

yet another stack saving scheme


This scheme is much more reasonable than my last idea :-)

I have a couple of places in my code that get invoked intermittantly
where stack usage is high and maximum stack usage is hard to estimate
with great confidence.

When the threads go back to "idle/waiting" mode, stack usage is minimal
and it is relatively straightforward to determine the precise amount of
stack usage.

One way to deal with this is to dynamically allocate memory for a new
stack and switch to that stack for the duration of the operation that
takes a lot of stack.

With eCos the most reasonable way to do this would be to create a new
thread with a suitably large stack, run the operation in question on
that thread and free up the thread/stack afterwards.

Wrapping this up in a nice fn should be relatively easy:

// returns true if stack could be allocated and fn was run
bool moreStack(int bytes, void (*fn)());

void foo()
{
	// do stack intensive stuff here
}

void loop()
{
	for (;;)
	{
		// wait for more to do.
		wait();

		// processing
		if (!moreStack(10000, foo))
		{
			// application needs to decide what 
			// should happen in this case.
			// sleep + retry?
		}	
	}
}


-- 
Øyvind Harboe
http://www.zylin.com



--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]