diff --git a/parallel/stack.hpp b/parallel/stack.hpp index 55a5326c..0978f162 100644 --- a/parallel/stack.hpp +++ b/parallel/stack.hpp @@ -11,6 +11,7 @@ #include "../thread/primitive.hpp" #include "../debug/assert.hpp" #include "../thread/spinlock.hpp" +#include "../view.hpp" #include #include @@ -84,6 +85,24 @@ namespace cruft::parallel { return true; } + // DO NOT make this enum easier to use. It's supposed to be annoying + // so that people don't use it. + enum class contract { I_HAVE_LOCKED_THIS_STRUCTURE }; + + /// Returns the currently available data. + /// + /// Data is laid out bottom-to-top of the stack. + /// + /// DO NOT call this if there are any other potential clients + /// accessing the structure as it will not be protected by locks. + cruft::view store (contract) + { + auto begin = reinterpret_cast (m_store.data ()); + auto end = begin + m_cursor.load (); + + return cruft::view { begin, end }; + } + private: using index_type = std::size_t; using raw_type = std::aligned_storage_t;