timed wait for cyg_io_read

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

timed wait for cyg_io_read

Michael W. Ellis
Is there a way to do a timed wait for cyg_io_read?  I have a thread that
is blocking on cyg_io_read and I wish to signal the thread to exit in an
orderly manner (using an event flag).  I know that I can make
cyg_io_read non-blocking and poll cyg_io_read and cyg_flag_poll but this
would burn a lot of cycles doing nothing.

Michael

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

Reply | Threaded
Open this post in threaded view
|

Re: timed wait for cyg_io_read

Grant Edwards-6
On 2016-05-27, Michael W. Ellis <[hidden email]> wrote:

> Is there a way to do a timed wait for cyg_io_read?

FAIK, there never used to be any "built-in" way to do that.  I ended
up adding timeout settings to my io drivers.

> I have a thread that is blocking on cyg_io_read and I wish to signal
> the thread to exit in an orderly manner (using an event flag).  I
> know that I can make cyg_io_read non-blocking and poll cyg_io_read
> and cyg_flag_poll but this would burn a lot of cycles doing nothing.

I think there used to be a way to explicity wakeup a thread that was
blocked on something, but I don't remember the details...

--
Grant




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

Reply | Threaded
Open this post in threaded view
|

Re: timed wait for cyg_io_read

Nick Garnett-2
In reply to this post by Michael W. Ellis


On 27/05/16 22:00, Michael W. Ellis wrote:
> Is there a way to do a timed wait for cyg_io_read?  I have a thread that
> is blocking on cyg_io_read and I wish to signal the thread to exit in an
> orderly manner (using an event flag).  I know that I can make
> cyg_io_read non-blocking and poll cyg_io_read and cyg_flag_poll but this
> would burn a lot of cycles doing nothing.

The eCos IO API largely follows the POSIX/UNIX model and therefore does
not contain any calls that include timeouts. Instead there is a
mechanism to allow you to set up an alarm and then break the thread out
of its wait if the alarm expires.

The general approach is to set up an alarm just before calling calling
cyg_io_read(). Pass it the thread's handle as the data argument. If the
alarm expires and calls its function, call
cyg_thread_release(thread_handle) in there. When cyg_io_read() returns,
its return code will be -EINTR if it was timed out, and ENOERR if it
suceeded. Regardless, call cyg_alarm_delete() immediately on return.

You could wrap all of this into a simple function that you can call from
your application.

However, if all you need to do is to wake the thread up so it can detect
when to terminate, then the timeout is probably unnecessary. You can
just call cyg_thread_release() on the thread when you set the
"terminate" event flag.

--
Nick Garnett                                         Kernel Architect
eCosCentric Limited    http://www.eCosCentric.com    The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.        +44 1223 245571
Registered in England and Wales:                      Reg No: 4422071

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