<div dir="ltr"><div dir="ltr"><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 8, 2020 at 12:15 PM Tomas Hajny <<a href="mailto:XHajT03@hajny.biz">XHajT03@hajny.biz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2020-06-08 11:39, Michael Van Canneyt wrote:<br>
> On Mon, 8 Jun 2020, Christo Crause via fpc-devel wrote:<br>
.<br>
.<br>
>> Thanks for your response Michael. Using InOutFunc to also flush the <br>
>> output<br>
>> buffer will work, but that seems inefficient, since the flush needs to <br>
>> wait<br>
>> until the transmit buffer is empty (at slow UART speeds this could<br>
>> potentially take several ms to complete). Is there a specific reason <br>
>> why<br>
>> the RTL Flush procedure does not call the FlushFunc method?<br>
> <br>
> I checked; That code is so old, no idea.<br>
> <br>
> From what I can see the flush code could be changed to<br>
> <br>
> if Assigned((TextRec(t).FlushFunc) then<br>
> FileFunc(TextRec(t).FlushFunc)(TextRec(t))<br>
> else<br>
> FileFunc(TextRec(t).InOutFunc)(TextRec(t));<br>
> <br>
> But keep in mind that the InoutFunc() is only called when actually <br>
> writing<br>
> data, meaning: when the internal text buffer is full or on a terminal <br>
> with<br>
> every writeln(), so I don't think it is inefficient. Writeln() will do <br>
> a<br>
> flush. Whether this happens in .InOutFunc or .FlushFunc is largely <br>
> irrelevant.<br>
<br>
The question is whether the potential change would make any difference. <br>
IMHO, the important points are:<br>
<br>
1) The point of flushing is making sure the I/O is really performed (the <br>
data are sent to the operating system _and_ flushed from internal <br>
buffers of the underlying operating system / platform). Doing the latter <br>
without the former makes no sense.<br>
<br>
2) From semantic point of view, all data should be sent to the final <br>
place (block device / console / ...) before the call to Flush is <br>
finished (otherwise the following actions may have incorrect results - <br>
the program might finish before all data are transmitted, other I/O may <br>
be invoked, etc.).<br>
<br>
From this point of view, the proposed change would only lead to code <br>
duplication between FlushFunc and InOutFunc and / or to increased code - <br>
e.g. checking FlushFunc being nil before calling InOutFunc just to call <br>
InOutFunc (or to perform functionality currently included in InOutFunc) <br>
from within FlushFunc anyway.<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel" rel="noreferrer" target="_blank"></a></blockquote><div><br></div><div>Tomas and Michael, thank you for this discussion. I'm starting to think the use case I'm considering is perhaps not covered by the current design. At the moment I directly call the OS flush function before putting the cpu to sleep and that works; I was just wondering if there is a Pascal way to accomplish this so that a user doesn't have to remember to call a nonstandard function when a Flush function already exist in the RTL.</div></div></div>