mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-13 08:29:55 +08:00
rtems-bsd-mutex: Update due to API changes
This commit is contained in:
parent
3cb5e9ef6d
commit
07ff2c1910
@ -48,7 +48,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct {
|
||||
Thread_queue_Control queue;
|
||||
Thread_queue_Queue queue;
|
||||
Thread_Control *owner;
|
||||
int nest_level;
|
||||
} rtems_bsd_mutex;
|
||||
|
@ -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,
|
||||
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
|
||||
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);
|
||||
|
||||
if (__predict_true(nest_level == 0)) {
|
||||
RBTree_Node *first;
|
||||
Thread_queue_Heads *heads;
|
||||
int keep_priority;
|
||||
|
||||
--owner->resource_count;
|
||||
@ -151,17 +152,17 @@ rtems_bsd_mutex_unlock(rtems_bsd_mutex *m)
|
||||
*/
|
||||
_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)
|
||||
|| !owner->priority_restore_hint;
|
||||
|
||||
m->owner = NULL;
|
||||
|
||||
if (__predict_true(first == NULL && keep_priority)) {
|
||||
if (__predict_true(heads == NULL && keep_priority)) {
|
||||
_Thread_queue_Release(&m->queue, &lock_context);
|
||||
} else {
|
||||
rtems_bsd_mutex_unlock_more(m, owner, keep_priority,
|
||||
first, &lock_context);
|
||||
heads, &lock_context);
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -188,7 +189,7 @@ rtems_bsd_mutex_recursed(rtems_bsd_mutex *m)
|
||||
static inline void
|
||||
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)) {
|
||||
m->nest_level = 0;
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include <rtems/score/schedulerimpl.h>
|
||||
#include <rtems/score/threadqimpl.h>
|
||||
|
||||
#define BSD_MUTEX_TQ_OPERATIONS &_Thread_queue_Operations_priority
|
||||
|
||||
void
|
||||
rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m,
|
||||
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);
|
||||
|
||||
++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,
|
||||
lock_context);
|
||||
}
|
||||
@ -66,15 +69,18 @@ rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m,
|
||||
|
||||
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)
|
||||
{
|
||||
if (first != NULL) {
|
||||
if (heads != NULL) {
|
||||
const Thread_queue_Operations *operations;
|
||||
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;
|
||||
_Thread_queue_Extract_critical(&m->queue, new_owner,
|
||||
lock_context);
|
||||
_Thread_queue_Extract_critical(&m->queue, operations,
|
||||
new_owner, lock_context);
|
||||
} else {
|
||||
_Thread_queue_Release(&m->queue, lock_context);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user