PERFORCE change 38284 for review

Hrishikesh Dandekar hdandeka at FreeBSD.org
Fri Sep 19 18:31:56 GMT 2003


http://perforce.freebsd.org/chv.cgi?CH=38284

Change 38284 by hdandeka at hdandeka_yash on 2003/09/19 11:30:58

	Integ the POSIX sem changes into the main branch.

Affected files ...

.. //depot/projects/trustedbsd/mac/sys/kern/uipc_sem.c#12 integrate

Differences ...

==== //depot/projects/trustedbsd/mac/sys/kern/uipc_sem.c#12 (text+ko) ====

@@ -89,6 +89,14 @@
 #define ID_TO_SEM(x)	id_to_sem(x)
 #define SEM_FREE(ks) sem_free(ks, 1)
 #define SEM_DROP(ks) sem_free(ks, 0)
+#define REF_UP(ks) sem_ref(ks)
+#define REF_DOWN(ksem)    \
+		do { \
+		    sem_rel((ksem)); /* Pump down */ \
+		    if((ksem)->ks_unlinked &&  \
+			LIST_EMPTY(&(ksem)->ks_users)) \
+			    SEM_FREE((ksem)); \
+		} while (0)
 
 #ifndef MAC
 struct kuser {
@@ -363,7 +371,7 @@
 		return (EPERM);
 	}
 	*idpk = SEM_TO_ID(ks);
-	sem_ref(ks); /* Pump up the refs to avoid the race with SEM_FREE */
+	REF_UP(ks); /* Pump up the refs to avoid the race with SEM_FREE */
 	mtx_unlock(&sem_lock);
 #ifdef MAC
 	mtx_lock(&ks->ks_mtx);
@@ -384,9 +392,7 @@
 	sem_enter(td->td_proc, ks);
 err_open_existing:
 	mtx_lock(&sem_lock);
-	sem_rel(ks); /* Pump down */
-	if(ks->ks_unlinked && LIST_EMPTY(&ks->ks_users))
-		SEM_FREE(ks);
+	REF_DOWN(ks);
 	mtx_unlock(&sem_lock);
 	return(error);
 }
@@ -464,6 +470,7 @@
 			}
 			/* Use the sem created by the winner */
 			else {
+			    /* ksem_open_existing unlocks sem_lock */
 			    error = ksem_open_existing(td, ks, dir, idp, &id);
 			}
 		} else {
@@ -475,6 +482,7 @@
 			mtx_unlock(&sem_lock);
 		}
 	} else {
+		/* ksem_open_existing unlocks sem_lock */
 		error = ksem_open_existing(td, ks, dir, idp, &id);
 	}
 	return (error);
@@ -724,7 +732,7 @@
 		mtx_unlock(&sem_lock);
 		return (EINVAL);
 	}
-	sem_ref(ks);/* Pump up the refs to avoid the race with SEM_FREE */
+	REF_UP(ks);/* Pump up the refs to avoid the race with SEM_FREE */
 	mtx_unlock(&sem_lock);
 
 	mtx_lock(&ks->ks_mtx);
@@ -744,9 +752,7 @@
 err_post:
 	mtx_unlock(&ks->ks_mtx);
 	mtx_lock(&sem_lock);
-	sem_rel(ks); /* Pump down */
-	if (ks->ks_unlinked && LIST_EMPTY(&ks->ks_users))
-		SEM_FREE(ks);
+	REF_DOWN(ks);
 	mtx_unlock(&sem_lock);
 	return (error);
 }
@@ -804,7 +810,7 @@
 		mtx_unlock(&sem_lock);
 		return (EINVAL);
 	}
-	sem_ref(ks);/* Pump up the refs to avoid the race with SEM_FREE */
+	REF_UP(ks);/* Pump up the refs to avoid the race with SEM_FREE */
 	mtx_unlock(&sem_lock);
 
 	mtx_lock(&ks->ks_mtx);
@@ -827,9 +833,7 @@
 	mtx_unlock(&ks->ks_mtx);
 	DP(("<<< kern_sem_wait leaving, error = %d\n", error));
 	mtx_lock(&sem_lock);
-	sem_rel(ks); /* Pump down */
-	if (ks->ks_unlinked && LIST_EMPTY(&ks->ks_users))
-		SEM_FREE(ks);
+	REF_DOWN(ks);
 	mtx_unlock(&sem_lock);
 	return (error);
 }
@@ -855,7 +859,7 @@
 		mtx_unlock(&sem_lock);
 		return (EINVAL);
 	}
-	sem_ref(ks);/* Pump up the refs to avoid the race with SEM_FREE */
+	REF_UP(ks);/* Pump up the refs to avoid the race with SEM_FREE */
 	mtx_unlock(&sem_lock);
 
 	mtx_lock(&ks->ks_mtx);
@@ -871,9 +875,7 @@
 	error = copyout(&val, uap->val, sizeof(val));
 err_getvalue:
 	mtx_lock(&sem_lock);
-	sem_rel(ks); /* Pump down */
-	if (ks->ks_unlinked && LIST_EMPTY(&ks->ks_users))
-		SEM_FREE(ks);
+	REF_DOWN(ks);
 	mtx_unlock(&sem_lock);
 	return (error);
 }
@@ -923,7 +925,7 @@
 	ks = LIST_FIRST(&ksem_head);
 	while (ks != NULL) {
 		ksnext = LIST_NEXT(ks, ks_entry);
-		if(!sem_leave(p, ks))
+		if((ks->ks_name != NULL) && (!sem_leave(p, ks)))
 		    if (ks->ks_unlinked && LIST_EMPTY(&ks->ks_users))
 			SEM_FREE(ks);
 		ks = ksnext;
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message



More information about the trustedbsd-cvs mailing list