TalkyBase& TalkyBase::operator<<(const TalkyMessage &m) {
		lockThread();
		sendQueue.push_back(m);
		unlockThread();
		
		return *this;
	}
示例#2
0
  void SharedLazyTessellationCache::reset()
  {
    /* lock the reset_state */
    reset_state.lock();

    /* lock the linked list of thread states */
    linkedlist_mtx.lock();

    /* block all threads */
    for (ThreadWorkState *t=current_t_state;t!=nullptr;t=t->next)
      if (lockThread(t) == 1)
        waitForUsersLessEqual(t,1);

    /* reset to the first segment */
    next_block = 0;
#if FORCE_SIMPLE_FLUSH == 1
    switch_block_threshold = maxBlocks;
#else
    switch_block_threshold = maxBlocks/NUM_CACHE_SEGMENTS;
#endif

    /* reset local time */
    localTime = NUM_CACHE_SEGMENTS;

    /* release all blocked threads */
    for (ThreadWorkState *t=current_t_state;t!=nullptr;t=t->next)
      unlockThread(t);

    /* unlock the linked list of thread states */
    linkedlist_mtx.unlock();	    

    /* unlock the reset_state */
    reset_state.unlock();
  }
示例#3
0
OMXCAM_ERROR OMXCAM_stopVideo (){
  OMXCAM_trace ("Stopping video");
  
  if (!running){
    OMXCAM_error ("Video capture is not running");
    return OMXCAM_ErrorVideo;
  }
  
  if (pthread_equal (pthread_self (), bgThread)){
    //Background thread
    OMXCAM_trace ("Stopping from background thread");
    
    //If stop() is called from inside the background thread (from the
    //bufferCallback), there's no need to use mutexes and join(), just set
    //running to false and the thread will die naturally
    running = 0;
    
    //This var is used to prevent calling mutex_lock() after mutex_destroy()
    safeRunning = 0;
  }else{
    //Main thread
    OMXCAM_trace ("Stopping from main thread");
    
    if (pthread_mutex_lock (&mutex)){
      OMXCAM_error ("pthread_mutex_lock");
      return OMXCAM_ErrorVideo;
    }
    
    running = 0;
    
    if (pthread_mutex_unlock (&mutex)){
      OMXCAM_error ("pthread_mutex_unlock");
      return OMXCAM_ErrorVideo;
    }
    
    if (pthread_join (bgThread, 0)){
      OMXCAM_error ("pthread_join");
      return OMXCAM_ErrorVideo;
    }
  }
  
  OMXCAM_ERROR error = deinitOMX ();
  
  if (sleeping){
    if (wakeThread ()){
      return error ? error : OMXCAM_ErrorWake;
    }
  }else if (locked){
    if (unlockThread ()){
      return error ? error : OMXCAM_ErrorUnlock;
    }
  }
  
  return OMXCAM_deinit ();
}
示例#4
0
  void SharedLazyTessellationCache::allocNextSegment() 
  {
    if (reset_state.try_lock())
      {
	if (next_block >= switch_block_threshold)
	  {
            /* lock the linked list of thread states */

            linkedlist_mtx.lock();

            /* block all threads */
	    for (ThreadWorkState *t=current_t_state;t!=nullptr;t=t->next)
	      if (lockThread(t) == 1)
		waitForUsersLessEqual(t,1);


            /* switch to the next segment */
	    addCurrentIndex();
	    CACHE_STATS(PRINT("RESET TESS CACHE"));

#if FORCE_SIMPLE_FLUSH == 1
	    next_block = 0;
	    switch_block_threshold = maxBlocks;
#else
	    const size_t region = localTime % NUM_CACHE_SEGMENTS;
	    next_block = region * (maxBlocks/NUM_CACHE_SEGMENTS);
	    switch_block_threshold = next_block + (maxBlocks/NUM_CACHE_SEGMENTS);
	    assert( switch_block_threshold <= maxBlocks );
#endif

	    CACHE_STATS(SharedTessellationCacheStats::cache_flushes++);

            /* release all blocked threads */

	    for (ThreadWorkState *t=current_t_state;t!=nullptr;t=t->next)
	      unlockThread(t);

            /* unlock the linked list of thread states */

            linkedlist_mtx.unlock();
	    

	  }
	reset_state.unlock();
      }
    else
      reset_state.wait_until_unlocked();	   
  }
示例#5
0
void LLWatchdog::run()
{
	lockThread();

	// Check the time since the last call to run...
	// If the time elapsed is two times greater than the regualr sleep time
	// reset the active timeouts.
	const U32 TIME_ELAPSED_MULTIPLIER = 2;
	U64 current_time = LLTimer::getTotalTime();
	U64 current_run_delta = current_time - mLastClockCount;
	mLastClockCount = current_time;
	
	if(current_run_delta > (WATCHDOG_SLEEP_TIME_USEC * TIME_ELAPSED_MULTIPLIER))
	{
		llinfos << "Watchdog thread delayed: resetting entries." << llendl;
		std::for_each(mSuspects.begin(), 
			mSuspects.end(), 
			std::mem_fun(&LLWatchdogEntry::reset)
			);
	}
	else
	{
		SuspectsRegistry::iterator result = 
			std::find_if(mSuspects.begin(), 
				mSuspects.end(), 
				std::not1(std::mem_fun(&LLWatchdogEntry::isAlive))
				);

		if(result != mSuspects.end())
		{
			// error!!!
			if(mTimer)
			{
				mTimer->stop();
			}

			llinfos << "Watchdog detected error:" << llendl;
#ifdef LL_WINDOWS
			RaiseException(0,0,0,0);
#else
			raise(SIGQUIT);
#endif
		}
	}


	unlockThread();
}
示例#6
0
  void SharedLazyTessellationCache::realloc(const size_t new_size)
  {
    /* lock the reset_state */
    reset_state.lock();

    /* lock the linked list of thread states */
    linkedlist_mtx.lock();

    /* block all threads */
    for (ThreadWorkState *t=current_t_state;t!=nullptr;t=t->next)
      if (lockThread(t) == 1)
        waitForUsersLessEqual(t,1);

    /* reallocate data */
    if (data) os_free(data,size);
    size      = new_size;
    data      = nullptr;
    if (size) data = (float*)os_malloc(size); // FIXME: do os_reserve under linux
    maxBlocks = size/64;    

    /* invalidate entire cache */
    localTime += NUM_CACHE_SEGMENTS; 

    /* reset to the first segment */
#if FORCE_SIMPLE_FLUSH == 1
    next_block = 0;
    switch_block_threshold = maxBlocks;
#else
    const size_t region = localTime % NUM_CACHE_SEGMENTS;
    next_block = region * (maxBlocks/NUM_CACHE_SEGMENTS);
    switch_block_threshold = next_block + (maxBlocks/NUM_CACHE_SEGMENTS);
    assert( switch_block_threshold <= maxBlocks );
#endif

    /* release all blocked threads */
    for (ThreadWorkState *t=current_t_state;t!=nullptr;t=t->next)
      unlockThread(t);

    /* unlock the linked list of thread states */
    linkedlist_mtx.unlock();	    

    /* unlock the reset_state */
    reset_state.unlock();
  }
示例#7
0
void LLWatchdog::remove(LLWatchdogEntry* e)
{
	lockThread();
    mSuspects.erase(e);
	unlockThread();
}
示例#8
0
void LLWatchdog::add(LLWatchdogEntry* e)
{
	lockThread();
	mSuspects.insert(e);
	unlockThread();
}