mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-15 23:20:06 +02:00
added NullMutex, extended Events so that mutex is a template param, minor performance optimzation for strategies
This commit is contained in:
@@ -51,7 +51,7 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
template <class TArgs, class TStrategy, class TDelegate>
|
||||
template <class TArgs, class TStrategy, class TDelegate, class TMutex = FastMutex>
|
||||
class AbstractEvent
|
||||
/// An AbstractEvent is the super-class of all events.
|
||||
/// It works similar to the way C# handles notifications (aka events in C#).
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
/// (DefaultStrategy, FIFOStrategy) follow that guideline but future ones
|
||||
/// can deviate.
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
typename TMutex::ScopedLock lock(_mutex);
|
||||
_strategy.add(aDelegate);
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ public:
|
||||
/// already existing one is determined by the < operator.
|
||||
/// If the observer is not found, the unregister will be ignored
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
typename TMutex::ScopedLock lock(_mutex);
|
||||
_strategy.remove(aDelegate);
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ public:
|
||||
bool enabled = false;
|
||||
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
typename TMutex::ScopedLock lock(_mutex);
|
||||
enabled = _enabled;
|
||||
if (_enabled)
|
||||
{
|
||||
@@ -243,7 +243,7 @@ public:
|
||||
NotifyAsyncParams params(pSender, args);
|
||||
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
typename TMutex::ScopedLock lock(_mutex);
|
||||
|
||||
// thread-safeness:
|
||||
// copy should be faster and safer than blocking until
|
||||
@@ -262,7 +262,7 @@ public:
|
||||
void enable()
|
||||
/// Enables the event
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
typename TMutex::ScopedLock lock(_mutex);
|
||||
_enabled = true;
|
||||
}
|
||||
|
||||
@@ -270,22 +270,29 @@ public:
|
||||
/// Disables the event. notify and notifyAsnyc will be ignored,
|
||||
/// but adding/removing delegates is still allowed.
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
typename TMutex::ScopedLock lock(_mutex);
|
||||
_enabled = false;
|
||||
}
|
||||
|
||||
bool isEnabled() const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
typename TMutex::ScopedLock lock(_mutex);
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
void clear()
|
||||
/// Removes all delegates.
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
typename TMutex::ScopedLock lock(_mutex);
|
||||
_strategy.clear();
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
/// Checks if any delegates are registered at the delegate
|
||||
{
|
||||
typename TMutex::ScopedLock lock(_mutex);
|
||||
return _strategy.empty();
|
||||
}
|
||||
|
||||
protected:
|
||||
struct NotifyAsyncParams
|
||||
@@ -319,7 +326,7 @@ protected:
|
||||
TStrategy _strategy; /// The strategy used to notify observers.
|
||||
bool _enabled; /// Stores if an event is enabled. Notfies on disabled events have no effect
|
||||
/// but it is possible to change the observers.
|
||||
mutable FastMutex _mutex;
|
||||
mutable TMutex _mutex;
|
||||
|
||||
private:
|
||||
AbstractEvent(const AbstractEvent& other);
|
||||
|
Reference in New Issue
Block a user