* sysv_sem.cc: Update to FreeBSD version 1.69.
1.68: Reduce the overhead of semop() by using the kernel stack instead of malloc'd memory to store the operations array if it is small enough to fit. 1.69: Adjust the number of processes waiting on a semaphore properly if we're woken up in the middle of sleeping.
This commit is contained in:
parent
00ee07cb12
commit
c6ef5fb7ec
@ -1,3 +1,12 @@
|
|||||||
|
2004-10-01 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* sysv_sem.cc: Update to FreeBSD version 1.69.
|
||||||
|
1.68: Reduce the overhead of semop() by using the kernel stack
|
||||||
|
instead of malloc'd memory to store the operations array if it
|
||||||
|
is small enough to fit.
|
||||||
|
1.69: Adjust the number of processes waiting on a semaphore properly
|
||||||
|
if we're woken up in the middle of sleeping.
|
||||||
|
|
||||||
2004-09-23 Corinna Vinschen <corinna@vinschen.de>
|
2004-09-23 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* sysv_shm.cc (kern_shmat): Avoid compiler warning.
|
* sysv_shm.cc (kern_shmat): Avoid compiler warning.
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#ifndef __FBSDID
|
#ifndef __FBSDID
|
||||||
#define __FBSDID(s) const char version[] = (s)
|
#define __FBSDID(s) const char version[] = (s)
|
||||||
#endif
|
#endif
|
||||||
__FBSDID("$FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/kern/sysv_sem.c,v 1.67 2003/11/15 11:56:53 tjr Exp $");
|
__FBSDID("$FreeBSD: /repoman/r/ncvs/src/sys/kern/sysv_sem.c,v 1.70 2004/05/30 20:34:58 phk Exp $");
|
||||||
|
|
||||||
#define _KERNEL 1
|
#define _KERNEL 1
|
||||||
#define __BSD_VISIBLE 1
|
#define __BSD_VISIBLE 1
|
||||||
@ -953,6 +953,8 @@ struct semop_args {
|
|||||||
int
|
int
|
||||||
semop(struct thread *td, struct semop_args *uap)
|
semop(struct thread *td, struct semop_args *uap)
|
||||||
{
|
{
|
||||||
|
#define SMALL_SOPS 8
|
||||||
|
struct sembuf small_sops[SMALL_SOPS];
|
||||||
int semid = uap->semid;
|
int semid = uap->semid;
|
||||||
size_t nsops = uap->nsops;
|
size_t nsops = uap->nsops;
|
||||||
struct sembuf *sops;
|
struct sembuf *sops;
|
||||||
@ -976,16 +978,20 @@ semop(struct thread *td, struct semop_args *uap)
|
|||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
|
||||||
/* Allocate memory for sem_ops */
|
/* Allocate memory for sem_ops */
|
||||||
if (nsops > (unsigned long) seminfo.semopm) {
|
if (nsops <= SMALL_SOPS)
|
||||||
|
sops = small_sops;
|
||||||
|
else if (nsops <= (unsigned long) seminfo.semopm)
|
||||||
|
sops = (struct sembuf *) sys_malloc(nsops * sizeof(*sops), M_SEM, M_WAITOK);
|
||||||
|
else {
|
||||||
DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm,
|
DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm,
|
||||||
nsops));
|
nsops));
|
||||||
return (E2BIG);
|
return (E2BIG);
|
||||||
}
|
}
|
||||||
sops = (struct sembuf *) sys_malloc(nsops * sizeof(sops[0]), M_SEM, M_WAITOK);
|
|
||||||
if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) {
|
if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) {
|
||||||
DPRINTF(("error = %d from copyin(%08x, %08x, %d)\n", error,
|
DPRINTF(("error = %d from copyin(%08x, %08x, %d)\n", error,
|
||||||
uap->sops, sops, nsops * sizeof(sops[0])));
|
uap->sops, sops, nsops * sizeof(sops[0])));
|
||||||
sys_free(sops, M_SEM);
|
if (sops != small_sops)
|
||||||
|
sys_free(sops, M_SEM);
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1110,15 +1116,7 @@ semop(struct thread *td, struct semop_args *uap)
|
|||||||
error = msleep(semaptr, sema_mtxp, (PZERO - 4) | PCATCH,
|
error = msleep(semaptr, sema_mtxp, (PZERO - 4) | PCATCH,
|
||||||
"semwait", 0);
|
"semwait", 0);
|
||||||
DPRINTF(("semop: good morning (error=%d)!\n", error));
|
DPRINTF(("semop: good morning (error=%d)!\n", error));
|
||||||
|
/* return code is checked below, after sem[nz]cnt-- */
|
||||||
if (error != 0) {
|
|
||||||
#ifdef __CYGWIN__
|
|
||||||
if (error != EIDRM)
|
|
||||||
#endif /* __CYGWIN__ */
|
|
||||||
error = EINTR;
|
|
||||||
goto done2;
|
|
||||||
}
|
|
||||||
DPRINTF(("semop: good morning!\n"));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure that the semaphore still exists
|
* Make sure that the semaphore still exists
|
||||||
@ -1137,6 +1135,20 @@ semop(struct thread *td, struct semop_args *uap)
|
|||||||
semptr->semzcnt--;
|
semptr->semzcnt--;
|
||||||
else
|
else
|
||||||
semptr->semncnt--;
|
semptr->semncnt--;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Is it really morning, or was our sleep interrupted?
|
||||||
|
* (Delayed check of msleep() return code because we
|
||||||
|
* need to decrement sem[nz]cnt either way.)
|
||||||
|
*/
|
||||||
|
if (error != 0) {
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
if (error != EIDRM)
|
||||||
|
#endif /* __CYGWIN__ */
|
||||||
|
error = EINTR;
|
||||||
|
goto done2;
|
||||||
|
}
|
||||||
|
DPRINTF(("semop: good morning!\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -1216,7 +1228,8 @@ done:
|
|||||||
td->td_retval[0] = 0;
|
td->td_retval[0] = 0;
|
||||||
done2:
|
done2:
|
||||||
mtx_unlock(sema_mtxp);
|
mtx_unlock(sema_mtxp);
|
||||||
sys_free(sops, M_SEM);
|
if (sops != small_sops)
|
||||||
|
sys_free(sops, M_SEM);
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user