mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
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
This commit is contained in:
parent
d9af87c40b
commit
c31fdeffdc
2 changed files with 29 additions and 15 deletions
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue