COIN-OR::LEMON - Graph Library

Changeset 1131:43a91b33f374 in lemon


Ignore:
Timestamp:
01/29/12 11:28:41 (13 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

Thread safe map construction and destruction (#223)

It currently support pthread and windows threads.

Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • CMakeLists.txt

    r1128 r1131  
    115115SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
    116116
     117INCLUDE(FindThreads)
     118SET(LEMON_USE_PTHREAD ${CMAKE_USE_PTHREADS_INIT})
     119SET(LEMON_USE_WIN32_THREADS ${CMAKE_USE_WIN32_THREADS_INIT})
     120
    117121ENABLE_TESTING()
    118122
  • lemon/Makefile.am

    r1111 r1131  
    139139        lemon/bits/graph_adaptor_extender.h \
    140140        lemon/bits/graph_extender.h \
     141        lemon/bits/lock.h \
    141142        lemon/bits/map_extender.h \
    142143        lemon/bits/path_dump.h \
  • lemon/bits/alteration_notifier.h

    r463 r1131  
    2424
    2525#include <lemon/core.h>
     26#include <lemon/bits/lock.h>
    2627
    2728//\ingroup graphbits
     
    252253    typedef std::list<ObserverBase*> Observers;
    253254    Observers _observers;
    254 
     255    lemon::bits::Lock _lock;
    255256
    256257  public:
     
    333334
    334335    void attach(ObserverBase& observer) {
     336      _lock.lock();
    335337      observer._index = _observers.insert(_observers.begin(), &observer);
    336338      observer._notifier = this;
     339      _lock.unlock();
    337340    }
    338341
    339342    void detach(ObserverBase& observer) {
     343      _lock.lock();
    340344      _observers.erase(observer._index);
    341345      observer._index = _observers.end();
    342346      observer._notifier = 0;
     347      _lock.unlock();
    343348    }
    344349
  • lemon/bits/windows.cc

    r1055 r1131  
    131131#endif
    132132    }
     133
     134    WinLock::WinLock() {
     135#ifdef WIN32
     136      CRITICAL_SECTION *lock = new CRITICAL_SECTION;
     137      InitializeCriticalSection(lock);
     138      _repr = lock;
     139#endif
     140    }
     141   
     142    WinLock::~WinLock() {
     143#ifdef WIN32
     144      CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
     145      DeleteCriticalSection(lock);
     146      delete lock;
     147#endif
     148    }
     149
     150    void WinLock::lock() {
     151#ifdef WIN32
     152      CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
     153      EnterCriticalSection(lock);
     154#endif
     155    }
     156
     157    void WinLock::unlock() {
     158#ifdef WIN32
     159      CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
     160      LeaveCriticalSection(lock);
     161#endif
     162    }
    133163  }
    134164}
  • lemon/bits/windows.h

    r576 r1131  
    2929    std::string getWinFormattedDate();
    3030    int getWinRndSeed();
     31
     32    class WinLock {
     33    public:
     34      WinLock();
     35      ~WinLock();
     36      void lock();
     37      void unlock();
     38    private:
     39      void *_repr;
     40    };
    3141  }
    3242}
  • lemon/config.h.cmake

    r725 r1131  
    77#cmakedefine LEMON_HAVE_CLP 1
    88#cmakedefine LEMON_HAVE_CBC 1
     9#cmakedefine LEMON_USE_PTHREAD 1
     10#cmakedefine LEMON_USE_WIN32_THREADS 1
  • lemon/config.h.in

    r725 r1131  
    2525/* Define to 1 if you have CBC */
    2626#undef LEMON_HAVE_CBC
     27
     28/* Define to 1 if you have pthread */
     29#undef LEMON_USE_PTHREAD
     30
     31/* Define to 1 if you have win32 threads */
     32#undef LEMON_USE_WIN32_THREADS
Note: See TracChangeset for help on using the changeset viewer.