# HG changeset patch # User reimar # Date 1151244236 0 # Node ID f6bd47b9ed4f4657bbf134c20c421a744e139245 # Parent 9634870ebe4c894b58762c5a4768e1af6c84c4c4 Make sure mp_input_read_key_code always sleeps. Avoids 100% CPU load during cache fill. diff -r 9634870ebe4c -r f6bd47b9ed4f input/input.c --- a/input/input.c Sun Jun 25 14:02:28 2006 +0000 +++ b/input/input.c Sun Jun 25 14:03:56 2006 +0000 @@ -914,11 +914,14 @@ fd_set fds; struct timeval tv,*time_val; #endif - int i,n=0,max_fd = 0; + int i,n=0,max_fd = 0, did_sleep = 0; static int last_loop = 0; if(num_key_fd == 0) + { + usec_sleep(time * 1000); return MP_INPUT_NOTHING; + } #ifndef HAVE_NO_POSIX_SELECT FD_ZERO(&fds); @@ -940,9 +943,6 @@ n++; } - if(num_key_fd == 0) - return MP_INPUT_NOTHING; - #ifndef HAVE_NO_POSIX_SELECT // if we have fd's without MP_FD_NO_SELECT flag, call select(): if(n>0){ @@ -962,6 +962,7 @@ } break; } + did_sleep = 1; } #endif @@ -984,6 +985,7 @@ code = getch2(time); if(code < 0) code = MP_INPUT_NOTHING; + did_sleep = 1; } else code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd); @@ -998,6 +1000,8 @@ key_fds[i].flags |= MP_FD_DEAD; } } + if (!did_sleep) + usec_sleep(time * 1000); return MP_INPUT_NOTHING; }