Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Dec 2006 21:39:15 GMT
From:      Todd Miller <millert@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 111480 for review
Message-ID:  <200612112139.kBBLdF1U095768@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=111480

Change 111480 by millert@millert_g5tower on 2006/12/11 21:38:20

	Convert to tiger-style mutexes.

Affected files ...

.. //depot/projects/trustedbsd/sedarwin8/darwin/xnu/bsd/kern/kern_condvar.c#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/xnu/bsd/sys/condvar.h#2 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/xnu/security/mac_base.c#26 edit
.. //depot/projects/trustedbsd/sedarwin8/darwin/xnu/security/mac_internal.h#10 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin8/darwin/xnu/bsd/kern/kern_condvar.c#2 (text+ko) ====

@@ -38,7 +38,7 @@
 #include <sys/condvar.h>
 
 #include <kern/debug.h>
-#include <kern/lock.h>
+#include <kern/locks.h>
 #include <kern/sched_prim.h>
 
 #include <string.h>
@@ -70,26 +70,26 @@
 }
 
 void
-cv_wait(struct cv *cvp, mutex_t *mp)
+cv_wait(struct cv *cvp, lck_mtx_t *mp)
 {
 	int ret;
 
-	mutex_unlock(mp);
+	lck_mtx_lock(mp);
 	ret = wait_queue_assert_wait(cvp->cv_wait_queue, 0, THREAD_UNINT, 0);
 	if (ret != THREAD_WAITING)
 		panic("cv_wait: wait_queue_assert_wait failed");
 	ret = thread_block(THREAD_CONTINUE_NULL);
 	if (ret != THREAD_AWAKENED)
 		panic("cv_wait: thread_block failed");
-	mutex_lock(mp);
+	lck_mtx_unlock(mp);
 }
 
 int
-cv_wait_sig(struct cv *cvp, mutex_t *mp)
+cv_wait_sig(struct cv *cvp, lck_mtx_t *mp)
 {
 	int ret;
 
-	mutex_unlock(mp);
+	lck_mtx_unlock(mp);
 	ret = wait_queue_assert_wait(cvp->cv_wait_queue, 0,
 	    THREAD_INTERRUPTIBLE, 0);
 	if (ret != THREAD_WAITING)
@@ -97,14 +97,14 @@
 	ret = thread_block(THREAD_CONTINUE_NULL);
 	if (ret != THREAD_AWAKENED)
 		panic("cv_wait: thread_block failed");
-	mutex_lock(mp);
+	lck_mtx_lock(mp);
 }
 
 /*
  * Not supported in Darwin right now.
  */
 int
