From owner-p4-projects@FreeBSD.ORG Fri Sep 19 11:31:58 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 47ABE16A4C0; Fri, 19 Sep 2003 11:31:58 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0A05016A4B3 for ; Fri, 19 Sep 2003 11:31:58 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 73B7843FEC for ; Fri, 19 Sep 2003 11:31:57 -0700 (PDT) (envelope-from Hrishikesh_Dandekar@NAI.com) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.9/8.12.9) with ESMTP id h8JIVvXJ035987 for ; Fri, 19 Sep 2003 11:31:57 -0700 (PDT) (envelope-from Hrishikesh_Dandekar@NAI.com) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.9/8.12.9/Submit) id h8JIVuJ1035984 for perforce@freebsd.org; Fri, 19 Sep 2003 11:31:56 -0700 (PDT) (envelope-from Hrishikesh_Dandekar@NAI.com) Date: Fri, 19 Sep 2003 11:31:56 -0700 (PDT) Message-Id: <200309191831.h8JIVuJ1035984@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to Hrishikesh_Dandekar@NAI.com using -f From: Hrishikesh Dandekar To: Perforce Change Reviews Subject: PERFORCE change 38284 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Sep 2003 18:31:58 -0000 http://perforce.freebsd.org/chv.cgi?CH=38284 Change 38284 by hdandeka@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;