From 994a4923e18255404f60a781520c067c76673562 Mon Sep 17 00:00:00 2001 From: kugel Date: Fri, 16 Apr 2010 22:11:40 +0000 Subject: [PATCH] Convert macro to inline function and move it into .c file. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25658 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/kernel.h | 8 -------- firmware/kernel.c | 36 +++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h index 734235aa2..c4d661f21 100644 --- a/firmware/export/kernel.h +++ b/firmware/export/kernel.h @@ -137,14 +137,6 @@ struct event_queue IF_COP( struct corelock cl; ) /* multiprocessor sync */ }; -#ifdef HAVE_PRIORITY_SCHEDULING -#define MUTEX_SET_THREAD(m, t) ((m)->blocker.thread = (t)) -#define MUTEX_GET_THREAD(m) ((m)->blocker.thread) -#else -#define MUTEX_SET_THREAD(m, t) ((m)->thread = (t)) -#define MUTEX_GET_THREAD(m) ((m)->thread) -#endif - struct mutex { struct thread_entry *queue; /* waiter list */ diff --git a/firmware/kernel.c b/firmware/kernel.c index 27f3b0d08..d28e508a7 100644 --- a/firmware/kernel.c +++ b/firmware/kernel.c @@ -857,6 +857,28 @@ int queue_broadcast(long id, intptr_t data) * Simple mutex functions ;) ****************************************************************************/ +static inline void mutex_set_thread(struct mutex *mtx, struct thread_entry *td) + __attribute__((always_inline)); +static inline void mutex_set_thread(struct mutex *mtx, struct thread_entry *td) +{ +#ifdef HAVE_PRIORITY_SCHEDULING + mtx->blocker.thread = td; +#else + mtx->thread = td; +#endif +} + +static inline struct thread_entry* mutex_get_thread(struct mutex *mtx) + __attribute__((always_inline)); +static inline struct thread_entry* mutex_get_thread(struct mutex *mtx) +{ +#ifdef HAVE_PRIORITY_SCHEDULING + return mtx->blocker.thread; +#else + return mtx->thread; +#endif +} + /* Initialize a mutex object - call before any use and do not call again once * the object is available to other threads */ void mutex_init(struct mutex *m) @@ -865,7 +887,7 @@ void mutex_init(struct mutex *m) m->queue = NULL; m->count = 0; m->locked = 0; - MUTEX_SET_THREAD(m, NULL); + mutex_set_thread(m, NULL); #ifdef HAVE_PRIORITY_SCHEDULING m->blocker.priority = PRIORITY_IDLE; m->blocker.wakeup_protocol = wakeup_priority_protocol_transfer; @@ -878,7 +900,7 @@ void mutex_lock(struct mutex *m) { struct thread_entry *current = thread_id_entry(THREAD_ID_CURRENT); - if(current == MUTEX_GET_THREAD(m)) + if(current == mutex_get_thread(m)) { /* current thread already owns this mutex */ m->count++; @@ -891,7 +913,7 @@ void mutex_lock(struct mutex *m) if(LIKELY(m->locked == 0)) { /* lock is open */ - MUTEX_SET_THREAD(m, current); + mutex_set_thread(m, current); m->locked = 1; corelock_unlock(&m->cl); return; @@ -915,9 +937,9 @@ void mutex_lock(struct mutex *m) void mutex_unlock(struct mutex *m) { /* unlocker not being the owner is an unlocking violation */ - KERNEL_ASSERT(MUTEX_GET_THREAD(m) == thread_id_entry(THREAD_ID_CURRENT), + KERNEL_ASSERT(mutex_get_thread(m) == thread_id_entry(THREAD_ID_CURRENT), "mutex_unlock->wrong thread (%s != %s)\n", - MUTEX_GET_THREAD(m)->name, + mutex_get_thread(m)->name, thread_id_entry(THREAD_ID_CURRENT)->name); if(m->count > 0) @@ -934,7 +956,7 @@ void mutex_unlock(struct mutex *m) if(LIKELY(m->queue == NULL)) { /* no threads waiting - open the lock */ - MUTEX_SET_THREAD(m, NULL); + mutex_set_thread(m, NULL); m->locked = 0; corelock_unlock(&m->cl); return; @@ -945,7 +967,7 @@ void mutex_unlock(struct mutex *m) /* Tranfer of owning thread is handled in the wakeup protocol * if priorities are enabled otherwise just set it from the * queue head. */ - IFN_PRIO( MUTEX_SET_THREAD(m, m->queue); ) + IFN_PRIO( mutex_set_thread(m, m->queue); ) IF_PRIO( unsigned int result = ) wakeup_thread(&m->queue); restore_irq(oldlevel); -- 2.11.4.GIT