public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Nick Garnett <nickg@calivar.com>
To: ecos-discuss@ecos.sourceware.org
Subject: Re: [ECOS] timed wait for cyg_io_read
Date: Tue, 31 May 2016 09:19:00 -0000	[thread overview]
Message-ID: <574D55CD.8080301@calivar.com> (raw)
In-Reply-To: <07FFDDED6CBCCE4E9FBD46AEC3EBFD4F02C5069C@exchange>



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

      parent reply	other threads:[~2016-05-31  9:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-27 20:59 Michael W. Ellis
2016-05-29 17:20 ` [ECOS] " Grant Edwards
2016-05-31  9:19 ` Nick Garnett [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=574D55CD.8080301@calivar.com \
    --to=nickg@calivar.com \
    --cc=ecos-discuss@ecos.sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).