diff options
author | Michi Henning <michi@zeroc.com> | 2004-05-10 02:15:57 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2004-05-10 02:15:57 +0000 |
commit | a6a7f49b10372b9e4adf2ac2431b361c5638d156 (patch) | |
tree | 1b4e44d9ba7a0209a9faa35b35ce29bb8d4d0e4e /cpp/src/IceUtil/GC.cpp | |
parent | Fixed VC6 build (diff) | |
download | ice-a6a7f49b10372b9e4adf2ac2431b361c5638d156.tar.bz2 ice-a6a7f49b10372b9e4adf2ac2431b361c5638d156.tar.xz ice-a6a7f49b10372b9e4adf2ac2431b361c5638d156.zip |
Merged changes from michi_pre_e3 branch
Diffstat (limited to 'cpp/src/IceUtil/GC.cpp')
-rw-r--r-- | cpp/src/IceUtil/GC.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/cpp/src/IceUtil/GC.cpp b/cpp/src/IceUtil/GC.cpp index 148a85fb878..e9fe8052c92 100644 --- a/cpp/src/IceUtil/GC.cpp +++ b/cpp/src/IceUtil/GC.cpp @@ -154,10 +154,9 @@ IceUtil::GC::collectGarbage() ObjectCounts counts; Time t; - GCStats stats; - RecMutex::Lock sync(*gcRecMutex._m); + RecMutex::Lock sync(*gcRecMutex._m); // Prevent any further class reference count activity. if(_statsCallback) { @@ -178,7 +177,6 @@ IceUtil::GC::collectGarbage() if(_statsCallback) { stats.examined = counts.size(); - stats.collected = 0; } // @@ -212,9 +210,9 @@ IceUtil::GC::collectGarbage() } } - for(GCObjectSet::const_iterator k = reachable.begin(); k != reachable.end(); ++k) + for(GCObjectSet::const_iterator j = reachable.begin(); j != reachable.end(); ++j) { - counts.erase(*k); + counts.erase(*j); } } @@ -225,26 +223,30 @@ IceUtil::GC::collectGarbage() ObjectCounts::const_iterator i; for(i = counts.begin(); i != counts.end(); ++i) { - i->first->__gcClear(); + i->first->__gcClear(); // Decrement ref count of objects pointed at by this object. } for(i = counts.begin(); i != counts.end(); ++i) { - gcObjects.erase(i->first); - delete i->first; - if(_statsCallback) - { - ++stats.collected; - } + gcObjects.erase(i->first); // Remove this object from candidate set. + delete i->first; // Delete this object. } - counts.clear(); } if(_statsCallback) { stats.msec = (Time::now() - t) * 1000.0L; + stats.collected = counts.size(); _statsCallback(stats); } + // + // We clear explicitly under protection of the lock, instead of waiting for the + // counts destructor. This avoids lots of lock contention later because, otherwise, + // the destructor of each object in the counts set would acquire and release + // gcRecMutex._m. + // + counts.clear(); + { Monitor<Mutex>::Lock sync(*this); |