예제 #1
0
bool SessionManager::iterateSessions()
{
    // kind of a hack to force this to wait, when removing etc.
    // mutex should do this but this thread seems way too eager
    if ( pause )
    {
        gravUtil::logVerbose( "Sessions temporarily paused...\n" );
        wxMicroSleep( 10 );
    }

    // note: iterate doesn't do lockSessions() since it shouldn't affect pause
    mutex_lock( sessionMutex );
    lockCount++;

    bool haveSessions = false;
    Group* sessions;
    SessionEntry* session;
    std::map<SessionType, Group*>::iterator i;

    // we iterate over the sessionmap here, instead of the regular group
    // children, since we might want to remove individual sessiongroups (like
    // audio) from that list for visual reasons
    for ( i = sessionMap.begin(); i != sessionMap.end(); ++i )
    {
        sessions = i->second;
        for ( int j = 0; j < sessions->numObjects(); j++ )
        {
            session = static_cast<SessionEntry*>( (*sessions)[j] );
            haveSessions = session->iterate() || haveSessions;
        }

        if ( haveSessions && gravApp::threadDebug )
        {
            if ( session->getTimestamp() % 1000 == 0 )
            {
                gravUtil::logVerbose( "SessionManager::iterate: "
                                      "have %u sessions in this group, last TS=%u\n",
                                      sessions->numObjects(), session->getTimestamp() );
            }
        }
    }

    lockCount--;
    mutex_unlock( sessionMutex );

    return haveSessions;
}