CMS 3D CMS Logo

Public Types | Static Public Member Functions

stor::KeepNewest< T > Struct Template Reference

#include <ConcurrentQueue.h>

List of all members.

Public Types

typedef SizeType ReturnType
typedef std::list< TSequenceType
typedef SequenceType::size_type SizeType
typedef std::pair< T, size_t > ValueType

Static Public Member Functions

static ReturnType doEnq (T const &item, SequenceType &elements, SizeType &size, SizeType &capacity, detail::MemoryType &used, detail::MemoryType &memory, size_t &elementsDropped, boost::condition &nonempty)
static void doInsert (T const &item, SequenceType &elements, SizeType &size, detail::MemoryType const &itemSize, detail::MemoryType &used, boost::condition &nonempty)

Detailed Description

template<class T>
struct stor::KeepNewest< T >

Definition at line 173 of file ConcurrentQueue.h.


Member Typedef Documentation

template<class T >
typedef SizeType stor::KeepNewest< T >::ReturnType

Definition at line 178 of file ConcurrentQueue.h.

template<class T >
typedef std::list<T> stor::KeepNewest< T >::SequenceType

Definition at line 176 of file ConcurrentQueue.h.

template<class T >
typedef SequenceType::size_type stor::KeepNewest< T >::SizeType

Definition at line 177 of file ConcurrentQueue.h.

template<class T >
typedef std::pair<T,size_t> stor::KeepNewest< T >::ValueType

Definition at line 175 of file ConcurrentQueue.h.


Member Function Documentation

template<class T >
static ReturnType stor::KeepNewest< T >::doEnq ( T const &  item,
SequenceType elements,
SizeType size,
SizeType capacity,
detail::MemoryType used,
detail::MemoryType memory,
size_t &  elementsDropped,
boost::condition &  nonempty 
) [inline, static]

Definition at line 197 of file ConcurrentQueue.h.

References stor::KeepNewest< T >::doInsert(), asciidump::elements, stor::detail::memoryUsage(), and findQualityFiles::size.

    {
      SizeType elementsRemoved(0);
      detail::MemoryType itemSize = detail::memoryUsage(item);
      while ( (size==capacity || used+itemSize > memory) && !elements.empty() )
      {
        SequenceType holder;
        // Move the item out of elements in a manner that will not throw.
        holder.splice(holder.begin(), elements, elements.begin());
        // Record the change in the length of elements.
        --size;
        used -= detail::memoryUsage( holder.front() );
        ++elementsRemoved;
      }
      if (size < capacity && used+itemSize <= memory)
        // we succeeded to make enough room for the new element
      {
        doInsert(item, elements, size, itemSize, used, nonempty);
      }
      else
      {
        // we cannot add the new element
        ++elementsRemoved;
      }
      elementsDropped += elementsRemoved;
      return elementsRemoved;
    }
template<class T >
static void stor::KeepNewest< T >::doInsert ( T const &  item,
SequenceType elements,
SizeType size,
detail::MemoryType const &  itemSize,
detail::MemoryType used,
boost::condition &  nonempty 
) [inline, static]

Definition at line 181 of file ConcurrentQueue.h.

References findQualityFiles::size.

Referenced by stor::KeepNewest< T >::doEnq().

    {
      elements.push_back(item);
      ++size;
      used += itemSize;
      nonempty.notify_one();
    }