/* begincopyright
  Copyright (c) 1988 Xerox Corporation. All rights reserved.
  Use and copying of this software and preparation of derivative works based
  upon this software are permitted. Any distribution of this software or
  derivative works must comply with all applicable United States export
  control laws. This software is made available AS IS, and Xerox Corporation
  makes no warranty about the software, its performance or its conformity to
  any specification. Any person obtaining a copy of this software is requested
  to send their name and post office or electronic mail address to:
    PCR Coordinator
    Xerox PARC
    3333 Coyote Hill Rd.
    Palo Alto, CA 94304
  endcopyright */

/*
 * ThreadsUIOINTEvent.c
 *
 * This is a clone of ThreadsUIOEvents.c that supports SIGINT
 * CHauser September 12, 1991 5:18:33 pm PDT
 */


#ifndef ←XR←THREADS←
#   include "xr/Threads.h"
#endif

#ifndef ←XR←THREADS←BACKDOOR←
#   include "xr/ThreadsBackdoor.h"
#endif

#ifndef ←XR←UIO←
#   include "xr/UIO.h"
#endif

#ifndef	←XR←UIO←PRIVATE←
#   include "xr/UIOPrivate.h"
#endif

#ifndef ←XR←UIO←EVENTS←
#   include "xr/UIOEvents.h"
#endif

#ifndef ←XR←ERRNO←
#   include "xr/Errno.h"
#endif


#include <signal.h>


extern struct XR←MLRep XR←iopUIOEventLock;

extern struct XR←CVRep XR←iopUIOEventAvail;




int
XR←UIORegisterInterestInINTEvent(interested)
    bool interested;
{
    struct XR←IOPOrderRep iopo;
    XR←IOPOResult result;
    int ans;
    XR←IOPE iope;
    XR←IOPE iopeLimit = XR←UIOIOPELimit;

    XR←MonitorEntry(&XR←iopUIOEventLock);
    for( iope = XR←uioArea->uioa←iope; iope < iopeLimit; iope++ ) {
        iopo.iopo←eventSigNum = SIGINT;
        iopo.iopo←eventInteresting = interested;
        result = XR←IssueIOPOrder(
                /* iop */	iope,
                /* order */	&iopo,
                /* proc */	XR←RegisterInterestIOPOrderProc,
                /* cancel */	NIL,
                /* abortable */	FALSE,
                /* timeout */	XR←WAIT←FOREVER
        );
        if( result != XR←IOPO←RESULT←OK ) {
            XR←MonitorExit(&XR←iopUIOEventLock);
            XR←SetErrno(EIO);
            return (-1);
        }
        ans = (int)(iopo.iopo←results[0]);
        if( ans < 0 ) {
            XR←MonitorExit(&XR←iopUIOEventLock);
            if( interested )
                (void) XR←UIORegisterInterestInINTEvent(FALSE);
            XR←SetErrno(-ans);
            return (-1);
        }
    }
    XR←MonitorExit(&XR←iopUIOEventLock);
    return 0;
}