This is the mail archive of the ecos-discuss@sourceware.org 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: timed wait for cyg_io_read



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


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