[MPlayer-cvslog] r33101 - trunk/mp_fifo.c
reimar
subversion at mplayerhq.hu
Thu Mar 24 22:56:34 CET 2011
Author: reimar
Date: Thu Mar 24 22:56:34 2011
New Revision: 33101
Log:
Change fifo to not waste one entry needlessly.
Modified:
trunk/mp_fifo.c
Modified: trunk/mp_fifo.c
==============================================================================
--- trunk/mp_fifo.c Thu Mar 24 21:25:45 2011 (r33100)
+++ trunk/mp_fifo.c Thu Mar 24 22:56:34 2011 (r33101)
@@ -24,12 +24,11 @@
int key_fifo_size = 7;
static int *key_fifo_data = NULL;
-static int key_fifo_read=0;
-static int key_fifo_write=0;
+static unsigned key_fifo_read=0;
+static unsigned key_fifo_write=0;
static void mplayer_put_key_internal(int code){
- int fifo_free = key_fifo_read - key_fifo_write - 1;
- if (fifo_free < 0) fifo_free += key_fifo_size;
+ int fifo_free = key_fifo_read + key_fifo_size - key_fifo_write;
// printf("mplayer_put_key(%d)\n",code);
if (key_fifo_data == NULL)
key_fifo_data = malloc(key_fifo_size * sizeof(int));
@@ -37,8 +36,8 @@ static void mplayer_put_key_internal(int
// reserve some space for key release events to avoid stuck keys
if((code & MP_KEY_DOWN) && fifo_free < (key_fifo_size >> 1))
return;
- key_fifo_data[key_fifo_write]=code;
- key_fifo_write=(key_fifo_write+1)%key_fifo_size;
+ key_fifo_data[key_fifo_write % key_fifo_size]=code;
+ key_fifo_write++;
}
int mplayer_get_key(int fd){
@@ -47,8 +46,8 @@ int mplayer_get_key(int fd){
if (key_fifo_data == NULL)
return MP_INPUT_NOTHING;
if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING;
- key=key_fifo_data[key_fifo_read];
- key_fifo_read=(key_fifo_read+1)%key_fifo_size;
+ key=key_fifo_data[key_fifo_read % key_fifo_size];
+ key_fifo_read++;
// printf("mplayer_get_key => %d\n",key);
return key;
}
More information about the MPlayer-cvslog
mailing list