// ----------------------------------------------------------------
// SharedStateManager::find
// ----------------------------------------------------------------
//
// The find methods don't need to lock _listMutex because the thread
// from which they are called is doing the writing to the lists.
osg::StateSet* SharedStateManager::find(osg::StateSet *ss)
{
    StateSetSet::iterator result
        = _sharedStateSetList.find(osg::ref_ptr<osg::StateSet>(ss));

    if (result == _sharedStateSetList.end())
        return NULL;
    else
        return result->get();
}
void
StateSetCache::prune()
{
    // assume an exclusive mutex is taken.

    unsigned ss_count = 0, sa_count = 0;

    for( StateSetSet::iterator i = _stateSetCache.begin(); i != _stateSetCache.end(); )
    {
        if ( i->get()->referenceCount() <= 1 )
        {
            // do not call releaseGLObjects since the attrs themselves might still be shared
            // TODO: review this.
            _stateSetCache.erase( i++ );
            ss_count++;
        }
        else
        {
            ++i;
        }
    }

    for( StateAttributeSet::iterator i = _stateAttributeCache.begin(); i != _stateAttributeCache.end(); )
    {
        if ( i->get()->referenceCount() <= 1 )
        {
            i->get()->releaseGLObjects( 0L );
            _stateAttributeCache.erase( i++ );
            sa_count++;
        }
        else
        {
            ++i;
        }
    }

    OE_DEBUG << LC << "Pruned " << sa_count << " attributes, " << ss_count << " statesets" << std::endl;
}