diff options
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/common/io.c | 30 |
1 files changed, 21 insertions, 9 deletions
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) | |||
189 | #endif | 189 | #endif |
190 | 190 | ||
191 | /** Simulator I/O engine routines **/ | 191 | /** Simulator I/O engine routines **/ |
192 | #define IO_YIELD_THRESHOLD 512 | ||
193 | |||
192 | enum | 194 | enum |
193 | { | 195 | { |
194 | IO_READ, | 196 | IO_READ, |
@@ -198,11 +200,12 @@ enum | |||
198 | struct sim_io | 200 | struct sim_io |
199 | { | 201 | { |
200 | struct mutex sim_mutex; /* Rockbox mutex */ | 202 | struct mutex sim_mutex; /* Rockbox mutex */ |
201 | volatile int cmd; /* The command to perform */ | 203 | int cmd; /* The command to perform */ |
202 | volatile int ready; /* I/O ready flag - 1= ready */ | 204 | int ready; /* I/O ready flag - 1= ready */ |
203 | volatile int fd; /* The file to read/write */ | 205 | int fd; /* The file to read/write */ |
204 | void* volatile buf; /* The buffer to read/write */ | 206 | void *buf; /* The buffer to read/write */ |
205 | volatile size_t count; /* Number of bytes to read/write */ | 207 | size_t count; /* Number of bytes to read/write */ |
208 | size_t accum; /* Acculated bytes transferred */ | ||
206 | }; | 209 | }; |
207 | 210 | ||
208 | static struct sim_io io; | 211 | static struct sim_io io; |
@@ -211,16 +214,22 @@ int ata_init(void) | |||
211 | { | 214 | { |
212 | /* Initialize the rockbox kernel objects on a rockbox thread */ | 215 | /* Initialize the rockbox kernel objects on a rockbox thread */ |
213 | mutex_init(&io.sim_mutex); | 216 | mutex_init(&io.sim_mutex); |
217 | io.accum = 0; | ||
214 | return 1; | 218 | return 1; |
215 | } | 219 | } |
216 | 220 | ||
217 | static ssize_t io_trigger_and_wait(int cmd) | 221 | static ssize_t io_trigger_and_wait(int cmd) |
218 | { | 222 | { |
219 | void *mythread; | 223 | void *mythread = NULL; |
220 | ssize_t result; | 224 | ssize_t result; |
221 | 225 | ||
222 | /* Allow other rockbox threads to run */ | 226 | if (io.count > IO_YIELD_THRESHOLD || |
223 | mythread = thread_sdl_thread_unlock(); | 227 | (io.accum += io.count) >= IO_YIELD_THRESHOLD) |
228 | { | ||
229 | /* Allow other rockbox threads to run */ | ||
230 | io.accum = 0; | ||
231 | mythread = thread_sdl_thread_unlock(); | ||
232 | } | ||
224 | 233 | ||
225 | switch (cmd) | 234 | switch (cmd) |
226 | { | 235 | { |
@@ -233,7 +242,10 @@ static ssize_t io_trigger_and_wait(int cmd) | |||
233 | } | 242 | } |
234 | 243 | ||
235 | /* Regain our status as current */ | 244 | /* Regain our status as current */ |
236 | thread_sdl_thread_lock(mythread); | 245 | if (mythread != NULL) |
246 | { | ||
247 | thread_sdl_thread_lock(mythread); | ||
248 | } | ||
237 | 249 | ||
238 | return result; | 250 | return result; |
239 | } | 251 | } |