SCSIParallelTaskIdentifier
SCSIParallelTimer::GetExpiredTask ( void )
{
	
	SCSIParallelTask *	expiredTask = NULL;
	
	closeGate ( );
	
	if ( queue_empty ( &fListHead ) == false )
	{
		
		uint64_t			now;
		AbsoluteTime		deadline1;
		AbsoluteTime		deadline2;
		SCSIParallelTask *	task;
		
        task		= ( SCSIParallelTask * ) queue_first ( &fListHead );
        now 		= mach_absolute_time ( );
        deadline1	= *( AbsoluteTime * ) &now;
		deadline2 	= GetDeadline ( task );
		
		if ( CompareDeadlines ( deadline1, deadline2 ) == 1 )
		{
			
			queue_remove_first ( &fListHead, expiredTask, SCSIParallelTask *, fTimeoutChain );
			
		}
IOReturn IOFWWorkLoop::wake(void *token)
{
#if 0
    if( fSleepToken != token ) 
	{
        DEBUGLOG( "IOFWWorkLoop::wake: wrong token: %p<->%p\n", token, fSleepToken );
        return kIOReturnError;
    }
#endif
	
	if( fSleepToken )
	{
		IORecursiveLockLock( gateLock );
		
		void * the_token = fSleepToken;
		fSleepToken = NULL;
		
		// delete any event sources that were removed during sleep
		fRemoveSourceDeferredSet->flushCollection();
		
		// wake up waiting threads
		wakeupGate( the_token, false );
    }
	else 
	{
		closeGate();
	}

	return kIOReturnSuccess;
}
Ejemplo n.º 3
0
// Free is called twice:
// First when the atomic retainCount transitions from 1 -> 0
// Secondly when the work loop itself is commiting hari kari
// Hence the each leg of the free must be single threaded.
void IOWorkLoop::free()
{
    if (workThread) {
	IOInterruptState is;

	// If we are here then we must be trying to shut down this work loop
	// in this case disable all of the event source, mark the loop
	// as terminating and wakeup the work thread itself and return
	// Note: we hold the gate across the entire operation mainly for the 
	// benefit of our event sources so we can disable them cleanly.
	closeGate();

	disableAllEventSources();

        is = IOSimpleLockLockDisableInterrupt(workToDoLock);
	SETP(&fFlags, kLoopTerminate);
        thread_wakeup_one((void *) &workToDo);
        IOSimpleLockUnlockEnableInterrupt(workToDoLock, is);

	openGate();
    }
    else /* !workThread */ {
        IOEventSource *event, *next;

        for (event = eventChain; event; event = next) {
            next = event->getNext();
            event->setWorkLoop(0);
            event->setNext(0);
            event->release();
        }
        eventChain = 0;

	// Either we have a partial initialization to clean up
	// or the workThread itself is performing hari-kari.
	// Either way clean up all of our resources and return.
	
	if (controlG) {
	    controlG->release();
	    controlG = 0;
	}

	if (workToDoLock) {
	    IOSimpleLockFree(workToDoLock);
	    workToDoLock = 0;
	}

	if (gateLock) {
	    IORecursiveLockFree(gateLock);
	    gateLock = 0;
	}
	if (reserved) {
	    IODelete(reserved, ExpansionData, 1);
	    reserved = 0;
	}

	super::free();
    }
}
Ejemplo n.º 4
0
/* virtual */ void IOCommandGate::enable()
{
    if (workLoop) {
	closeGate();
	super::enable();
	wakeupGate(&enabled, /* oneThread */ false); // Unblock sleeping threads
	openGate();
    }
}
void
SCSIParallelTimer::EndTimeoutContext ( void )
{
	
	closeGate ( );
	fHandlingTimeout = false;
	openGate ( );
	
}
void
SCSIParallelTimer::BeginTimeoutContext ( void )
{
	
	closeGate ( );
	fHandlingTimeout = true;
	openGate ( );
	
}
void gateIn(void)
{

	char msgBuf[MAX_MESSAGE_LENGTH];

	while(1)
	{
		/*obtain new values of sensors*/
		/*	newSensors = getSensorValues(); */

		/* receieve message from gete in queue*/
		if(msgQReceive(gateInQueue, msgBuf, MAX_MESSAGE_LENGTH,
				WAIT_FOREVER) == ERROR){
			printf("msgQReceive - gate in queue\n");
		}else{

			if(newSensors != oldSensors)
			{
				/*IN*/
				oldCarIn = oldSensors & 0x0010;
				newCarIn = newSensors & 0x0010;
				if(oldCarIn != newCarIn)   
				{

					/* A car has arrived or a car has left */

					if(newCarIn > oldCarIn)  /* A car has arrived*/
					{
						/*check lot count*/
						openGate(1); /* 1 = in*/
						printf("A CAR WANTS TO ENTER THE LOT \n");
						taskDelay(10);
					}
					else /* a car has succesfullly entered*/
					{
						closeGate(1); /* 1 = in*/
						printf("A CAR ENTERED THE LOT!\n");
						/*semaphore*/
						parkingLotCount++;

						taskDelay(10);
					}
				}


			}

			/*set current value to sensors as the old value*/
			/*	oldSensors = newSensors;*/


		}

	}

}
bool com_apple_dts_SCSIEmulatorEventSource::addItemToQueue(SCSIEmulatorRequestBlock* elem)
{
	closeGate();
	queue_enter(&mResponderQueue, elem, SCSIEmulatorRequestBlock *, fQueueChain);
	openGate();
	
	signalWorkAvailable();
	
	return true;
}
Ejemplo n.º 9
0
IOReturn IOWorkLoop::runAction(Action inAction, OSObject *target,
                                  void *arg0, void *arg1,
                                  void *arg2, void *arg3)
{
    IOReturn res;

    // closeGate is recursive so don't worry if we already hold the lock.
    closeGate();
    res = (*inAction)(target, arg0, arg1, arg2, arg3);
    openGate();

    return res;
}
Ejemplo n.º 10
0
/* virtual */ void IOCommandGate::setWorkLoop(IOWorkLoop *inWorkLoop)
{
    uintptr_t *sleepersP = (uintptr_t *) &reserved;
    if (!inWorkLoop && workLoop) {		// tearing down
	closeGate();
	*sleepersP |= 1;
	while (*sleepersP >> 1) {
	    thread_wakeup_with_result(&enabled, THREAD_INTERRUPTED);
	    sleepGate(sleepersP, THREAD_UNINT);
	}
	*sleepersP = 0;
	openGate();
    }
Ejemplo n.º 11
0
bool
self::targetRescan(void)
{
	bool	result;

	closeGate();
	result = actionMask & ARCMSR_ESFLAG_RESCAN;
	if (result)
		actionMask &= ~ARCMSR_ESFLAG_RESCAN;
	openGate();

	debug(DEBUGF_RESCAN, "async handler checking for rescan - %s", result ? "true" : "false");
	return(result);
}
Ejemplo n.º 12
0
/* virtual */ bool IOWorkLoop::runEventSources()
{
    bool res = false;
    bool traceWL = (gIOKitTrace & kIOTraceWorkLoops) ? true : false;
    bool traceES = (gIOKitTrace & kIOTraceEventSources) ? true : false;
    
    closeGate();
    if (ISSETP(&fFlags, kLoopTerminate))
		goto abort;
	
    if (traceWL)
    	IOTimeStampStartConstant(IODBG_WORKLOOP(IOWL_WORK), (uintptr_t) this);
	
    bool more;
    do {
		CLRP(&fFlags, kLoopRestart);
		more = false;
		IOInterruptState is = IOSimpleLockLockDisableInterrupt(workToDoLock);
		workToDo = false;
		IOSimpleLockUnlockEnableInterrupt(workToDoLock, is);
		/* NOTE: only loop over event sources in eventChain. Bypass "passive" event sources for performance */
		for (IOEventSource *evnt = eventChain; evnt; evnt = evnt->getNext()) {
			
			if (traceES)
				IOTimeStampStartConstant(IODBG_WORKLOOP(IOWL_CLIENT), (uintptr_t) this, (uintptr_t) evnt);
			
			more |= evnt->checkForWork();
			
			if (traceES)
				IOTimeStampEndConstant(IODBG_WORKLOOP(IOWL_CLIENT), (uintptr_t) this, (uintptr_t) evnt);
			
			if (ISSETP(&fFlags, kLoopTerminate))
				goto abort;
			else if (fFlags & kLoopRestart) {
				more = true;
				break;
			}
		}
    } while (more);
	
    res = true;
	
    if (traceWL)
    	IOTimeStampEndConstant(IODBG_WORKLOOP(IOWL_WORK), (uintptr_t) this);
	
abort:
    openGate();
    return res;
}
Ejemplo n.º 13
0
void
self::addNotification(uint32_t mask)
{
	closeGate();
	debug(DEBUGF_MISC, "async handler adding notification %x", mask);
	actionMask |= mask;

	// if the handler's not currently running, kick it off shortly
	if (!handlerRunning) {
		debug(DEBUGF_MISC, "async handler not running, kicking it off with flags %x", actionMask);
		handlerRunning = true;
		setTimeoutUS(1);
	}
	openGate();
}
void gateOut(void)
{

	char msgBuf[MAX_MESSAGE_LENGTH];

	while(1)
	{
		/*obtain new values of sensors*/
		/*newSensors = getSensorValues();*/

		/* receieve message from gete out queue*/
		if(msgQReceive(gateOutQueue, msgBuf, MAX_MESSAGE_LENGTH,
				WAIT_FOREVER) == ERROR){
			printf("msgQReceive - gate in queue\n");
		}else{

			if(newSensors != oldSensors)
			{		
				/*OUT*/
				oldCarOut = oldSensors & 0x0020;
				newCarOut = newSensors & 0x0020;
				if(oldCarOut != newCarOut)
				{

					/* A car has arrived or a car has left of the barrier */

					if(newCarOut > oldCarOut)  /* A car has arrived to the gate*/
					{
						openGate(0); /*0 = out*/
						printf("A CAR WANTS TO LEAVE THE LOT \n");
						taskDelay(10);
					}
					else
					{
						closeGate(0); /*0=Out*/
						printf("A CAR LEFT THE LOT!\n");
						parkingLotCount--;
						taskDelay(10);
					}
				}
			}
			/*set current value to sensors as the old value*/
			/*oldSensors = newSensors;*/

		}
	}
}
Ejemplo n.º 15
0
bool
self::handlerDone(void)
{
	bool	done;

	closeGate();

	if (actionMask == 0) {
		debug(DEBUGF_MISC, "async handler is done");
		handlerRunning = false;
		done = true;
	} else {
		debug(DEBUGF_MISC, "async handler has work to do");
		done = false;
	}
	openGate();
	return(done);
}
Ejemplo n.º 16
0
void AppleRAIDEventSource::completeRequest(AppleRAIDMemoryDescriptor * memoryDescriptor,
					   IOReturn status, UInt64 actualByteCount)
{
    UInt32			memberIndex = memoryDescriptor->mdMemberIndex;
    AppleRAIDStorageRequest *	storageRequest = memoryDescriptor->mdStorageRequest;
    
    closeGate();

    // Count the member as completed.
    storageRequest->srCompletedCount++;
    
    // Save the members results.
    storageRequest->srRequestStatus[memberIndex] = status;
    storageRequest->srRequestByteCounts[memberIndex] = actualByteCount;
    
    if (storageRequest->srCompletedCount == storageRequest->srRequestCount) {
        queue_enter(&fCompletedHead, storageRequest, AppleRAIDStorageRequest *, fCommandChain);
        
	signalWorkAvailable();
    }
Ejemplo n.º 17
0
/* virtual */ bool IOWorkLoop::runEventSources()
{
    bool res = false;
    closeGate();
    if (ISSETP(&fFlags, kLoopTerminate))
	goto abort;

    IOTimeWorkS();
    bool more;
    do {
	CLRP(&fFlags, kLoopRestart);
	more = false;
	IOInterruptState is = IOSimpleLockLockDisableInterrupt(workToDoLock);
	workToDo = false;
	IOSimpleLockUnlockEnableInterrupt(workToDoLock, is);
	for (IOEventSource *evnt = eventChain; evnt; evnt = evnt->getNext()) {

	    IOTimeClientS();
	    more |= evnt->checkForWork();
	    IOTimeClientE();

	    if (ISSETP(&fFlags, kLoopTerminate))
		goto abort;
	    else if (fFlags & kLoopRestart) {
		more = true;
		break;
	    }
	}
    } while (more);

    res = true;
    IOTimeWorkE();

abort:
    openGate();
    return res;
}
Ejemplo n.º 18
0
task main()
{
	waitForStart();   // wait for start of tele-op phase
	// initializeRobot();
	while (true)
	{
		getJoystickSettings(joystick); // update joystick input

		drive(deadband(joystick.joy1_x1), deadband(joystick.joy1_y1), deadband(joystick.joy1_x2)); // normal drive
		manualLiftSlide(deadband(joystick.joy2_y1), deadband(joystick.joy2_y2));

		if (joy1Btn(4) == 1) {
			liftTalons();
		}
		if (joy1Btn(1) == 1) {
			dropTalons();
		}

		if (joy2Btn(3) == 1)
			liftHood();

		if (joy2Btn(2) == 1)
			dropHood();

		if (joy2Btn(6) == 1)
			openGate();

		if (joy2Btn(5) == 1)
			closeGate();

		//if (joy2Btn(8))
		//{
		//	while (joy2Btn(8)) // Wait while pressed
		//	{
		//		getJoystickSettings(joystick);
		//	}
		//	if (brushToggle)
		//		brushToggle = false;
		//	else
		//		brushToggle = true;
		//}

		//if (brushToggle)
		//	motor[Brush] = 90;
		//else
		//	motor[Brush] = 0;

		if (joy1Btn(5))
			motor[Brush] = 75;

		if (joy1Btn(6))
			motor[Brush] = 0;

		if (joy2Btn(1))
			motor[Shooter] = -90;
		else
			motor[Shooter] = 0;
		// ball shooting
		//if (ServoValue[])
	}
}
Ejemplo n.º 19
0
void
IOHIDEventSource::lock(void)
{
    closeGate();
}