Changeset 688 for threadman/trunk

Show
Ignore:
Timestamp:
30/06/08 23:35:45 (2 years ago)
Author:
tapted
Message:

Add a cmake optimise option and reduce the risk of a deadlock, holding a lock when waiting

Location:
threadman/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • threadman/trunk/CMakeLists.txt

    r685 r688  
    11CMAKE_MINIMUM_REQUIRED(VERSION 2.4) 
    22project(threadman) 
     3 
     4OPTION(optimise "Build with optimisations in vanilla make" OFF) 
     5if (optimise) 
     6  SET(CMAKE_BUILD_TYPE Release) 
     7else(optimise) 
     8  SET(CMAKE_BUILD_TYPE Debug) 
     9endif(optimise) 
    310 
    411ENABLE_TESTING() 
  • threadman/trunk/threadman.cpp

    r687 r688  
    390390    bail = true; //don't let new stuff get created 
    391391    SDL_mutexP(mut); 
     392    //holding the mutex here is safe -- stop doesn't block 
    392393    const SYNCS::iterator e = sync.end(); 
    393394    for (SYNCS::iterator it = sync.begin(); it != e; ++it) 
     
    402403    stopAll(); 
    403404    SDL_mutexP(mut); 
    404     const SYNCS::iterator e = sync.end(); 
    405     for (SYNCS::iterator it = sync.begin(); it != e; ++it) { 
     405    SYNCS local_sync; 
     406    RSYNCS local_rsync; 
     407    std::swap(local_sync, sync); 
     408    std::swap(local_rsync, rsync); 
     409    SDL_mutexV(mut); 
     410 
     411    const SYNCS::iterator e = local_sync.end(); 
     412    for (SYNCS::iterator it = local_sync.begin(); it != e; ++it) { 
    406413        it->second->wait(); 
    407414        delete it->second; 
    408415    } 
    409     sync.clear(); 
    410     const RSYNCS::iterator re = rsync.end(); 
    411     for (RSYNCS::iterator it = rsync.begin(); it != re; ++it) { 
     416    const RSYNCS::iterator re = local_rsync.end(); 
     417    for (RSYNCS::iterator it = local_rsync.begin(); it != re; ++it) { 
    412418        (*it)->wait(); 
    413419        delete *it; 
    414420    } 
    415     rsync.clear(); 
    416     SDL_mutexV(mut); 
    417421} 
    418422