aboutsummaryrefslogtreecommitdiff
path: root/miscutils/less.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-08 17:52:36 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-08 17:52:36 +0000
commit18d6fc1a506dfe717cb5de433870dd6eca46270b (patch)
tree6576dbba1fa94d12a01f4dd8c9fcd146e7ba8c64 /miscutils/less.c
parent5c1de367020ed4c05a094ffa3cd2781205db03c1 (diff)
downloadbusybox-w32-18d6fc1a506dfe717cb5de433870dd6eca46270b.tar.gz
busybox-w32-18d6fc1a506dfe717cb5de433870dd6eca46270b.tar.bz2
busybox-w32-18d6fc1a506dfe717cb5de433870dd6eca46270b.zip
less: yet another attempt to make search better
Diffstat (limited to 'miscutils/less.c')
-rw-r--r--miscutils/less.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index b0e2754f8..207f5864e 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -21,6 +21,8 @@
21 * redirected input has been read from stdin 21 * redirected input has been read from stdin
22 */ 22 */
23 23
24#include <sched.h> /* sched_yield() */
25
24#include "busybox.h" 26#include "busybox.h"
25#if ENABLE_FEATURE_LESS_REGEXP 27#if ENABLE_FEATURE_LESS_REGEXP
26#include "xregex.h" 28#include "xregex.h"
@@ -200,16 +202,30 @@ static void read_lines(void)
200 char c; 202 char c;
201 /* if no unprocessed chars left, eat more */ 203 /* if no unprocessed chars left, eat more */
202 if (readpos >= readeof) { 204 if (readpos >= readeof) {
205 smallint yielded = 0;
206
203 ndelay_on(0); 207 ndelay_on(0);
208 read_again:
204 eof_error = safe_read(0, readbuf, sizeof(readbuf)); 209 eof_error = safe_read(0, readbuf, sizeof(readbuf));
205 ndelay_off(0);
206 readpos = 0; 210 readpos = 0;
207 readeof = eof_error; 211 readeof = eof_error;
208 if (eof_error < 0) { 212 if (eof_error < 0) {
213 if (errno == EAGAIN && !yielded) {
214 /* We can hit EAGAIN while searching for regexp match.
215 * Yield is not 100% reliable solution in general,
216 * but for less it should be good enough.
217 * We give stdin supplier some CPU time to produce more.
218 * We do it just once. */
219 sched_yield();
220 yielded = 1;
221 goto read_again;
222 }
209 readeof = 0; 223 readeof = 0;
210 if (errno != EAGAIN) 224 if (errno != EAGAIN)
211 print_statusline("read error"); 225 print_statusline("read error");
212 } 226 }
227 ndelay_off(0);
228
213 if (eof_error <= 0) { 229 if (eof_error <= 0) {
214 goto reached_eof; 230 goto reached_eof;
215 } 231 }