From 6a05883239e3fa0569ce7ac90910c6ae8f3675c2 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Mon, 3 Dec 2007 15:33:12 +0000 Subject: Simulate the effects of sector caching a bit. Bypass I/O yield if a byte counter hasn't reached a certain threshold. Can be dialed-in by changing a #define. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15871 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/common/io.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'uisimulator/common/io.c') diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index 62d869f3fc..822a43b63d 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c @@ -189,6 +189,8 @@ static unsigned int rockbox2sim(int opt) #endif /** Simulator I/O engine routines **/ +#define IO_YIELD_THRESHOLD 512 + enum { IO_READ, @@ -198,11 +200,12 @@ enum struct sim_io { struct mutex sim_mutex; /* Rockbox mutex */ - volatile int cmd; /* The command to perform */ - volatile int ready; /* I/O ready flag - 1= ready */ - volatile int fd; /* The file to read/write */ - void* volatile buf; /* The buffer to read/write */ - volatile size_t count; /* Number of bytes to read/write */ + int cmd; /* The command to perform */ + int ready; /* I/O ready flag - 1= ready */ + int fd; /* The file to read/write */ + void *buf; /* The buffer to read/write */ + size_t count; /* Number of bytes to read/write */ + size_t accum; /* Acculated bytes transferred */ }; static struct sim_io io; @@ -211,16 +214,22 @@ int ata_init(void) { /* Initialize the rockbox kernel objects on a rockbox thread */ mutex_init(&io.sim_mutex); + io.accum = 0; return 1; } static ssize_t io_trigger_and_wait(int cmd) { - void *mythread; + void *mythread = NULL; ssize_t result; - /* Allow other rockbox threads to run */ - mythread = thread_sdl_thread_unlock(); + if (io.count > IO_YIELD_THRESHOLD || + (io.accum += io.count) >= IO_YIELD_THRESHOLD) + { + /* Allow other rockbox threads to run */ + io.accum = 0; + mythread = thread_sdl_thread_unlock(); + } switch (cmd) { @@ -233,7 +242,10 @@ static ssize_t io_trigger_and_wait(int cmd) } /* Regain our status as current */ - thread_sdl_thread_lock(mythread); + if (mythread != NULL) + { + thread_sdl_thread_lock(mythread); + } return result; } -- cgit v1.2.3