Try to adapt the usema driver to new select/poll world order.

Also fix build with DEBUG_IRIX defined.
Fixes PR port-sgimips/38367 and makes GENERIC build again.
Only build tested because something else is still wrong with compat_irix.
This commit is contained in:
tnn 2008-05-10 12:57:18 +00:00
parent d6c75ad916
commit 503997e388
2 changed files with 22 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: irix_usema.c,v 1.32 2008/05/09 20:49:14 tnn Exp $ */
/* $NetBSD: irix_usema.c,v 1.33 2008/05/10 12:57:18 tnn Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -30,11 +30,11 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irix_usema.c,v 1.32 2008/05/09 20:49:14 tnn Exp $");
__KERNEL_RCSID(0, "$NetBSD: irix_usema.c,v 1.33 2008/05/10 12:57:18 tnn Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/condvar.h>
#include <sys/select.h>
#include <sys/proc.h>
#include <sys/errno.h>
#include <sys/ioctl.h>
@ -181,11 +181,6 @@ irix_usema_ioctl(void *v)
register_t *retval;
int error;
#ifdef DEBUG_IRIX
printf("irix_usema_ioctl(): vp = %p, cmd = %lx, data = %p\n",
vp, cmd, data);
#endif
/*
* Some ioctl commands need to set the ioctl return value. In
* irix_sys_ioctl(), we copy the return value address and the
@ -197,6 +192,11 @@ irix_usema_ioctl(void *v)
data = iiu->iiu_data;
retval = iiu->iiu_retval;
#ifdef DEBUG_IRIX
printf("irix_usema_ioctl(): vp = %p, cmd = %lx, data = %p\n",
vp, cmd, data);
#endif
switch (cmd) {
case IRIX_UIOCABLOCKQ: /* semaphore has been blocked */
if ((iur = iur_lookup_by_vn(vp)) == NULL)
@ -210,9 +210,10 @@ irix_usema_ioctl(void *v)
return EBADF;
if ((iwpr = iur_proc_getfirst(iur)) != NULL) {
extern kcondvar_t select_cv;
iur_proc_release(iur, iwpr);
cv_broadcast(&select_cv);
rw_enter(&iur->iur_lock, RW_READER);
selnotify(&iur->iur_si, 0, 0);
rw_exit(&iur->iur_lock);
}
break;
@ -272,8 +273,13 @@ irix_usema_poll(void *v)
if ((iur = iur_lookup_by_vn(vp)) == NULL)
return 0;
if (iur_proc_isreleased(iur, curlwp->l_proc) == 0)
rw_enter(&iur->iur_lock, RW_READER);
if (iur_proc_isreleased(iur, curlwp->l_proc) == 0) {
selrecord(curlwp, &iur->iur_si);
rw_exit(&iur->iur_lock);
return 0;
}
rw_exit(&iur->iur_lock);
return (events & check);
}
@ -522,6 +528,7 @@ iur_insert(struct irix_semaphore *sem, struct vnode *vp, struct proc *p)
iur->iur_p = p;
iur->iur_waiting_count = 0;
rw_init(&iur->iur_lock);
selinit(&iur->iur_si);
TAILQ_INIT(&iur->iur_waiting_p);
TAILQ_INIT(&iur->iur_released_p);
rw_enter(&irix_usema_reclist_lock, RW_WRITER);
@ -556,6 +563,7 @@ released_restart:
LIST_REMOVE(iur, iur_list);
rw_exit(&irix_usema_reclist_lock);
seldestroy(&iur->iur_si);
rw_exit(&iur->iur_lock);
rw_destroy(&iur->iur_lock);
free(iur, M_DEVBUF);
@ -609,20 +617,19 @@ iur_proc_release(struct irix_usema_rec *iur, struct irix_waiting_proc_rec *iwpr)
}
/* Should be called with iur_lock RW_READER held */
static int
iur_proc_isreleased(struct irix_usema_rec *iur, struct proc *p)
{
struct irix_waiting_proc_rec *iwpr;
int res = 0;
rw_enter(&iur->iur_lock, RW_READER);
TAILQ_FOREACH(iwpr, &iur->iur_released_p, iwpr_list) {
if (iwpr->iwpr_p == p) {
res = 1;
break;
}
}
rw_exit(&iur->iur_lock);
return res;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: irix_usema.h,v 1.13 2008/04/28 20:23:42 martin Exp $ */
/* $NetBSD: irix_usema.h,v 1.14 2008/05/10 12:57:18 tnn Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -104,6 +104,7 @@ struct irix_usema_rec {
struct irix_semaphore *iur_sem;
int iur_shid;
struct proc *iur_p;
struct selinfo iur_si;
int iur_waiting_count;
TAILQ_HEAD(iur_waiting_p, irix_waiting_proc_rec) iur_waiting_p;
TAILQ_HEAD(iur_released_p, irix_waiting_proc_rec) iur_released_p;