getnextfaultthread.c 1.69 KB
/**************************************************************************
 *									  *
 *		 Copyright (C) 1995, Silicon Graphics, Inc.		  *
 *									  *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright law.  They  may  not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *									  *
 **************************************************************************/

#include "osint.h"


/*
 * __osGetNextFaultedThread(OSThread *lastFault)
 *
 * Finds and returns the next faulted thread from the active queue list (that
 * doesn't match the last faulted thread). If lastFault is NULL, start
 * the search from the beginning of the active list. Otherwise, start the
 * search from lastFault. This routine returns NULL if it cannot find any
 * faulted thread.
 */
OSThread *
__osGetNextFaultedThread(OSThread *lastFault)
{
    register u32	saveMask;
    register OSThread	*fault;

    /* Disable interrupts */
    saveMask = __osDisableInt();

    fault = (lastFault == (OSThread *)NULL) ? __osActiveQueue : lastFault;

    while (fault->priority != -1) {

        if ((fault->flags & OS_FLAG_FAULT) && (fault != lastFault)) {
            /* This thread faulted */
            break;
        }
        fault = fault->tlnext;
    }  /* while */

    /* We can't find any faulted thread, set fault to NULL for return */
    if (fault->priority == -1)
        fault = (OSThread *)NULL;

    /* Restore interrupts */
    __osRestoreInt(saveMask);

    return(fault);
}