Changeset 3:7756f79b7410 in rrlib_buffer_pools


Ignore:
Timestamp:
13.11.2012 21:21:08 (6 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Added custom buffer deleter as buffer pool template argument.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • policies/management/ArrayAndFlagBased.h

    r2 r3  
    7676template < typename T, 
    7777         concurrent_containers::tConcurrency CONCURRENCY, 
     78         typename TBufferDeleter, 
    7879         typename TAddMutex = typename std::conditional < (CONCURRENCY == concurrent_containers::tConcurrency::FULL) || (CONCURRENCY == concurrent_containers::tConcurrency::MULTIPLE_READERS), thread::tMutex, thread::tNoMutex >::type > 
    7980class ArrayAndFlagBased : TAddMutex 
     
    153154        if (buffer) 
    154155        { 
    155           delete buffer; 
     156          TBufferDeleter deleter; 
     157          deleter(buffer); 
    156158          this->buffer_count--; 
    157159        } 
  • policies/management/QueueBased.h

    r2 r3  
    7070 * Con: Types T must be queueable => memory overhead & possibly difficult to achieve 
    7171 */ 
    72 template <typename T, concurrent_containers::tConcurrency CONCURRENCY> 
     72template <typename T, concurrent_containers::tConcurrency CONCURRENCY, typename TBufferDeleter> 
    7373class QueueBased 
    7474{ 
     
    7979 
    8080  /*! Pointer type used in internal queue (we don't want any auto-recycling here) */ 
    81   typedef std::unique_ptr<T> tQueuePointer; 
     81  typedef std::unique_ptr<T, TBufferDeleter> tQueuePointer; 
    8282 
    8383  /*! 
  • policies/recycling/UseOwnerStorageInBuffer.h

    r0 r3  
    6565// Class declaration 
    6666//---------------------------------------------------------------------- 
    67 //! SHORT_DESCRIPTION 
     67//! Policy for types derived from tBufferManagementInfo 
    6868/*! 
    6969 * Use owner storage in buffer. In order for this to work, the type T must be derived 
  • tBufferManagementInfo.h

    r2 r3  
    6161namespace management 
    6262{ 
    63 template <typename T, concurrent_containers::tConcurrency CONCURRENCY, typename> 
     63template <typename T, concurrent_containers::tConcurrency CONCURRENCY, typename TBufferDeleter, typename> 
    6464class ArrayAndFlagBased; 
    6565 
    66 template <typename T, concurrent_containers::tConcurrency CONCURRENCY> 
     66template <typename T, concurrent_containers::tConcurrency CONCURRENCY, typename TBufferDeleter> 
    6767class QueueBased; 
    6868} 
     
    9292private: 
    9393 
    94   template <typename T, concurrent_containers::tConcurrency CONCURRENCY, typename> 
     94  template <typename T, concurrent_containers::tConcurrency CONCURRENCY, typename TBufferDeleter, typename> 
    9595  friend class management::ArrayAndFlagBased; 
    9696 
    97   template <typename T, concurrent_containers::tConcurrency CONCURRENCY> 
     97  template <typename T, concurrent_containers::tConcurrency CONCURRENCY, typename TBufferDeleter> 
    9898  friend class management::QueueBased; 
    9999 
  • tBufferPool.h

    r2 r3  
    9696 *             how unique pointer obtained from this class look like, and whether buffers can be added to concurrent queues. 
    9797 *             Custom recycling policies can make a lot of sense. 
     98 * TBufferDeleter 
    9899 * TBufferManagementPolicyArgs  Any additional arguments for the BufferManagementPolicy (apart from T and CONCURRENCY) 
    99100 */ 
     
    103104         template <typename> class TDeletingPolicy = deleting::ComplainOnMissingBuffers, 
    104105         template <typename, typename> class TRecycling = recycling::StoreOwnerInUniquePointer, 
     106         typename TBufferDeleter = std::default_delete<typename TRecycling<T, int>::tManagedType>, 
    105107         typename... TBufferManagementPolicyArgs > 
    106108class tBufferPool : boost::noncopyable 
    107109{ 
    108   typedef TBufferManagementPolicy<typename TRecycling<T, int>::tManagedType, CONCURRENCY, TBufferManagementPolicyArgs...> tBufferManagement; 
     110  typedef TBufferManagementPolicy<typename TRecycling<T, int>::tManagedType, CONCURRENCY, TBufferDeleter, TBufferManagementPolicyArgs...> tBufferManagement; 
    109111  typedef TRecycling<T, tBufferManagement> tRecycler; 
    110112 
     
    165167  } 
    166168 
     169  /*! 
     170   * \return Returns internal buffer management backend for special manual tweaking of 
     171   * buffer pool. In most cases, it should not be necessary to access internals. 
     172   */ 
     173  tBufferManagement& InternalBufferManagement() 
     174  { 
     175    return buffer_management.GetBufferManagement(); 
     176  } 
     177 
    167178//---------------------------------------------------------------------- 
    168179// Private fields and methods 
     
    171182 
    172183  /*! Buffer Pool backend */ 
    173   TDeletingPolicy<TBufferManagementPolicy<typename TRecycling<T, int>::tManagedType, CONCURRENCY, TBufferManagementPolicyArgs...>> buffer_management; 
     184  TDeletingPolicy<tBufferManagement> buffer_management; 
    174185 
    175186}; 
  • tGarbageFromDeletedBufferPools.cpp

    r0 r3  
    9090static inline unsigned int GetLongevity(tDeletionList*) 
    9191{ 
    92   return 0xFF000000; // should exist longer than any reusable (and longer than any thread objects 
     92  return 0xFF000000; // should exist longer than any reusable (and longer than any thread objects) 
    9393} 
    9494 
  • test/basic_operation.cpp

    r2 r3  
    132132void TestBufferPoolWithAllConcurrencyLevels(const char* pool_type_printf_string) 
    133133{ 
     134  typedef std::default_delete<typename TRecycling<T, int>::tManagedType> tDeleter; 
    134135  RRLIB_LOG_PRINTF(USER, " "); 
    135136  { 
    136137    RRLIB_LOG_PRINTF(USER, pool_type_printf_string, "tConcurrency::NONE"); 
    137     typedef tBufferPool<T, tConcurrency::NONE, TBufferManagementPolicy, TDeletingPolicy, TRecycling, TBufferManagementPolicyArgs...> tPool; 
     138    typedef tBufferPool<T, tConcurrency::NONE, TBufferManagementPolicy, TDeletingPolicy, TRecycling, tDeleter, TBufferManagementPolicyArgs...> tPool; 
    138139    TestBufferPool<T, typename tPool::tManagedType, INSTANT_DELETE>(new tPool()); 
    139140  } 
    140141  { 
    141142    RRLIB_LOG_PRINTF(USER, pool_type_printf_string, "tConcurrency::SINGLE_READER_AND_WRITER"); 
    142     typedef tBufferPool<T, tConcurrency::SINGLE_READER_AND_WRITER, TBufferManagementPolicy, TDeletingPolicy, TRecycling, TBufferManagementPolicyArgs...> tPool; 
     143    typedef tBufferPool<T, tConcurrency::SINGLE_READER_AND_WRITER, TBufferManagementPolicy, TDeletingPolicy, TRecycling, tDeleter, TBufferManagementPolicyArgs...> tPool; 
    143144    TestBufferPool<T, typename tPool::tManagedType, INSTANT_DELETE>(new tPool()); 
    144145  } 
    145146  { 
    146147    RRLIB_LOG_PRINTF(USER, pool_type_printf_string, "tConcurrency::MULTIPLE_WRITERS"); 
    147     typedef tBufferPool<T, tConcurrency::MULTIPLE_WRITERS, TBufferManagementPolicy, TDeletingPolicy, TRecycling, TBufferManagementPolicyArgs...> tPool; 
     148    typedef tBufferPool<T, tConcurrency::MULTIPLE_WRITERS, TBufferManagementPolicy, TDeletingPolicy, TRecycling, tDeleter, TBufferManagementPolicyArgs...> tPool; 
    148149    TestBufferPool<T, typename tPool::tManagedType, INSTANT_DELETE>(new tPool()); 
    149150  } 
    150151  { 
    151152    RRLIB_LOG_PRINTF(USER, pool_type_printf_string, "tConcurrency::MULTIPLE_READERS"); 
    152     typedef tBufferPool<T, tConcurrency::MULTIPLE_READERS, TBufferManagementPolicy, TDeletingPolicy, TRecycling, TBufferManagementPolicyArgs...> tPool; 
     153    typedef tBufferPool<T, tConcurrency::MULTIPLE_READERS, TBufferManagementPolicy, TDeletingPolicy, TRecycling, tDeleter, TBufferManagementPolicyArgs...> tPool; 
    153154    TestBufferPool<T, typename tPool::tManagedType, INSTANT_DELETE>(new tPool()); 
    154155  } 
    155156  { 
    156157    RRLIB_LOG_PRINTF(USER, pool_type_printf_string, "tConcurrency::FULL"); 
    157     typedef tBufferPool<T, tConcurrency::FULL, TBufferManagementPolicy, TDeletingPolicy, TRecycling, TBufferManagementPolicyArgs...> tPool; 
     158    typedef tBufferPool<T, tConcurrency::FULL, TBufferManagementPolicy, TDeletingPolicy, TRecycling, tDeleter, TBufferManagementPolicyArgs...> tPool; 
    158159    TestBufferPool<T, typename tPool::tManagedType, INSTANT_DELETE>(new tPool()); 
    159160  } 
Note: See TracChangeset for help on using the changeset viewer.