Changeset 15041 for trunk/FACT++


Ignore:
Timestamp:
03/13/13 10:48:43 (12 years ago)
Author:
tbretz
Message:
Use the lock guard where appropriate; added GetServiceList member function
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/StateMachineDimControl.cc

    r15021 r15041  
    315315int StateMachineDimControl::HandleStates(const string &server, DimDescriptions *dim)
    316316{
    317     fMutex.lock();
     317    const lock_guard<mutex> guard(fMutex);
    318318
    319319    const auto is = fCurrentStateList.find(server);
     
    332332    }
    333333
    334     fMutex.unlock();
    335 
    336334    return GetCurrentState();
    337335}
     
    339337int StateMachineDimControl::HandleDescriptions(DimDescriptions *dim)
    340338{
    341     fMutex.lock();
     339    const lock_guard<mutex> guard(fMutex);
    342340
    343341    for (auto it=dim->descriptions.begin(); it!=dim->descriptions.end(); it++)
    344342        fServiceDescriptionList[it->front().name].assign(it->begin(), it->end());
    345 
    346     fMutex.unlock();
    347343
    348344    return GetCurrentState();
     
    382378    // Make a copy of the list to be able to
    383379    // lock the access to the list
    384     fMutex.lock();
     380
     381    const lock_guard<mutex> guard(fMutex);
    385382    fServerList.insert(server);
    386     fMutex.unlock();
    387383
    388384    return GetCurrentState();
     
    391387int StateMachineDimControl::HandleServerRemove(const string &server)
    392388{
    393     fMutex.lock();
     389    const lock_guard<mutex> guard(fMutex);
    394390    fServerList.erase(server);
    395     fMutex.unlock();
    396391
    397392    return GetCurrentState();
     
    402397    vector<string> rc;
    403398
    404     fMutex.lock();
     399    const lock_guard<mutex> guard(fMutex);
    405400
    406401    rc.reserve(fServerList.size());
     
    408403        rc.push_back(*it);
    409404
    410     fMutex.unlock();
    411 
    412405    return rc;
    413406}
     
    435428    vector<string> rc;
    436429
    437     fMutex.lock();
     430    const lock_guard<mutex> guard(fMutex);
    438431
    439432    for (auto it=fServiceList.begin(); it!=fServiceList.end(); it++)
     
    441434            rc.push_back(it->server+"/"+it->service);
    442435
    443     fMutex.unlock();
    444436    return rc;
     437}
     438
     439set<Service> StateMachineDimControl::GetServiceList()
     440{
     441    const lock_guard<mutex> guard(fMutex);
     442    return fServiceList;
    445443}
    446444
     
    467465    // Make a copy of the list to be able to
    468466    // lock the access to the list
    469     fMutex.lock();
     467    const lock_guard<mutex> guard(fMutex);
    470468    fServiceList.insert(svc);
    471     fMutex.unlock();
    472469
    473470    return GetCurrentState();
     
    476473bool StateMachineDimControl::HasServer(const std::string &server)
    477474{
    478     fMutex.lock();
    479     const bool rc = fServerList.find(server)!=fServerList.end();
    480     fMutex.unlock();
    481 
    482     return rc;
     475    const lock_guard<mutex> guard(fMutex);
     476    return fServerList.find(server)!=fServerList.end();
    483477}
    484478
  • trunk/FACT++/src/StateMachineDimControl.h

    r14741 r15041  
    6161    std::vector<Description> GetDescription(const std::string &service);
    6262    std::vector<State>       GetStates(const std::string &server);
    63 
     63    std::set<Service>        GetServiceList();
    6464
    6565    int PrintStates(std::ostream &out, const std::string &serv="");
Note: See TracChangeset for help on using the changeset viewer.