-cv_timedwait(struct cv *cvp __unused, mutex_t *mp __unused, int timo __unused)
+cv_timedwait(struct cv *cvp __unused, lck_mtx_t *mp __unused, int timo __unused)
 {
 
 	panic("cv_timedwait: not currently supported");
@@ -114,7 +114,7 @@
  * Not supported in Darwin right now.
  */
 int
-cv_timedwait_sig(struct cv *cvp __unused, mutex_t *mp __unused, int timo __unused)
+cv_timedwait_sig(struct cv *cvp __unused, lck_mtx_t *mp __unused, int timo __unused)
 {
 
 	panic("cv_timedwait: not currently supported");

==== //depot/projects/trustedbsd/sedarwin8/darwin/xnu/bsd/sys/condvar.h#2 (text+ko) ====

@@ -34,22 +34,22 @@
  * Implement BSD-layer condition variables using Mach-layer wait queues.
  */
 
-#include <kern/lock.h>
+#include <kern/locks.h>
 #include <kern/wait_queue.h>
 
 struct cv {
 	wait_queue_t		 cv_wait_queue;
-	mutex_t			*cv_mutex;		/* Debugging only. */
+	lck_mtx_t		*cv_mutex;		/* Debugging only. */
 	const char		*cv_description;
 };
 
 struct uthread;
 void	cv_init(struct cv *cvp, const char *desc);
 void	cv_destroy(struct cv *cvp);
-void	cv_wait(struct cv *cvp, mutex_t *mp);
-int	cv_wait_sig(struct cv *cvp, mutex_t *mp);
-int	cv_timedwait(struct cv *cvp, mutex_t *mp, int timo);
-int	cv_timedwait_sig(struct cv *cvp, mutex_t *mp, int timo);
+void	cv_wait(struct cv *cvp, lck_mtx_t *mp);
+int	cv_wait_sig(struct cv *cvp, lck_mtx_t *mp);
+int	cv_timedwait(struct cv *cvp, lck_mtx_t *mp, int timo);
+int	cv_timedwait_sig(struct cv *cvp, lck_mtx_t *mp, int timo);
 void	cv_signal(struct cv *cvp);
 void	cv_broadcast(struct cv *cvp);
 void	cv_waitq_remove(struct uthread *td);

==== //depot/projects/trustedbsd/sedarwin8/darwin/xnu/security/mac_base.c#26 (text+ko) ====

@@ -174,7 +174,7 @@
  * that they should try to acquire the lock if a first attempt at
  * exclusive access fails.
  */
-static mutex_t *mac_policy_mtx;
+static lck_mtx_t *mac_policy_mtx;
 static struct cv mac_policy_cv;
 
 /*
@@ -312,7 +312,7 @@
 static __inline void
 mac_policy_grab_exclusive(void)
 {
-	mutex_lock(mac_policy_mtx);
+	lck_mtx_lock(mac_policy_mtx);
 	while (mac_policy_busy != 0)
 		cv_wait(&mac_policy_cv, mac_policy_mtx);
 }
@@ -331,16 +331,16 @@
 
 	KASSERT(mac_policy_busy == 0,
 	    ("mac_policy_release_exclusive(): not exclusive"));
-	mutex_unlock(mac_policy_mtx);
+	lck_mtx_unlock(mac_policy_mtx);
 	cv_signal(&mac_policy_cv);
 }
 
 void
 mac_policy_list_busy(void)
 {
-        mutex_lock(mac_policy_mtx);
+        lck_mtx_lock(mac_policy_mtx);
 	mac_policy_busy++;
-	mutex_unlock(mac_policy_mtx);
+	lck_mtx_unlock(mac_policy_mtx);
 }
 
 int
@@ -348,7 +348,7 @@
 {
 	int ret;
 
-	if (!mutex_try(mac_policy_mtx))
+	if (!lck_mtx_try_lock(mac_policy_mtx))
 		return (-1);
 
 	if (mac_policy_list.numloaded > mac_policy_list.staticmax) {
@@ -356,7 +356,7 @@
 		ret = 1;
 	} else
 		ret = 0;
-	mutex_unlock(mac_policy_mtx);
+	lck_mtx_unlock(mac_policy_mtx);
 	return (ret);
 }
 
@@ -365,25 +365,25 @@
 {
 	int ret;
 
-	mutex_lock(mac_policy_mtx);
+	lck_mtx_lock(mac_policy_mtx);
 	if (mac_policy_list.numloaded > mac_policy_list.staticmax) {
 		mac_policy_busy++;
 		ret = 1;
 	} else
 		ret = 0;
-	mutex_unlock(mac_policy_mtx);
+	lck_mtx_unlock(mac_policy_mtx);
 	return (ret);
 }
 
 void
 mac_policy_list_unbusy(void)
 {
-	mutex_lock(mac_policy_mtx);
+	lck_mtx_lock(mac_policy_mtx);
 	mac_policy_busy--;
 	KASSERT(mac_policy_busy >= 0, ("MAC_POLICY_LIST_LOCK"));
 	if (mac_policy_busy == 0)
 		cv_signal(&mac_policy_cv);
-	mutex_unlock(mac_policy_mtx);
+	lck_mtx_unlock(mac_policy_mtx);
 }
 
 /*
@@ -392,6 +392,9 @@
 void
 mac_policy_init(void)
 {
+	lck_grp_attr_t *mac_lck_grp_attr;
+	lck_attr_t *mac_lck_attr;
+	lck_grp_t *mac_lck_grp;
 
 	mac_policy_list.numloaded = 0;
 	mac_policy_list.max = MAC_POLICY_LIST_CHUNKSIZE;
@@ -407,7 +410,16 @@
 	LIST_INIT(&mac_static_label_element_list);
 	TAILQ_INIT(&mac_label_journal_list);
 
-	mac_policy_mtx = mutex_alloc(ETAP_NO_TRACE);
+	mac_lck_grp_attr = lck_grp_attr_alloc_init();
+	lck_grp_attr_setstat(mac_lck_grp_attr);
+	mac_lck_grp = lck_grp_alloc_init("MAC lock", mac_lck_grp_attr);
+	mac_lck_attr = lck_attr_alloc_init();
+	lck_attr_setdefault(mac_lck_attr);
+	mac_policy_mtx = lck_mtx_alloc_init(mac_lck_grp, mac_lck_attr);
+	lck_attr_free(mac_lck_attr);
+	lck_grp_attr_free(mac_lck_grp_attr);
+	lck_grp_free(mac_lck_grp);
+	
 	mac_labelzone_init();
 }
 

==== //depot/projects/trustedbsd/sedarwin8/darwin/xnu/security/mac_internal.h#10 (text+ko) ====

@@ -49,7 +49,7 @@
 #include <security/mac_data.h>
 #include <sys/sysctl.h>
 #include <kern/wait_queue.h>
-#include <kern/lock.h>
+#include <kern/locks.h>
 #include <sys/kernel.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612112139.kBBLdF1U095768>