# HG changeset patch
# User Balazs Dezso <deba@inf.elte.hu>
# Date 1327155512 -3600
# Node ID 25f977576e5c37a84499f401d28a46363b1358df
# Parent b1744d7bdb478e2145c094578242b8e897d4df49
Thread safe map construction and destruction
diff -r b1744d7bdb47 -r 25f977576e5c CMakeLists.txt
a
|
b
|
|
114 | 114 | CHECK_TYPE_SIZE("long long" LONG_LONG) |
115 | 115 | SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG}) |
116 | 116 | |
| 117 | INCLUDE(FindThreads) |
| 118 | SET(LEMON_USE_PTHREAD ${CMAKE_USE_PTHREADS_INIT}) |
| 119 | SET(LEMON_USE_WIN32_THREADS ${CMAKE_USE_WIN32_THREADS_INIT}) |
| 120 | |
117 | 121 | ENABLE_TESTING() |
118 | 122 | |
119 | 123 | IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer") |
diff -r b1744d7bdb47 -r 25f977576e5c lemon/Makefile.am
a
|
b
|
|
138 | 138 | lemon/bits/enable_if.h \ |
139 | 139 | lemon/bits/graph_adaptor_extender.h \ |
140 | 140 | lemon/bits/graph_extender.h \ |
| 141 | lemon/bits/lock.h \ |
141 | 142 | lemon/bits/map_extender.h \ |
142 | 143 | lemon/bits/path_dump.h \ |
143 | 144 | lemon/bits/solver_bits.h \ |
diff -r b1744d7bdb47 -r 25f977576e5c lemon/bits/alteration_notifier.h
a
|
b
|
|
23 | 23 | #include <list> |
24 | 24 | |
25 | 25 | #include <lemon/core.h> |
| 26 | #include <lemon/bits/lock.h> |
26 | 27 | |
27 | 28 | //\ingroup graphbits |
28 | 29 | //\file |
… |
… |
|
251 | 252 | |
252 | 253 | typedef std::list<ObserverBase*> Observers; |
253 | 254 | Observers _observers; |
254 | | |
| 255 | lemon::bits::Lock _lock; |
255 | 256 | |
256 | 257 | public: |
257 | 258 | |
… |
… |
|
332 | 333 | protected: |
333 | 334 | |
334 | 335 | void attach(ObserverBase& observer) { |
| 336 | _lock.lock(); |
335 | 337 | observer._index = _observers.insert(_observers.begin(), &observer); |
336 | 338 | observer._notifier = this; |
| 339 | _lock.unlock(); |
337 | 340 | } |
338 | 341 | |
339 | 342 | void detach(ObserverBase& observer) { |
| 343 | _lock.lock(); |
340 | 344 | _observers.erase(observer._index); |
341 | 345 | observer._index = _observers.end(); |
342 | 346 | observer._notifier = 0; |
| 347 | _lock.unlock(); |
343 | 348 | } |
344 | 349 | |
345 | 350 | public: |
diff -r b1744d7bdb47 -r 25f977576e5c lemon/bits/windows.cc
a
|
b
|
|
130 | 130 | return getpid() + tv.tv_sec + tv.tv_usec; |
131 | 131 | #endif |
132 | 132 | } |
| 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 | } |
133 | 163 | } |
134 | 164 | } |
diff -r b1744d7bdb47 -r 25f977576e5c lemon/bits/windows.h
a
|
b
|
|
28 | 28 | double &cutime, double &cstime); |
29 | 29 | std::string getWinFormattedDate(); |
30 | 30 | int getWinRndSeed(); |
| 31 | |
| 32 | class WinLock { |
| 33 | public: |
| 34 | WinLock(); |
| 35 | ~WinLock(); |
| 36 | void lock(); |
| 37 | void unlock(); |
| 38 | private: |
| 39 | void *_repr; |
| 40 | }; |
31 | 41 | } |
32 | 42 | } |
33 | 43 | |
diff -r b1744d7bdb47 -r 25f977576e5c lemon/config.h.cmake
a
|
b
|
|
6 | 6 | #cmakedefine LEMON_HAVE_CPLEX 1 |
7 | 7 | #cmakedefine LEMON_HAVE_CLP 1 |
8 | 8 | #cmakedefine LEMON_HAVE_CBC 1 |
| 9 | #cmakedefine LEMON_USE_PTHREAD 1 |
| 10 | #cmakedefine LEMON_USE_WIN32_THREADS 1 |
diff -r b1744d7bdb47 -r 25f977576e5c lemon/config.h.in
a
|
b
|
|
24 | 24 | |
25 | 25 | /* Define to 1 if you have CBC */ |
26 | 26 | #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 |