diff --git a/src/lib/allocationcluster.cpp b/src/lib/allocationcluster.cpp index 20ae8ae0a..06982df51 100644 --- a/src/lib/allocationcluster.cpp +++ b/src/lib/allocationcluster.cpp @@ -81,7 +81,7 @@ namespace lib { void AllocationCluster::MemoryManager::reset (TypeInfo info) { - Concurrency::Lock guard SIDEEFFECT; + Concurrency::ClassLock guard(); if (0 < mem_.size()) purge(); type_ = info; @@ -96,7 +96,7 @@ namespace lib { void AllocationCluster::MemoryManager::purge() { - Concurrency::Lock guard SIDEEFFECT; + Concurrency::ClassLock guard(); REQUIRE (type_.killIt, "we need a deleter function"); REQUIRE (0 < type_.allocSize, "allocation size unknown"); @@ -120,7 +120,7 @@ namespace lib { inline void* AllocationCluster::MemoryManager::allocate() { - Concurrency::Lock guard SIDEEFFECT; + Concurrency::ClassLock guard(); REQUIRE (0 < type_.allocSize); REQUIRE (top_ <= mem_.size()); @@ -140,7 +140,7 @@ namespace lib { inline void AllocationCluster::MemoryManager::commit (void* pendingAlloc) { - Concurrency::Lock guard SIDEEFFECT; + Concurrency::ClassLock guard(); REQUIRE (pendingAlloc); ASSERT (top_ < mem_.size()); @@ -175,7 +175,7 @@ namespace lib { { try { - Concurrency::Lock guard SIDEEFFECT + Concurrency::ClassLock guard(); TRACE (memory, "shutting down AllocationCluster"); for (size_t i = typeHandlers_.size(); 0 < i; --i) @@ -214,7 +214,7 @@ namespace lib { ASSERT (0 < slot); { - Concurrency::Lock guard SIDEEFFECT; /////TODO: decide tradeoff: lock just the instance, or lock the AllocationCluster class? + Concurrency::ClassLock guard(); /////TODO: decide tradeoff: lock just the instance, or lock the AllocationCluster class? if (slot > typeHandlers_.size()) typeHandlers_.resize(slot); diff --git a/src/lib/allocationcluster.hpp b/src/lib/allocationcluster.hpp index 0e1e85fdd..dd7ce8959 100644 --- a/src/lib/allocationcluster.hpp +++ b/src/lib/allocationcluster.hpp @@ -222,7 +222,7 @@ namespace lib { static TypeInfo setup() { - Concurrency::Lock guard SIDEEFFECT; + Concurrency::ClassLock guard(); if (!id_) id_= ++maxTypeIDs; diff --git a/src/lib/concurrency.hpp b/src/lib/concurrency.hpp index 369afa01a..fc40a4edf 100644 --- a/src/lib/concurrency.hpp +++ b/src/lib/concurrency.hpp @@ -74,7 +74,6 @@ namespace lib { Monitor objectMonitor_; - /////////////////////////////////////////////////////////////////////////TODO: any better idea for where to put the template parameter? so we can get rid of it for the typical usage scenario? /////////////////////////////////////////////////////////////////////////TODO: better solution for the storage? Implement the per-this locking without subclassing! /////////////////////////////////////////////////////////////////////////TODO: factor out the recursive/non-recursive mutex case as policy... @@ -84,19 +83,17 @@ namespace lib { static inline Monitor& getMonitor(Concurrency* forThis); - template class Lock { Monitor& mon_; public: - Lock(X* it) - : mon_(getMonitor(it)) + template + Lock(X* it) : mon_(getMonitor(it)) { mon_.acquireLock(); } - Lock() - : mon_(getMonitor()) + Lock(Monitor& m) : mon_(m) { mon_.acquireLock(); } @@ -106,8 +103,17 @@ namespace lib { mon_.releaseLock(); } }; + + template + struct ClassLock : Lock + { + ClassLock() : Lock (getMonitor()) {} + }; + }; + + Concurrency::Monitor& diff --git a/src/lib/singletonpolicies.hpp b/src/lib/singletonpolicies.hpp index e00be62b6..afbb87253 100644 --- a/src/lib/singletonpolicies.hpp +++ b/src/lib/singletonpolicies.hpp @@ -139,7 +139,7 @@ namespace lumiera struct Multithreaded { typedef volatile S VolatileType; - typedef lib::Concurrency::Lock Lock; + typedef lib::Concurrency::ClassLock Lock; }; diff --git a/src/lib/visitordispatcher.hpp b/src/lib/visitordispatcher.hpp index 46db635b0..de56445b9 100644 --- a/src/lib/visitordispatcher.hpp +++ b/src/lib/visitordispatcher.hpp @@ -62,7 +62,7 @@ namespace lumiera { static void generateID (size_t& id) { - Concurrency::Lock guard SIDEEFFECT; + Concurrency::ClassLock guard(); if (!id) id = ++lastRegisteredID; } @@ -138,7 +138,7 @@ namespace lumiera { void accomodate (size_t index) { - Concurrency::Lock guard SIDEEFFECT; + Concurrency::ClassLock guard(); if (index > table_.size()) table_.resize (index); // performance bottleneck?? TODO: measure the real impact! } diff --git a/src/proc/assetmanager.cpp b/src/proc/assetmanager.cpp index 7c4b6da06..fb2623153 100644 --- a/src/proc/assetmanager.cpp +++ b/src/proc/assetmanager.cpp @@ -116,7 +116,7 @@ namespace asset TODO ("check validity of Ident Category"); ID asset_id (getID (idi)); - Concurrency::Lock guard SIDEEFFECT; + Concurrency::ClassLock guard(); TODO ("handle duplicate Registrations"); P smart_ptr (obj, &destroy); diff --git a/src/proc/mobject/session/defsregistry.hpp b/src/proc/mobject/session/defsregistry.hpp index 3920ed143..8a3fcdfd5 100644 --- a/src/proc/mobject/session/defsregistry.hpp +++ b/src/proc/mobject/session/defsregistry.hpp @@ -162,7 +162,7 @@ namespace mobject { static void createSlot (Table& table) { - Concurrency::Lock guard SIDEEFFECT; + Concurrency::ClassLock guard(); if (!index) index = ++maxSlots; if (index > table.size()) diff --git a/tests/common/concurrency-locking-test.cpp b/tests/common/concurrency-locking-test.cpp index e3b0bbbe6..2bc7065b1 100644 --- a/tests/common/concurrency-locking-test.cpp +++ b/tests/common/concurrency-locking-test.cpp @@ -63,7 +63,7 @@ namespace lib { void pause () { - Lock guard (this); // note recursive lock + Lock guard (this); // note recursive lock for ( uint i=0, lim=(rand() % MAX_PAUSE); i guard (this); + Lock guard (this); step_ = newStep; incrementAll(); } @@ -97,7 +97,7 @@ namespace lib { bool belowLimit () { - Lock guard (this); + Lock guard (this); return cnt_[0] < MAX_SUM; }