ComponentResult completeThisSourceFrame(VP8EncoderGlobals glob,
                                      ICMCompressorSourceFrameRef sourceFrame)
{
  ComponentResult err = noErr;

  if (!isInQueue(glob, sourceFrame))
  {
    err = encodeThisSourceFrame(glob, sourceFrame);
  }
  if (err) return err;
  while (isInQueue(glob, sourceFrame))
  {
    UInt32 framesInQueue = glob->sourceQueue.size;
    err = encodeThisSourceFrame(glob, NULL);
    if (err) break;

    //handles the case where terminating source frames are dropped
    if (glob->sourceQueue.size == framesInQueue)
    {
        dbg_printf("[VP8E] Dropping frame %ld\n", glob->sourceQueue.frames_out);
        sourceFrame = popSourceFrame(glob);
        err = ICMCompressorSessionDropFrame(glob->session, sourceFrame);
      if (err)
        return err;
    }
  }
  return err;
}
示例#2
0
/** Starts a non-running thread

    The thread is started by placing it on a run queue.

    @param thread The TCB of the thread to be started.
    @return 0 on success. -1 on failure. 1 if the thread doesn't need to be started.
*/
int startThread( TCB *thread )
{
  #if DEBUG
  if( isInTimerQueue(thread) )
    kprintf("Thread is in timer queue!\n");
  #endif /* DEBUG */

  assert( !isInTimerQueue(thread) );

  if( thread->threadState == PAUSED ) /* A paused queue really isn't necessary. */
  {
    #if DEBUG
      unsigned int level;

      for( level=0; level < NUM_RUN_QUEUES; level++ )
      {
        if( isInQueue( &runQueues[level], thread ) )
          kprintf("Thread is in run queue, but it's paused?\n");
        assert( !isInQueue( &runQueues[level], thread ) );
      }
    #endif /* DEBUG */

    thread->threadState = READY;

    attachRunQueue( thread );
    return 0;
  }
  else
  {
    kprintf("Can't start a thread unless it's paused!\n");
    return 1;
  }
}
示例#3
0
/*
 * initialize the priority queue with the initial state
 * explored <-- empty
 * loop do
 *      if empty(queue) return failure
 *      node <-- queue.pop()
 *      if node is goal, then return solution(node)
 *      add node to explored
 *      for each action in Action(problem, node) do
 *          child node <-- childnode(problem, node, action)
 *          if child is not in queue or expolored, add node to queue
 *          otherwise, if the child.state is in queue and with a higher pathcost,
 *          then replace that node with the child
 *
 */
bool UCSearch::doSearch(Problem &problem, std::vector<MapNode *> &path)
{
    MapNode *init = problem.getInitState();
    insertQueue(init);

    while(!_queue->isEmpty())
    {
        MapNode *node = _queue->pop();
        if(problem.isGoal(node))
        {
            node->getPathFromRoot(path);
            return true;
        }
        
        insertExplored(node);
        
        std::vector<MovAction_t> & action = problem.getActions();
        std::vector<MovAction_t>::iterator it;
        for(it=action.begin(); it<action.end(); it++)
        {
            if(*it == MOV_ACT_NOOP) {
                continue;
            }

            MapNode *child = NULL;
            int res = 0;
            res = problem.movAction(node, *it, &child);
            if(res == OP_OK)
            {
                if(!isInQueue(child) && !isInExplored(child))
                {
                    insertQueue(child);
                }
                else
                {
                    if(isInQueue(child))
                    {
                        //get old one
                        MapNode *old = findQueueByKey(child->getKey());
                        if(child->getPathCost() < old->getPathCost())
                        {
                            //update;
#ifdef HW1_DEBUG
                            std::cout <<"before update, child cost: " << child->getPathCost();
                            std::cout <<",  old cost: " << old->getPathCost();
#endif
                            updateQueue(old, child);
#ifdef HW1_DEBUG
                            std::cout <<"after,  old cost: " << old->getPathCost();
#endif
                        }
                    }
                }
            }
        }
    }

    return false;
}
示例#4
0
int Mutex::acquire(Thread* thrd, TVMTick timeout)
{
  if (owner)
  {
    if (!isInQueue(*(thrd->getIDRef())) && timeout != VM_TIMEOUT_IMMEDIATE)
    {
      QTex->push(thrd);
      return ACQUIRE_WAIT;
    }
    return ACQUIRE_UNNECESSARY;
  }
  owner = thrd;
  return ACQUIRE_SUCCESS;
}//int Mutex::acquire(Thread* thrd, TVMTick timeout)
示例#5
0
bool BFSearch::doSearch(Problem &problem, std::vector<MapNode *> &path)
{

    MapNode *init = problem.getInitState();
    if(problem.isGoal(init))
    {
        init->getPathFromRoot(path); 
        return true;
    }

    insertQueue(init);

    while(!_queue->isEmpty())
    {
        MapNode * node = getFromQueue();
        insertExplored(node);
        std::vector<MovAction_t> & actions = problem.getActions();
        std::vector<MovAction_t>::iterator it;
        for(it = actions.begin(); it < actions.end(); it++)
        {
            if(*it == MOV_ACT_NOOP) 
            {
                continue;
            }

            MapNode * child = NULL;
            int res = 0;
            res = problem.movAction(node, *it, &child);
            if(res == OP_OK)
            {
                //check if in the queue
                if(!isInQueue(child) && !isInExplored(child))
                {
                    if(problem.isGoal(child))
                    {
                        child->getPathFromRoot(path);
                        return true;
                    }

                    insertQueue(child);
                }
            }
        } //for
    } //while
     
    return false;
}
示例#6
0
int
kthread_mutex_lock( int mutex_id ){
	kthread_mutex_t *mutex;
	int destinationIndex;
	//int isInSleepingTID = 0;
	while(1){
		acquire(&mtable.lock);
		mutex = &mtable.kthread_locks[mutex_id];
		if (mutex->status == M_UNUSED){
			release(&mtable.lock);
			return -1;
		} else if (mutex->status == M_UNLOCKED){
					mutex->status = M_LOCKED;
					mutex->tid = proc->threadId;
					release(&mtable.lock);
					return 0;
		} else if (mutex->status == M_LOCKED){
					//add tid to the queue
					if (isInQueue(mutex_id, proc->threadId) == 0){
						destinationIndex =  (mutex->startIndex + mutex->count) % MAX_THREADS;
						mutex->sleepingTID[destinationIndex] = proc->threadId;
						mutex->count = mutex->count+1;
						//isInSleepingTID = 1;
					}
					release(&mtable.lock);
					//block
					acquire(&ptable.lock);
					proc->state = BLOCKING;
					sched();
					release(&ptable.lock);
					
					acquire(&mtable.lock);
					/*if (proc->threadId == mutex->tid){
						release(&mtable.lock);
						return 0;
					} else {
						release(&mtable.lock);
					}*/
					release(&mtable.lock);
					
		}
	}		
	return -1;
}
示例#7
0
bool Renderable::isVisible() const {
	return isInQueue(_queueVisible);
}