[rtems-libbsd commit] rtems-bsd-mutex: Use _Thread_queue_Surrender()

Sebastian Huber sebh at rtems.org
Thu Aug 11 10:37:32 UTC 2016


Module:    rtems-libbsd
Branch:    master
Commit:    691ed15cba6525fd5777aeb16a0de458568a85a5
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=691ed15cba6525fd5777aeb16a0de458568a85a5

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Aug 11 09:01:42 2016 +0200

rtems-bsd-mutex: Use _Thread_queue_Surrender()

---

 rtemsbsd/include/machine/rtems-bsd-muteximpl.h | 13 +++++-----
 rtemsbsd/rtems/rtems-kernel-muteximpl.c        | 33 +-------------------------
 2 files changed, 8 insertions(+), 38 deletions(-)

diff --git a/rtemsbsd/include/machine/rtems-bsd-muteximpl.h b/rtemsbsd/include/machine/rtems-bsd-muteximpl.h
index 4175190..4a871be 100644
--- a/rtemsbsd/include/machine/rtems-bsd-muteximpl.h
+++ b/rtemsbsd/include/machine/rtems-bsd-muteximpl.h
@@ -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 {
diff --git a/rtemsbsd/rtems/rtems-kernel-muteximpl.c b/rtemsbsd/rtems/rtems-kernel-muteximpl.c
index 616e0dc..3ce68a6 100644
--- a/rtemsbsd/rtems/rtems-kernel-muteximpl.c
+++ b/rtemsbsd/rtems/rtems-kernel-muteximpl.c
@@ -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);
-	}
-}



More information about the vc mailing list