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]

Re: How to reset the timeout on a thread waiting for a flag


Fabrice Gautier wrote:
-----Original Message-----
From: Jonathan Larmour [mailto:jifl@eCosCentric.com]
Sent: Monday, January 27, 2003 8:33 PM
To: Fabrice Gautier
Cc: Ecos-List (E-mail)
Subject: Re: [ECOS] How to reset the timeout on a thread waiting for a
flag


Fabrice Gautier wrote:

Hi,

Here is what i want to do:

I have a thread starting an operation and waiting for it to finish. The operation result in a series of interrupts.
The thread waits on a flag, and the ISR will eventually set
the flag when the operation is done, to wake up the thread.
DSR I hope :-).

Well... actually no... Is it safe do that in the ISR? I guess not... but i'm
not sure why. How does the cyg_flag_set function blocks?
It's not to do with blocking or not. It's that it may interrupt another kernel operation and leave the scheduler in an undefined state.

Anyway I''m doing it and in my case it seems to work fine, but I dont set
the flag anywhere else.
When you set the flag and someone's waiting on it you could well screw up the scheduler's state if it was in the kernel in some other thread. Sure 99% of the time it'll work because other threads won't be in the kernel, and the other 1% will hose the system.

If I dont want to implement a DSR, what would be the best way to implement
this ?
Polled shared state marked volatile - that's about it for useful alternatives.

Remember that DSRs are sort of equivalent to ISRs in many other OS's - they often blip the global interrupt flag instead of just blipping a scheduler lock.

I also want a timeout. But not a total timeout value for the total operation
but a timeout based on the interrupt activity. ie if there
is no more

interrupt for 1/2sec then i want to timeout.

So is ther any function to reset the thread timer.
Not exported in C (nor should it be really). You could look in the C++ headers, but there be dragons.

I try to add a cyg_thread_set_delay(thread, delay) function that call
Cyg_Thread::set_timer but I'm not sure it's working... I actually have to
implement a case to test it...
That should be enough. But only from a DSR again :-).

But I would imagine an alternative way to do this is to use two flag bits with cyg_flag_timed_wait() - one bit set on each interrupt, and the other when the operation completes. It's used with CYG_FLAG_WAITMODE_OR.

Then when the thread wakes up, it checks why it woke up, and if necessary waits again for the operation to complete.
Yes... that would do... the only is that you would have to wake up the
thread for each interrupt in the other case you only wake up once...
Well, eCos is lightweight enough that's not likely to be much overhead.

Jifl
--
eCosCentric       http://www.eCosCentric.com/       <info@eCosCentric.com>
--[ "You can complain because roses have thorns, or you ]--
--[  can rejoice because thorns have roses." -Lincoln   ]-- Opinions==mine


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


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