This is the mail archive of the 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]

Re: blocking for n events

On Thu, Dec 08, 2005 at 10:32:51AM -0800, Heiko Panther wrote:
> Hi-
> 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:
and search the list archive:

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