From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3967 invoked by alias); 31 May 2016 09:19:08 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 3955 invoked by uid 89); 31 May 2016 09:19:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_40,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=wake, expires, Wales, ECOS X-HELO: mail.calivar.com Received: from calivar.com (HELO mail.calivar.com) (88.97.108.23) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 31 May 2016 09:18:57 +0000 Received: by mail.calivar.com (Postfix, from userid 111) id E78E341E5C; Tue, 31 May 2016 10:18:53 +0100 (BST) Received: from [10.0.1.1] (daikon.calivar.com [10.0.1.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.calivar.com (Postfix) with ESMTPSA id 368BB41E5C for ; Tue, 31 May 2016 10:13:50 +0100 (BST) To: ecos-discuss@ecos.sourceware.org References: <07FFDDED6CBCCE4E9FBD46AEC3EBFD4F02C5069C@exchange> From: Nick Garnett Message-ID: <574D55CD.8080301@calivar.com> Date: Tue, 31 May 2016 09:19:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <07FFDDED6CBCCE4E9FBD46AEC3EBFD4F02C5069C@exchange> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Subject: Re: [ECOS] timed wait for cyg_io_read X-SW-Source: 2016-05/txt/msg00007.txt.bz2 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