Пример #1
0
IEventItem* CEventManager::GetPendingEvent()
{
	CAutoSectionLock lockList(&m_csEvent);

	if (m_event.empty()) {
		return NULL;
	}

	CEventItem *pItem = *m_event.begin();
	m_event.pop_front();
	return pItem;
}
void ossimPlanetIoSocketServerChannel::performIo()
{
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theSocketMutex);
   if(handle() < 0)
   {
      if(theAutoReconnectFlag)
      {
         if(theLastTick == 0)
         {
            theLastTick = osg::Timer::instance()->tick();
            return;
         }
         else 
         {
				double delta = osg::Timer::instance()->delta_m(theLastTick, osg::Timer::instance()->tick());
				
				if(delta < 0.0)
				{
					theLastTick = 0;
				}
				else if(delta > theAutoReconnectInterval)
				{
					theLastTick = 0; // reset the next try
					if(!protectedSetSocket(theHost, thePort, theIoType))
					{
						return;
					}
					else if(handle() < 0)// Quick test again to make sure its valid
					{
						return;
					}
				}
				else // we were not able to update the handle yet so return, still invalid
				{
					return;
				}
			}
		}
		else// we were not able to update the handle yet so return, still invalid
		{
			return;
		}
   }
      
   // poll for additional I/O connections
   poll(10);
   
   // handle any current connections and process the messages.
   OpenThreads::ScopedLock<OpenThreads::Mutex> lockList(theIoListMutex);
   std::vector<osg::ref_ptr<ossimPlanetIo> >::iterator iter = theIoList.begin();
   while(iter!=theIoList.end())
   {
      
      osg::ref_ptr<ossimPlanetMessage> msg;
      // perform IO
      (*iter)->performIo();
      
      // now pop any message for handling
      //
      while((msg=(*iter)->popMessage()).valid())
      {
         theInQueueMutex.lock();
         if(enableFlag())
         {
            theInQueue.push(msg);
         }
         else
         {
            while(!theInQueue.empty())
            {
               theInQueue.pop();
            }
         }
         theInQueueMutex.unlock();
      }
      // check to see if it's been marked as finished and if so remove from the list
      if((*iter)->finishedFlag())
      {
         iter = theIoList.erase(iter);
      }
      else
      {
         ++iter;
      }
   }
}