From baf06088dff0b961843ad03efd75ff009befec5c Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 30 Oct 2018 15:31:27 -0400 Subject: Feature/serial string pool refactor (#702) * Ongoing serialization for full debug work. * Use StringRepresentationCache and StringSlicePool for serialization. * Removed some older path handling for serialization which had some wrong underlying assumptions. * Builds with refactored use of SubStringPool in ir-serialize. * Removed prohibitedCategories because not used anywhere. * Add category 'compatibility-issue' * Remove work in progress on debug serialization. --- source/core/slang-object-scope-manager.h | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 source/core/slang-object-scope-manager.h (limited to 'source/core/slang-object-scope-manager.h') diff --git a/source/core/slang-object-scope-manager.h b/source/core/slang-object-scope-manager.h new file mode 100644 index 000000000..14008a490 --- /dev/null +++ b/source/core/slang-object-scope-manager.h @@ -0,0 +1,67 @@ +#ifndef SLANG_OBJECT_SCOPE_MANAGER_H +#define SLANG_OBJECT_SCOPE_MANAGER_H + +#include "smart-pointer.h" +#include "list.h" + +namespace Slang { + +/** Keep objects added in scope. + +This is currently about the most simple implementation possible. Objects are added to a list +which members are released when ObjectScopeManager loses scope, or clear is called. + +The same object can be added multiple times. This implementation will just add the same object +multiple times. A more complex implementation might notice that the object is already in scope +and not add a reference. + +Another potential improvement would be to hold the pointers in a MemoryArena. Doing so would remove +the requirement of a List of contiguous memory. + +In implementations that can hold multiple references to the same thing, we may want to add some +garbage collection to remove repeat references. +*/ +struct ObjectScopeManager +{ +public: + + /// Add an object which will be kept in scope until manager is destroyed + SLANG_INLINE RefObject* add(RefObject* obj); + /// Add an object, where it may be nullptr. If it null its a no-op + SLANG_INLINE RefObject* addMaybeNull(RefObject* obj); + + /// Clear the contents + void clear(); + + /// Dtor + ~ObjectScopeManager() { _releaseAll(); } + +protected: + void _releaseAll(); + + List m_objs; +}; + +// --------------------------------------------------------------------------- +RefObject* ObjectScopeManager::addMaybeNull(RefObject* obj) +{ + if (obj) + { + obj->addReference(); + m_objs.Add(obj); + } + return obj; +} + +// --------------------------------------------------------------------------- +RefObject* ObjectScopeManager::add(RefObject* obj) +{ + SLANG_ASSERT(obj); + obj->addReference(); + m_objs.Add(obj); + return obj; +} + +} // namespace Slang + +#endif // SLANG_OBJECT_SCOPE_MANAGER_H \ No newline at end of file -- cgit v1.2.3