rtems-bsd-mutex: Use _Thread_queue_Surrender()

This commit is contained in:
Sebastian Huber 2016-08-11 09:01:42 +02:00
parent 26a8cee1c3
commit 691ed15cba
2 changed files with 8 additions and 38 deletions

View File

@ -48,11 +48,15 @@
#include <rtems/bsd/sys/lock.h>
#include <rtems/score/threadimpl.h>
#include <rtems/score/threadqimpl.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define RTEMS_BSD_MUTEX_TQ_OPERATIONS \
&_Thread_queue_Operations_priority_inherit
static inline void
rtems_bsd_mutex_init(struct lock_object *lock, rtems_bsd_mutex *m,
struct lock_class *class, const char *name, const char *type, int flags)
@ -122,10 +126,6 @@ rtems_bsd_mutex_trylock(struct lock_object *lock, rtems_bsd_mutex *m)
return (success);
}
void rtems_bsd_mutex_unlock_more(rtems_bsd_mutex *m, Thread_Control *owner,
int keep_priority, Thread_queue_Heads *heads,
Thread_queue_Context *queue_context);
static inline void
rtems_bsd_mutex_unlock(rtems_bsd_mutex *m)
{
@ -163,8 +163,9 @@ rtems_bsd_mutex_unlock(rtems_bsd_mutex *m)
if (__predict_true(heads == NULL && keep_priority)) {
_Thread_queue_Release(&m->queue, &queue_context.Lock_context);
} else {
rtems_bsd_mutex_unlock_more(m, owner, keep_priority,
heads, &queue_context);
_Thread_queue_Surrender(&m->queue.Queue,
RTEMS_BSD_MUTEX_TQ_OPERATIONS, heads, owner,
keep_priority, &queue_context);
}
} else {

View File

@ -41,9 +41,6 @@
#include <machine/rtems-bsd-muteximpl.h>
#include <rtems/score/schedulerimpl.h>
#include <rtems/score/threadqimpl.h>
#define BSD_MUTEX_TQ_OPERATIONS &_Thread_queue_Operations_priority_inherit
void
rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m,
@ -56,40 +53,12 @@ rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m,
_Thread_queue_Release(&m->queue, &queue_context->Lock_context);
} else {
++executing->resource_count;
_Thread_queue_Context_set_expected_level(queue_context, 1);
_Thread_queue_Context_set_no_timeout(queue_context);
_Thread_queue_Context_set_deadlock_callout(queue_context,
_Thread_queue_Deadlock_fatal);
_Thread_queue_Enqueue_critical(&m->queue.Queue,
BSD_MUTEX_TQ_OPERATIONS, executing,
RTEMS_BSD_MUTEX_TQ_OPERATIONS, executing,
STATES_WAITING_FOR_SYS_LOCK_MUTEX, queue_context);
}
}
void
rtems_bsd_mutex_unlock_more(rtems_bsd_mutex *m, Thread_Control *owner,
int keep_priority, Thread_queue_Heads *heads,
Thread_queue_Context *queue_context)
{
if (heads != NULL) {
const Thread_queue_Operations *operations;
Thread_Control *new_owner;
operations = BSD_MUTEX_TQ_OPERATIONS;
new_owner = ( *operations->first )( heads );
m->queue.Queue.owner = new_owner;
_Thread_queue_Extract_critical(&m->queue.Queue, operations,
new_owner, queue_context);
} else {
_Thread_queue_Release(&m->queue, &queue_context->Lock_context);
}
if (!keep_priority) {
Per_CPU_Control *cpu_self;
cpu_self = _Thread_Dispatch_disable();
_Thread_Restore_priority(owner);
_Thread_Dispatch_enable(cpu_self);
}
}