osgEarth 2.1.1
Public Member Functions | Private Attributes

osgEarth::TaskRequestQueue Class Reference

Inheritance diagram for osgEarth::TaskRequestQueue:
Collaboration diagram for osgEarth::TaskRequestQueue:

List of all members.

Public Member Functions

 TaskRequestQueue ()
void add (TaskRequest *request)
TaskRequestget ()
void clear ()
void setDone ()
void setStamp (int value)
int getStamp () const
unsigned int getNumRequests () const

Private Attributes

TaskRequestPriorityMap _requests
OpenThreads::Mutex _mutex
OpenThreads::Condition _cond
volatile bool _done
int _stamp

Detailed Description

Definition at line 122 of file TaskService.


Constructor & Destructor Documentation

TaskRequestQueue::TaskRequestQueue ( )

Definition at line 67 of file TaskService.cpp.

                                   :
osg::Referenced( true ),
_done( false )
{
}

Member Function Documentation

void TaskRequestQueue::add ( TaskRequest request)

Definition at line 88 of file TaskService.cpp.

{
    request->setState( TaskRequest::STATE_PENDING );

    // install a progress callback if one isn't already installed
    if ( !request->getProgressCallback() )
        request->setProgressCallback( new ProgressCallback() );

    ScopedLock<Mutex> lock(_mutex);

    // insert by priority.
    _requests.insert( std::pair<float,TaskRequest*>(request->getPriority(), request) );

#if 0
    // insert by priority.
    bool inserted = false;
    for( TaskRequestList::iterator i = _requests.begin(); i != _requests.end(); i++ )
    {
        if ( request->getPriority() > i->get()->getPriority() )
        {
            _requests.insert( i, request );
            inserted = true;
            //OE_NOTICE << "TaskRequestQueue size=" << _requests.size() << std::endl;
            break;
        }
    }

    if ( !inserted )
        _requests.push_back( request );
#endif

    // since there is data in the queue, wake up one waiting task thread.
    _cond.signal();
}

Here is the call graph for this function:

void TaskRequestQueue::clear ( )

Definition at line 74 of file TaskService.cpp.

{
    ScopedLock<Mutex> lock(_mutex);
    _requests.clear();
}
TaskRequest * TaskRequestQueue::get ( )

Definition at line 124 of file TaskService.cpp.

{
    ScopedLock<Mutex> lock(_mutex);

    while ( !_done && _requests.empty() )
    {
        // releases the mutex and waits on the condition.
        _cond.wait( &_mutex );
    }

    if ( _done )
    {
        return 0L;
    }

    osg::ref_ptr<TaskRequest> next = _requests.begin()->second.get(); //_requests.front();
    _requests.erase( _requests.begin() ); //_requests.pop_front();

    // I'm done, someone else take a turn:
    // (technically this shouldn't be necessary since add() bumps the semaphore once
    // for each request in the queue)
    _cond.signal();

    return next.release();
}
unsigned int TaskRequestQueue::getNumRequests ( ) const

Definition at line 81 of file TaskService.cpp.

{
    ScopedLock<Mutex> lock(const_cast<TaskRequestQueue*>(this)->_mutex);
    return _requests.size();
}
int osgEarth::TaskRequestQueue::getStamp ( ) const [inline]

Definition at line 134 of file TaskService.

{ return _stamp; }
void TaskRequestQueue::setDone ( )

Definition at line 151 of file TaskService.cpp.

{
    // we need to obtain the mutex since we're using the Condition
    ScopedLock<Mutex> lock(_mutex);

    _done = true;

    // wake everyone up so they can see the _done flag set and exit.
    //_cond.broadcast();

    // alternative to buggy win32 broadcast (OSG pre-r10457 on windows)
    for(int i=0; i<128; i++)
        _cond.signal();
}
void osgEarth::TaskRequestQueue::setStamp ( int  value) [inline]

Definition at line 133 of file TaskService.

{ _stamp = value; }

Member Data Documentation

OpenThreads::Condition osgEarth::TaskRequestQueue::_cond [private]

Definition at line 141 of file TaskService.

volatile bool osgEarth::TaskRequestQueue::_done [private]

Definition at line 142 of file TaskService.

OpenThreads::Mutex osgEarth::TaskRequestQueue::_mutex [private]

Definition at line 140 of file TaskService.

Definition at line 139 of file TaskService.

Definition at line 144 of file TaskService.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines