コード例 #1
0
//
// // Terminate invoking thread
void MyThreadExit(void)
{
	thread *readythread=NULL,*runningthread=NULL;
	if(!isQEmpty(running))
		 runningthread = dequeue(running);
	int isJoinAll;
	// chck if the present thread has any parent which is in the block queue

	thread *parentFound = findParentInBlockedQ(runningthread->parentid);

	// for join all.. Check if there is any child which is present in ready q.
	if(parentFound!=NULL)
	{
		if(parentFound->isjoinall) // It is a join all
		{	
			isJoinAll = findThreadWithSameParentInReadyQ(parentFound->id) || findThreadWithSameParentinBlockedQ(parentFound->id);
			if(!isJoinAll)
			{
				removeFromBlocked(parentFound->id);	
				enqueue(mylist,parentFound);
			}
		}	
		else // It is just a Join
		{
			if(parentFound->joinid == runningthread->id)
			{
			   removeFromBlocked(parentFound->id);
			   enqueue(mylist,parentFound);
			}

		}
		
	}
        if(!isQEmpty(mylist))
                 readythread = dequeue(mylist);
	
	runningthread->status = 1;	
	
	if(readythread != NULL)
	{
		enqueue(running,readythread);
		swapcontext(&runningthread->threadcontext,&readythread->threadcontext);
	}
	else
	{
		swapcontext(&runningthread->threadcontext,&parent);

	}
}
コード例 #2
0
DifferentialStepper::Command *DifferentialStepper::getCurrentCommand() {
    if (isQEmpty()) {
        return NULL;
    } else {
        return &_q[_qHead];
    }
}
コード例 #3
0
DifferentialStepper::Command *DifferentialStepper::getCommand(uint8_t index) {
    if (isQEmpty() || index >= _qSize) {
        return NULL;
    } else {
        index += _qHead;
        if (index >= DIFFERENTIALSTEPPER_COMMAND_QUEUE_LENGTH)
            index -= DIFFERENTIALSTEPPER_COMMAND_QUEUE_LENGTH;
        return &_q[index];
    }
}
コード例 #4
0
//
// // Wait on a semaphore
 void MySemaphoreWait(MySemaphore sem)
{
      S *s = (S*)sem;
        thread *readythread =NULL;
        thread *runningthread;
        s->svalue--;
        if(s->svalue <0)
        {
                runningthread = dequeue(running);
                enqueue(s->semblocked , runningthread);
		if(!isQEmpty(mylist))
			readythread = dequeue(mylist);
		if(readythread==NULL)
		{
			swapcontext(&runningthread->threadcontext,&parent);
		}
		enqueue(running,readythread);
                swapcontext(&runningthread->threadcontext,&readythread->threadcontext);
        }


}