|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56911 - sandbox/stm/branches/vbe/boost/stm/memory_managers
From: vicente.botet_at_[hidden]
Date: 2009-10-16 07:19:14
Author: viboes
Date: 2009-10-16 07:19:13 EDT (Fri, 16 Oct 2009)
New Revision: 56911
URL: http://svn.boost.org/trac/boost/changeset/56911
Log:
TBoost.STM vbe:
* Adding memory manager independent from the transaction object
Added:
sandbox/stm/branches/vbe/boost/stm/memory_managers/
sandbox/stm/branches/vbe/boost/stm/memory_managers/base_memory_manager.hpp (contents, props changed)
sandbox/stm/branches/vbe/boost/stm/memory_managers/memory_manage.hpp (contents, props changed)
Added: sandbox/stm/branches/vbe/boost/stm/memory_managers/base_memory_manager.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/memory_managers/base_memory_manager.hpp 2009-10-16 07:19:13 EDT (Fri, 16 Oct 2009)
@@ -0,0 +1,87 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_BASE_MEMORY_MANAGER__HPP
+#define BOOST_STM_BASE_MEMORY_MANAGER__HPP
+
+//-----------------------------------------------------------------------------
+#include <pthread.h>
+//-----------------------------------------------------------------------------
+#include <list>
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/datatypes.hpp>
+#include <boost/stm/synchro.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/memory_pool.hpp>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+// forward declarations
+//-----------------------------------------------------------------------------
+class transaction;
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+// this class provides two functions (retrieve_mem and return_mem) and
+// to manage a pool of memory
+//-----------------------------------------------------------------------------
+
+class base_memory_manager
+{
+ base_memory_manager();
+public:
+ static void alloc_size(size_t size) { memory_.alloc_size(size); }
+
+ static void return_mem(void *mem, size_t size)
+ {
+#ifndef BOOST_STM_USE_BOOST_MUTEX
+ lock(&transactionObjectMutex_);
+ memory_.returnChunk(mem, size);
+ unlock(&transactionObjectMutex_);
+#else
+ boost::lock_guard<boost::mutex> lock(transactionObjectMutex_);
+ memory_.returnChunk(mem, size);
+#endif
+ }
+
+ static void* retrieve_mem(size_t size)
+ {
+#ifndef BOOST_STM_USE_BOOST_MUTEX
+ lock(&transactionObjectMutex_);
+ void *mem = memory_.retrieveChunk(size);
+ unlock(&transactionObjectMutex_);
+#else
+ boost::lock_guard<boost::mutex> lock(transactionObjectMutex_);
+ void *mem = memory_.retrieveChunk(size);
+#endif
+
+ return mem;
+ }
+
+private:
+
+ static Mutex transactionObjectMutex_;
+ static MemoryPool<void*> memory_;
+};
+
+} // namespace core
+}
+#endif // BOOST_STM_BASE_MEMORY_MANAGER__HPP
+
+
Added: sandbox/stm/branches/vbe/boost/stm/memory_managers/memory_manage.hpp
==============================================================================
--- (empty file)
+++ sandbox/stm/branches/vbe/boost/stm/memory_managers/memory_manage.hpp 2009-10-16 07:19:13 EDT (Fri, 16 Oct 2009)
@@ -0,0 +1,73 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Justin E. Gottchlich 2009.
+// (C) Copyright Vicente J. Botet Escriba 2009.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STM_MEMORY_MANAGER__HPP
+#define BOOST_STM_MEMORY_MANAGER__HPP
+
+//-----------------------------------------------------------------------------
+//#include <stdarg.h>
+#include <pthread.h>
+//-----------------------------------------------------------------------------
+#include <list>
+//-----------------------------------------------------------------------------
+#include <boost/stm/detail/config.hpp>
+//-----------------------------------------------------------------------------
+#include <boost/stm/base_transaction_object.hpp>
+#include <boost/stm/cache_fct.hpp>
+#include <boost/stm/datatypes.hpp>
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+namespace boost { namespace stm {
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+// memory_manager mixin
+// Functions new and delete
+
+// The parameter Base allows to mix memory_manager and polymorphism
+// class B : memory_manager<B> {}
+// class D : memory_manager<D, B> {}
+// the single issue is the forward constructors from memory_manager<D, B> to B
+//-----------------------------------------------------------------------------
+template <class Derived, typename Base>
+class memory_manager : public Base
+{
+public:
+ typedef memory_manager<Derived, Base> this_type;
+
+ void* operator new(size_t size, const nothrow_t&) throw () {
+ return base_memory_manager::retrieve_mem(size);
+ }
+
+ void* operator new(size_t size) throw (std::bad_alloc) {
+ void* ptr= base_memory_manager::retrieve_mem(size);
+ if (ptr==0) throw std::bad_alloc;
+ return ptr;
+ }
+
+ void operator delete(void* mem) throw () {
+ static Derived elem;
+ static size_t elemSize = sizeof(elem);
+ base_memory_manager::return_mem(mem, elemSize);
+ }
+};
+
+}}
+#endif // BOOST_STM_TRANSACTION_OBJECT__HPP
+
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk