Fix the locking mechanism that got broken with the new syscall interface.

This commit is contained in:
mycroft 1994-12-05 06:41:42 +00:00
parent 835dfab068
commit fc508faac1
1 changed files with 16 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysv_sem.c,v 1.11 1994/12/04 14:06:36 mycroft Exp $ */
/* $NetBSD: sysv_sem.c,v 1.12 1994/12/05 06:41:42 mycroft Exp $ */
/*
* Implementation of SVID semaphores
@ -50,8 +50,8 @@ seminit()
* This will probably eventually evolve into a general purpose semaphore
* facility status enquiry mechanism (I don't like the "read /dev/kmem"
* approach currently taken by ipcs and the amount of info that we want
* to be able to extract for ipcs is probably beyond what the capability
* of the getkerninfo facility.
* to be able to extract for ipcs is probably beyond the capability of
* the getkerninfo facility.
*
* At the time that the current version of semconfig was written, ipcs is
* the only user of the semconfig facility. It uses it to ensure that the
@ -69,6 +69,9 @@ semconfig(p, uap, retval)
{
int eval = 0;
while (semlock_holder != NULL && semlock_holder != p)
sleep((caddr_t)&semlock_holder, (PZERO - 4));
switch (SCARG(uap, flag)) {
case SEM_CONFIG_FREEZE:
semlock_holder = p;
@ -285,6 +288,9 @@ __semctl(p, uap, retval)
printf("call to semctl(%d, %d, %d, 0x%x)\n", semid, semnum, cmd, arg);
#endif
while (semlock_holder != NULL && semlock_holder != p)
sleep((caddr_t)&semlock_holder, (PZERO - 4));
semid = IPCID_TO_IX(semid);
if (semid < 0 || semid >= seminfo.semmsl)
return(EINVAL);
@ -442,6 +448,9 @@ semget(p, uap, retval)
printf("semget(0x%x, %d, 0%o)\n", key, nsems, semflg);
#endif
while (semlock_holder != NULL && semlock_holder != p)
sleep((caddr_t)&semlock_holder, (PZERO - 4));
if (key != IPC_PRIVATE) {
for (semid = 0; semid < seminfo.semmni; semid++) {
if ((sema[semid].sem_perm.mode & SEM_ALLOC) &&
@ -558,6 +567,9 @@ semop(p, uap, retval)
printf("call to semop(%d, 0x%x, %d)\n", semid, sops, nsops);
#endif
while (semlock_holder != NULL && semlock_holder != p)
sleep((caddr_t)&semlock_holder, (PZERO - 4));
semid = IPCID_TO_IX(semid); /* Convert back to zero origin */
if (semid < 0 || semid >= seminfo.semmsl)
@ -815,12 +827,8 @@ semexit(p)
* If somebody else is holding the global semaphore facility lock
* then sleep until it is released.
*/
while (semlock_holder != NULL && semlock_holder != p) {
#ifdef SEM_DEBUG
printf("semaphore facility locked - sleeping ...\n");
#endif
while (semlock_holder != NULL && semlock_holder != p)
sleep((caddr_t)&semlock_holder, (PZERO - 4));
}
did_something = 0;
@ -942,9 +950,6 @@ compat_10_semsys(p, uap, retval)
syscallarg(int) flag;
} */ semconfig_args;
while (semlock_holder != NULL && semlock_holder != p)
sleep((caddr_t)&semlock_holder, (PZERO - 4));
switch (SCARG(uap, which)) {
case 0: /* __semctl() */
SCARG(&__semctl_args, semid) = SCARG(uap, a2);