public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] timed wait for cyg_io_read
@ 2016-05-27 20:59 Michael W. Ellis
  2016-05-29 17:20 ` [ECOS] " Grant Edwards
  2016-05-31  9:19 ` [ECOS] " Nick Garnett
  0 siblings, 2 replies; 3+ messages in thread
From: Michael W. Ellis @ 2016-05-27 20:59 UTC (permalink / raw)
  To: ecos-discuss

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ECOS] Re: timed wait for cyg_io_read
  2016-05-27 20:59 [ECOS] timed wait for cyg_io_read Michael W. Ellis
@ 2016-05-29 17:20 ` Grant Edwards
  2016-05-31  9:19 ` [ECOS] " Nick Garnett
  1 sibling, 0 replies; 3+ messages in thread
From: Grant Edwards @ 2016-05-29 17:20 UTC (permalink / raw)
  To: ecos-discuss

On 2016-05-27, Michael W. Ellis <mellis@pesa.com> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] timed wait for cyg_io_read
  2016-05-27 20:59 [ECOS] timed wait for cyg_io_read Michael W. Ellis
  2016-05-29 17:20 ` [ECOS] " Grant Edwards
@ 2016-05-31  9:19 ` Nick Garnett
  1 sibling, 0 replies; 3+ messages in thread
From: Nick Garnett @ 2016-05-31  9:19 UTC (permalink / raw)
  To: ecos-discuss



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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-05-31  9:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-27 20:59 [ECOS] timed wait for cyg_io_read Michael W. Ellis
2016-05-29 17:20 ` [ECOS] " Grant Edwards
2016-05-31  9:19 ` [ECOS] " Nick Garnett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).