Esempio n. 1
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();
  }
Esempio n. 2
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;
			mKillerCallback();
		}
	}


	unlockThread();
}
Esempio n. 3
0
	void Server::update(float timeDelta)
	{
		Binder::_update(timeDelta);
		hmutex::ScopeLock lock(&this->mutexState);
		hmutex::ScopeLock lockThread(&this->serverThread->mutex);
		State result = this->serverThread->result;
		if (result == RUNNING || result == IDLE)
		{
			return;
		}
		this->serverThread->result = IDLE;
		this->state = BOUND;
		lockThread.release();
		lock.release();
		// delegate calls
		switch (result)
		{
		case FINISHED:	this->serverDelegate->onStopped(this);		break;
		case FAILED:	this->serverDelegate->onStartFailed(this);	break;
		default:													break;
		}
	}
Esempio n. 4
0
void LLWatchdog::remove(LLWatchdogEntry* e)
{
	lockThread();
    mSuspects.erase(e);
	unlockThread();
}
Esempio n. 5
0
void LLWatchdog::add(LLWatchdogEntry* e)
{
	lockThread();
	mSuspects.insert(e);
	unlockThread();
}
Esempio n. 6
0
	void Binder::_update(float timeDelta)
	{
		hmutex::ScopeLock lock(this->_mutexState);
		hmutex::ScopeLock lockThread(&this->_thread->mutex);
		State state = *this->_state;
		State result = this->_thread->result;
		Host localHost = this->_thread->host;
		unsigned short localPort = (unsigned short)(int)this->_thread->port;
		if (result == RUNNING || result == IDLE)
		{
			return;
		}
		this->_thread->state = IDLE;
		this->_thread->result = IDLE;
		switch (result)
		{
		case FINISHED:
			switch (state)
			{
			case BINDING:
				*this->_state = BOUND;
				*this->_localHost = localHost;
				*this->_localPort = localPort;
				break;
			case UNBINDING:
				*this->_state = IDLE;
				localHost = *this->_localHost;
				localPort = *this->_localPort;
				*this->_localHost = Host();
				*this->_localPort = 0;
				break;
			default:
				break;
			}
			break;
		case FAILED:
			switch (state)
			{
			case BINDING:
				*this->_state = IDLE;
				break;
			case UNBINDING:
				*this->_state = BOUND;
				break;
			default:
				break;
			}
			break;
		default:
			break;
		}
		lockThread.release();
		lock.release();
		// delegate calls
		switch (result)
		{
		case FINISHED:
			switch (state)
			{
			case BINDING:	this->_binderDelegate->onBound(this, localHost, localPort);		break;
			case UNBINDING:	this->_binderDelegate->onUnbound(this, localHost, localPort);	break;
			default:																		break;
			}
			break;
		case FAILED:
			switch (state)
			{
			case BINDING:	this->_binderDelegate->onBindFailed(this, localHost, localPort);	break;
			case UNBINDING:	this->_binderDelegate->onUnbindFailed(this, localHost, localPort);	break;
			default:																			break;
			}
			break;
		default:
			break;
		}
	}
Esempio n. 7
0
OMXCAM_ERROR OMXCAM_startVideo (OMXCAM_VIDEO_SETTINGS* settings, uint32_t ms){
  OMXCAM_trace ("Starting video");
  
  if (!settings->bufferCallback){
    OMXCAM_error ("The 'bufferCallback' field must be defined");
    return OMXCAM_ErrorBadParameter;
  }
  if (running){
    OMXCAM_error ("Video capture is already running");
    return OMXCAM_ErrorVideo;
  }
  
  bgError = 0;
  OMXCAM_ERROR error;
  
  if ((error = OMXCAM_init ())) return error;
  
  if ((error = initOMX (settings))) return error;
  
  //Start the background thread
  OMXCAM_trace ("Creating background thread");
  
  if (pthread_mutex_init (&mutex, 0)){
    OMXCAM_error ("pthread_mutex_init");
    return OMXCAM_ErrorVideo;
  }
  
  running = 1;
  
  if (pthread_create (&bgThread, 0, captureVideo, &threadArg)){
    OMXCAM_error ("pthread_create");
    return OMXCAM_ErrorVideo;
  }
  
  //Block the main thread
  if (ms){
    if (sleepThread (ms)) return OMXCAM_ErrorSleep;
  }else{
    if (lockThread ()) return OMXCAM_ErrorLock;
  }
  
  if (bgError){
    //The video was already stopped due to an error
    OMXCAM_trace ("Video stopped due to an error");
    
    int err = bgError;
    bgError = 0;
    
    if (pthread_join (bgThread, 0)){
      OMXCAM_error ("pthread_join");
      return OMXCAM_ErrorVideo;
    }
    
    return err;
  }
  
  if (!running){
    //The video was already stopped by the client
    OMXCAM_trace ("Video stopped by the client");
    
    if (pthread_join (bgThread, 0)){
      OMXCAM_error ("pthread_join");
      return OMXCAM_ErrorVideo;
    }
    
    return OMXCAM_ErrorNone;
  }
  
  return OMXCAM_stopVideo ();
}