diff options
author | David Robillard <d@drobilla.net> | 2013-01-12 23:38:03 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-01-12 23:38:03 +0000 |
commit | 4a05f65f51fca38b774f2bd5cda8e665c86f3917 (patch) | |
tree | 3333ca8e58cf48bffdfa16fadfa9905f56403c78 /raul/Maid.hpp | |
parent | faad203b6ae046fb3c7e6f7f2a471787163d09b4 (diff) | |
download | raul-4a05f65f51fca38b774f2bd5cda8e665c86f3917.tar.gz raul-4a05f65f51fca38b774f2bd5cda8e665c86f3917.tar.bz2 raul-4a05f65f51fca38b774f2bd5cda8e665c86f3917.zip |
Remove Raul::SharedPtr and switch to std::shared_ptr.
Use project local short type aliases for shared_ptr and friends.
Move Raul::Disposable and Raul::Manageable into Raul::Maid.
Use sets to store machina nodes and edges to avoid O(n) searches.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4939 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul/Maid.hpp')
-rw-r--r-- | raul/Maid.hpp | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/raul/Maid.hpp b/raul/Maid.hpp index c64a1db..c1d76c1 100644 --- a/raul/Maid.hpp +++ b/raul/Maid.hpp @@ -18,11 +18,10 @@ #define RAUL_MAID_HPP #include <atomic> +#include <memory> -#include "raul/Disposable.hpp" -#include "raul/Manageable.hpp" +#include "raul/Deletable.hpp" #include "raul/Noncopyable.hpp" -#include "raul/SharedPtr.hpp" namespace Raul { @@ -36,6 +35,26 @@ namespace Raul { class Maid : public Noncopyable { public: + /** An object that can be managed by the maid using shared_ptr. */ + class Manageable : public Deletable { + public: + Manageable() {} + + private: + friend class Maid; + std::shared_ptr<Manageable> _maid_next; + }; + + /** An object that can be disposed via Maid::dispose(). */ + class Disposable : public Deletable { + public: + Disposable() : _maid_next(NULL) {} + + private: + friend class Maid; + Disposable* _maid_next; + }; + Maid() : _disposed(NULL) {} inline ~Maid() { @@ -59,18 +78,18 @@ public: } } - /** Manage an object held by a SharedPtr. + /** Manage an object held by a shared pointer. * * This will hold a reference to @p ptr ensuring it will not be deleted - * except by cleanup(). This is mainly useful to allow dropping SharedPtr - * references in real-time threads without causing a deletion. + * except by cleanup(). This is mainly useful to allow dropping references + * in real-time threads without causing a deletion. * * This is not thread-safe. * * Note this mechanism scales linearly. If a very large number of objects * are managed cleanup() will become very expensive. */ - inline void manage(SharedPtr<Manageable> ptr) { + inline void manage(std::shared_ptr<Manageable> ptr) { ptr->_maid_next = _managed; _managed = ptr; } @@ -98,18 +117,18 @@ public: } // Free the managed list - SharedPtr<Manageable> managed = _managed; + std::shared_ptr<Manageable> managed = _managed; _managed.reset(); - for (SharedPtr<Manageable> obj = managed; obj;) { - const SharedPtr<Manageable> next = obj->_maid_next; + for (std::shared_ptr<Manageable> obj = managed; obj;) { + const std::shared_ptr<Manageable> next = obj->_maid_next; obj->_maid_next.reset(); obj = next; } } private: - std::atomic<Disposable*> _disposed; - SharedPtr<Manageable> _managed; + std::atomic<Disposable*> _disposed; + std::shared_ptr<Manageable> _managed; }; } // namespace Raul |