diff options
| author | Michael Sevakis <jethead71@rockbox.org> | 2007-03-09 08:03:18 +0000 |
|---|---|---|
| committer | Michael Sevakis <jethead71@rockbox.org> | 2007-03-09 08:03:18 +0000 |
| commit | dee43ece2086e15894934b754e47cb7ce5882cda (patch) | |
| tree | 9238a5c80fe4382975387ec90eca61bda8d4ed8f /firmware/kernel.c | |
| parent | f4b83e68594f076cdfe510cd2e23b7f57fd158b5 (diff) | |
| download | rockbox-dee43ece2086e15894934b754e47cb7ce5882cda.zip rockbox-dee43ece2086e15894934b754e47cb7ce5882cda.tar.gz rockbox-dee43ece2086e15894934b754e47cb7ce5882cda.tar.bz2 rockbox-dee43ece2086e15894934b754e47cb7ce5882cda.tar.xz | |
Put an end to priority inversion in the ata driver. Gave up trying to have fully atomic dual use mutexes so just replaced the ata driver locking with spins. Maybe I'll have better luck later. Things should run smoothly with database updates and such happening in the background.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12688 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/kernel.c')
| -rw-r--r-- | firmware/kernel.c | 79 |
1 files changed, 52 insertions, 27 deletions
diff --git a/firmware/kernel.c b/firmware/kernel.c index 313530f..db7249f 100644 --- a/firmware/kernel.c +++ b/firmware/kernel.c @@ -656,48 +656,73 @@ void mutex_init(struct mutex *m) m->thread = NULL; } -#ifdef CPU_PP -/* PortalPlayer chips have 2 cores, therefore need atomic mutexes */ +/* PortalPlayer chips have 2 cores, therefore need atomic mutexes + * Just use it for ARM, Coldfire and whatever else well...why not? + */ -static inline bool test_and_set(bool *x, bool v) -{ - asm volatile ( - "swpb %0, %0, [%1]\n" - : "+r"(v) - : "r"(x) - ); - return v; -} +/* Macros generate better code than an inline function is this case */ +#if defined (CPU_PP) || defined (CPU_ARM) +#define test_and_set(x_, v_) \ +({ \ + uint32_t old; \ + asm volatile ( \ + "swpb %[old], %[v], [%[x]] \r\n" \ + : [old]"=r"(old) \ + : [v]"r"((uint32_t)v_), [x]"r"((uint32_t *)x_) \ + ); \ + old; \ + }) +#elif defined (CPU_COLDFIRE) +#define test_and_set(x_, v_) \ +({ \ + uint8_t old; \ + asm volatile ( \ + "bset.l %[v], (%[x]) \r\n" \ + "sne.b %[old] \r\n" \ + : [old]"=d,d"(old) \ + : [v]"i,d"((uint32_t)v_), [x]"a,a"((uint32_t *)x_) \ + ); \ + old; \ + }) +#else +/* default for no asm version */ +#define test_and_set(x_, v_) \ +({ \ + uint32_t old = *(uint32_t *)x_; \ + *(uint32_t *)x_ = v_; \ + old; \ + }) +#endif void mutex_lock(struct mutex *m) { - if (test_and_set(&m->locked,true)) + if (test_and_set(&m->locked, 1)) { /* Wait until the lock is open... */ block_thread(&m->thread); } } -#else -void mutex_lock(struct mutex *m) +void mutex_unlock(struct mutex *m) { - if (m->locked) + if (m->thread == NULL) + m->locked = 0; + else + wakeup_thread(&m->thread); +} + +void spinlock_lock(struct mutex *m) +{ + while (test_and_set(&m->locked, 1)) { - /* Wait until the lock is open... */ - block_thread(&m->thread); + /* wait until the lock is open... */ + switch_thread(true, NULL); } - - /* ...and lock it */ - m->locked = true; } -#endif -void mutex_unlock(struct mutex *m) +void spinlock_unlock(struct mutex *m) { - if (m->thread == NULL) - m->locked = false; - else - wakeup_thread(&m->thread); + m->locked = 0; } -#endif +#endif /* ndef SIMULATOR */ |