This is the mail archive of the
mailing list for the eCos project.
Re: blocking for n events
- From: Andrew Lunn <andrew at lunn dot ch>
- To: Heiko Panther <heiko dot panther at web dot de>
- Cc: ecos-discuss at sources dot redhat dot com
- Date: Thu, 8 Dec 2005 19:48:29 +0100
- Subject: Re: [ECOS] blocking for n events
- References: <43987C53.email@example.com>
On Thu, Dec 08, 2005 at 10:32:51AM -0800, Heiko Panther wrote:
> I have the following interesting synchronization problem.
> I am triggering a random number of transaction. Only after the last one I will
> know how many I actually triggered. Then I need to wait for all of them to complete.
> In my imagination, I have a semaphore that I can decrease by n, and then wake up
> when it was posted n times and so is back to 0.
> However, eCos semaphores don't work that way, and maybe they seldomly do. So, do
> you have a suggestion what to do instead? As I said, I don't have the number of
> transcations before, so I can't just set a variable and decrease it from the
> callback, and then trigger an event flag.
> What I could do is to wait for the semaphore in a for() loop, but I want to
> avoid the overhead of task switches.
How about a eCos counter, an eCos alarm and a semaphore.
At the beginning you set the counter to zero. You then start each
transaction. When each transaction is completed it calls the
cyg_counter_tick() on the counter.
You create an alarm based on the counter. When you have started the
last transaction and know the number of transactions you then set an
alarm for that number of ticks. You then wait on a semaphore. When all
the transactions have finished and the counter hits the alarm value,
the alarm fires, posts on the semaphore and wakes you up.
There might be a clever way to use a condition variable as well.....
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss