better invocation, get rid of the template parameter
This commit is contained in:
parent
c4df935113
commit
751e1be596
8 changed files with 27 additions and 21 deletions
|
|
@ -81,7 +81,7 @@ namespace lib {
|
|||
void
|
||||
AllocationCluster::MemoryManager::reset (TypeInfo info)
|
||||
{
|
||||
Concurrency::Lock<MemoryManager> guard SIDEEFFECT;
|
||||
Concurrency::ClassLock<MemoryManager> guard();
|
||||
|
||||
if (0 < mem_.size()) purge();
|
||||
type_ = info;
|
||||
|
|
@ -96,7 +96,7 @@ namespace lib {
|
|||
void
|
||||
AllocationCluster::MemoryManager::purge()
|
||||
{
|
||||
Concurrency::Lock<MemoryManager> guard SIDEEFFECT;
|
||||
Concurrency::ClassLock<MemoryManager> 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<MemoryManager> guard SIDEEFFECT;
|
||||
Concurrency::ClassLock<MemoryManager> guard();
|
||||
|
||||
REQUIRE (0 < type_.allocSize);
|
||||
REQUIRE (top_ <= mem_.size());
|
||||
|
|
@ -140,7 +140,7 @@ namespace lib {
|
|||
inline void
|
||||
AllocationCluster::MemoryManager::commit (void* pendingAlloc)
|
||||
{
|
||||
Concurrency::Lock<MemoryManager> guard SIDEEFFECT;
|
||||
Concurrency::ClassLock<MemoryManager> guard();
|
||||
|
||||
REQUIRE (pendingAlloc);
|
||||
ASSERT (top_ < mem_.size());
|
||||
|
|
@ -175,7 +175,7 @@ namespace lib {
|
|||
{
|
||||
try
|
||||
{
|
||||
Concurrency::Lock<AllocationCluster> guard SIDEEFFECT
|
||||
Concurrency::ClassLock<AllocationCluster> 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<AllocationCluster> guard SIDEEFFECT; /////TODO: decide tradeoff: lock just the instance, or lock the AllocationCluster class?
|
||||
Concurrency::ClassLock<AllocationCluster> guard(); /////TODO: decide tradeoff: lock just the instance, or lock the AllocationCluster class?
|
||||
|
||||
if (slot > typeHandlers_.size())
|
||||
typeHandlers_.resize(slot);
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ namespace lib {
|
|||
static TypeInfo
|
||||
setup()
|
||||
{
|
||||
Concurrency::Lock<AllocationCluster> guard SIDEEFFECT;
|
||||
Concurrency::ClassLock<AllocationCluster> guard();
|
||||
if (!id_)
|
||||
id_= ++maxTypeIDs;
|
||||
|
||||
|
|
|
|||
|
|
@ -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 X>
|
||||
class Lock
|
||||
{
|
||||
Monitor& mon_;
|
||||
public:
|
||||
Lock(X* it)
|
||||
: mon_(getMonitor(it))
|
||||
template<class X>
|
||||
Lock(X* it) : mon_(getMonitor(it))
|
||||
{
|
||||
mon_.acquireLock();
|
||||
}
|
||||
|
||||
Lock()
|
||||
: mon_(getMonitor<X>())
|
||||
Lock(Monitor& m) : mon_(m)
|
||||
{
|
||||
mon_.acquireLock();
|
||||
}
|
||||
|
|
@ -106,8 +103,17 @@ namespace lib {
|
|||
mon_.releaseLock();
|
||||
}
|
||||
};
|
||||
|
||||
template<class X>
|
||||
struct ClassLock : Lock
|
||||
{
|
||||
ClassLock() : Lock (getMonitor<X>()) {}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Concurrency::Monitor&
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ namespace lumiera
|
|||
struct Multithreaded
|
||||
{
|
||||
typedef volatile S VolatileType;
|
||||
typedef lib::Concurrency::Lock<S> Lock;
|
||||
typedef lib::Concurrency::ClassLock<S> Lock;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ namespace lumiera {
|
|||
static void
|
||||
generateID (size_t& id)
|
||||
{
|
||||
Concurrency::Lock<Tag> guard SIDEEFFECT;
|
||||
Concurrency::ClassLock<Tag> guard();
|
||||
if (!id)
|
||||
id = ++lastRegisteredID;
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ namespace lumiera {
|
|||
void
|
||||
accomodate (size_t index)
|
||||
{
|
||||
Concurrency::Lock<Dispatcher> guard SIDEEFFECT;
|
||||
Concurrency::ClassLock<Dispatcher> guard();
|
||||
if (index > table_.size())
|
||||
table_.resize (index); // performance bottleneck?? TODO: measure the real impact!
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ namespace asset
|
|||
TODO ("check validity of Ident Category");
|
||||
ID<KIND> asset_id (getID (idi));
|
||||
|
||||
Concurrency::Lock<DB> guard SIDEEFFECT;
|
||||
Concurrency::ClassLock<DB> guard();
|
||||
TODO ("handle duplicate Registrations");
|
||||
P<KIND> smart_ptr (obj, &destroy);
|
||||
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ namespace mobject {
|
|||
static void
|
||||
createSlot (Table& table)
|
||||
{
|
||||
Concurrency::Lock<TableEntry> guard SIDEEFFECT;
|
||||
Concurrency::ClassLock<TableEntry> guard();
|
||||
if (!index)
|
||||
index = ++maxSlots;
|
||||
if (index > table.size())
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace lib {
|
|||
void
|
||||
pause ()
|
||||
{
|
||||
Lock<Victim> guard (this); // note recursive lock
|
||||
Lock guard (this); // note recursive lock
|
||||
|
||||
for ( uint i=0, lim=(rand() % MAX_PAUSE); i<lim; ++i);
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ namespace lib {
|
|||
void
|
||||
inc (uint newStep)
|
||||
{
|
||||
Lock<Victim> guard (this);
|
||||
Lock guard (this);
|
||||
step_ = newStep;
|
||||
incrementAll();
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ namespace lib {
|
|||
bool
|
||||
belowLimit ()
|
||||
{
|
||||
Lock<Victim> guard (this);
|
||||
Lock guard (this);
|
||||
return cnt_[0] < MAX_SUM;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue