trunk/branch integration: update to ScopedLockWithUnlock

This commit is contained in:
Marian Krivos
2011-08-22 18:33:08 +00:00
parent f30a8dfd95
commit b554e38b37

View File

@@ -1,7 +1,7 @@
// //
// AbstractEvent.h // AbstractEvent.h
// //
// $Id: //poco/svn/Foundation/include/Poco/AbstractEvent.h#2 $ // $Id: //poco/1.4/Foundation/include/Poco/AbstractEvent.h#2 $
// //
// Library: Foundation // Library: Foundation
// Package: Events // Package: Events
@@ -209,25 +209,16 @@ public:
/// the next notify. If one of the delegates throws an exception, the notify /// the next notify. If one of the delegates throws an exception, the notify
/// method is immediately aborted and the exception is reported to the caller. /// method is immediately aborted and the exception is reported to the caller.
{ {
SharedPtr<TStrategy> ptrStrat; Poco::ScopedLockWithUnlock<TMutex> lock(_mutex);
bool enabled = false;
if (!_enabled) return;
{
typename TMutex::ScopedLock lock(_mutex);
enabled = _enabled;
if (_enabled)
{
// thread-safeness: // thread-safeness:
// copy should be faster and safer than blocking until // copy should be faster and safer than blocking until
// execution ends // execution ends
ptrStrat = new TStrategy(_strategy); TStrategy strategy(_strategy);
} lock.unlock();
} strategy.notify(pSender, args);
if (enabled)
{
ptrStrat->notify(pSender, args);
}
} }
ActiveResult<TArgs> notifyAsync(const void* pSender, const TArgs& args) ActiveResult<TArgs> notifyAsync(const void* pSender, const TArgs& args)
@@ -260,7 +251,7 @@ public:
} }
void enable() void enable()
/// Enables the event /// Enables the event.
{ {
typename TMutex::ScopedLock lock(_mutex); typename TMutex::ScopedLock lock(_mutex);
_enabled = true; _enabled = true;
@@ -288,7 +279,7 @@ public:
} }
bool empty() const bool empty() const
/// Checks if any delegates are registered at the delegate /// Checks if any delegates are registered at the delegate.
{ {
typename TMutex::ScopedLock lock(_mutex); typename TMutex::ScopedLock lock(_mutex);
return _strategy.empty(); return _strategy.empty();
@@ -337,4 +328,4 @@ private:
} // namespace Poco } // namespace Poco
#endif #endif // Foundation_AbstractFoundation_INCLUDED