rtems-bsd-mutex: Update due to API changes

This commit is contained in:
Sebastian Huber 2015-07-24 10:42:35 +02:00
parent 3cb5e9ef6d
commit 07ff2c1910
3 changed files with 20 additions and 13 deletions

View File

@ -48,7 +48,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
typedef struct { typedef struct {
Thread_queue_Control queue; Thread_queue_Queue queue;
Thread_Control *owner; Thread_Control *owner;
int nest_level; int nest_level;
} rtems_bsd_mutex; } rtems_bsd_mutex;

View File

@ -122,7 +122,8 @@ rtems_bsd_mutex_trylock(struct lock_object *lock, rtems_bsd_mutex *m)
} }
void rtems_bsd_mutex_unlock_more(rtems_bsd_mutex *m, Thread_Control *owner, void rtems_bsd_mutex_unlock_more(rtems_bsd_mutex *m, Thread_Control *owner,
int keep_priority, RBTree_Node *first, ISR_lock_Context *lock_context); int keep_priority, Thread_queue_Heads *heads,
ISR_lock_Context *lock_context);
static inline void static inline void
rtems_bsd_mutex_unlock(rtems_bsd_mutex *m) rtems_bsd_mutex_unlock(rtems_bsd_mutex *m)
@ -139,7 +140,7 @@ rtems_bsd_mutex_unlock(rtems_bsd_mutex *m)
BSD_ASSERT(owner == _Thread_Executing); BSD_ASSERT(owner == _Thread_Executing);
if (__predict_true(nest_level == 0)) { if (__predict_true(nest_level == 0)) {
RBTree_Node *first; Thread_queue_Heads *heads;
int keep_priority; int keep_priority;
--owner->resource_count; --owner->resource_count;
@ -151,17 +152,17 @@ rtems_bsd_mutex_unlock(rtems_bsd_mutex *m)
*/ */
_Atomic_Fence( ATOMIC_ORDER_ACQ_REL ); _Atomic_Fence( ATOMIC_ORDER_ACQ_REL );
first = _RBTree_First(&m->queue.Queues.Priority, RBT_LEFT); heads = m->queue.heads;
keep_priority = _Thread_Owns_resources(owner) keep_priority = _Thread_Owns_resources(owner)
|| !owner->priority_restore_hint; || !owner->priority_restore_hint;
m->owner = NULL; m->owner = NULL;
if (__predict_true(first == NULL && keep_priority)) { if (__predict_true(heads == NULL && keep_priority)) {
_Thread_queue_Release(&m->queue, &lock_context); _Thread_queue_Release(&m->queue, &lock_context);
} else { } else {
rtems_bsd_mutex_unlock_more(m, owner, keep_priority, rtems_bsd_mutex_unlock_more(m, owner, keep_priority,
first, &lock_context); heads, &lock_context);
} }
} else { } else {
@ -188,7 +189,7 @@ rtems_bsd_mutex_recursed(rtems_bsd_mutex *m)
static inline void static inline void
rtems_bsd_mutex_destroy(struct lock_object *lock, rtems_bsd_mutex *m) rtems_bsd_mutex_destroy(struct lock_object *lock, rtems_bsd_mutex *m)
{ {
BSD_ASSERT(_RBTree_Is_empty(&m->queue.Queues.Priority)); BSD_ASSERT(m->queue.heads == NULL);
if (rtems_bsd_mutex_owned(m)) { if (rtems_bsd_mutex_owned(m)) {
m->nest_level = 0; m->nest_level = 0;

View File

@ -43,6 +43,8 @@
#include <rtems/score/schedulerimpl.h> #include <rtems/score/schedulerimpl.h>
#include <rtems/score/threadqimpl.h> #include <rtems/score/threadqimpl.h>
#define BSD_MUTEX_TQ_OPERATIONS &_Thread_queue_Operations_priority
void void
rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m, rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m,
Thread_Control *owner, Thread_Control *executing, Thread_Control *owner, Thread_Control *executing,
@ -58,7 +60,8 @@ rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m,
_Thread_Raise_priority(owner, executing->current_priority); _Thread_Raise_priority(owner, executing->current_priority);
++executing->resource_count; ++executing->resource_count;
_Thread_queue_Enqueue_critical(&m->queue, executing, _Thread_queue_Enqueue_critical(&m->queue,
BSD_MUTEX_TQ_OPERATIONS, executing,
STATES_WAITING_FOR_MUTEX, WATCHDOG_NO_TIMEOUT, 0, STATES_WAITING_FOR_MUTEX, WATCHDOG_NO_TIMEOUT, 0,
lock_context); lock_context);
} }
@ -66,15 +69,18 @@ rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m,
void void
rtems_bsd_mutex_unlock_more(rtems_bsd_mutex *m, Thread_Control *owner, rtems_bsd_mutex_unlock_more(rtems_bsd_mutex *m, Thread_Control *owner,
int keep_priority, RBTree_Node *first, ISR_lock_Context *lock_context) int keep_priority, Thread_queue_Heads *heads,
ISR_lock_Context *lock_context)
{ {
if (first != NULL) { if (heads != NULL) {
const Thread_queue_Operations *operations;
Thread_Control *new_owner; Thread_Control *new_owner;
new_owner = THREAD_RBTREE_NODE_TO_THREAD(first); operations = BSD_MUTEX_TQ_OPERATIONS;
new_owner = ( *operations->first )( heads );
m->owner = new_owner; m->owner = new_owner;
_Thread_queue_Extract_critical(&m->queue, new_owner, _Thread_queue_Extract_critical(&m->queue, operations,
lock_context); new_owner, lock_context);
} else { } else {
_Thread_queue_Release(&m->queue, lock_context); _Thread_queue_Release(&m->queue, lock_context);
} }