Ejemplo n.º 1
0
osg::StateSet*
ResourceCache::getStateSet( SkinResource* skin )
{
    // first check if it exists
    {
        Threading::ScopedReadLock shared( _skinCacheMutex );
        SkinCache::Record rec = _skinCache.get( skin );
        if ( rec.valid() )
            return rec.value();
    }

    // no? exclusive lock and create it.
    {
        Threading::ScopedWriteLock exclusive( _skinCacheMutex );

        // double check to avoid race condition
        SkinCache::Record rec = _skinCache.get( skin );
        if ( rec.valid() )
            return rec.value();

        // still not there, make it.
        osg::StateSet* stateSet = skin->createStateSet();
        if ( stateSet )
            _skinCache.insert( skin, stateSet );

        return stateSet;
    }
}
Ejemplo n.º 2
0
osg::StateSet*
ResourceCache::getStateSet( SkinResource* skin )
{
    osg::StateSet* result = 0L;

    if ( _threadSafe )
    {
        // first check if it exists
        {
            Threading::ScopedReadLock shared( _mutex );

            SkinCache::Record rec = _skinCache.get( skin );
            if ( rec.valid() )
            {
                result = rec.value();
            }
        }

        // no? exclusive lock and create it.
        if ( !result )
        {
            Threading::ScopedWriteLock exclusive( _mutex );
            
            // double check to avoid race condition
            SkinCache::Record rec = _skinCache.get( skin );
            if ( rec.valid() )
            {
                result = rec.value();
            }
            else
            {
                // still not there, make it.
                result = skin->createStateSet( _dbOptions.get() );
                if ( result )
                    _skinCache.insert( skin, result );
            }
        }
    }

    else
    {
        SkinCache::Record rec = _skinCache.get( skin );
        if ( rec.valid() )
        {
            result = rec.value();
        }
        else
        {
            result = skin->createStateSet( _dbOptions.get() );
            if ( result )
                _skinCache.insert( skin, result );
        }
    }

    return result;
}