Android-cuttlefish cvd tool
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
cuttlefish::UniqueResourceAllocator< T > Class Template Reference

#include <unique_resource_allocator.h>

Classes

class  Reservation
 
struct  ReservationHash
 

Public Types

using ReservationSet = std::unordered_set< Reservation, ReservationHash >
 

Public Member Functions

std::vector< T > ExpandPool (std::vector< T > another_pool)
 
std::vector< T > ExpandPool (T &&t)
 
std::vector< T > ExpandPool (const T &t)
 
std::optional< ReservationUniqueItem ()
 
std::optional< ReservationSetUniqueItems (const int n)
 
template<typename V = T>
std::enable_if_t< std::is_integral< V >::value, std::optional< ReservationSet > > UniqueConsecutiveItems (const std::size_t n)
 
std::optional< ReservationTake (const T &t)
 
template<typename Container >
std::optional< ReservationSetTakeAll (const Container &ts)
 
template<typename V = T>
std::enable_if_t< std::is_integral< V >::value, std::optional< ReservationSet > > TakeRange (const T &start_inclusive, const T &end_exclusive)
 

Static Public Member Functions

static UniqueResourceAllocatorCreate (const std::vector< T > &pool)
 
static std::unique_ptr< UniqueResourceAllocatorNew (const std::vector< T > &pool)
 

Private Types

template<typename U >
using RemoveCvref = typename std::remove_cv_t< typename std::remove_reference_t< U > >
 

Private Member Functions

template<typename Container >
 UniqueResourceAllocator (const Container &items)
 
bool operator== (const UniqueResourceAllocator &other) const
 
void Reclaim (const T &t)
 
template<typename V = T>
std::enable_if_t< std::is_integral< V >::value, std::optional< ReservationSet > > TakeRangeInternal (const T &start_inclusive, const T &end_exclusive)
 
const T * RemoveFromPool (const typename std::set< T >::iterator itr)
 

Private Attributes

std::set< T > available_resources_
 
std::unordered_set< T > allocated_resources_
 
std::mutex mutex_
 

Detailed Description

template<typename T>
class cuttlefish::UniqueResourceAllocator< T >

Generic allocator that can provide RAII-aware resource reservations.

See go/cf-resource-allocator-utils for more details.

Member Typedef Documentation

◆ RemoveCvref

template<typename T >
template<typename U >
using cuttlefish::UniqueResourceAllocator< T >::RemoveCvref = typename std::remove_cv_t<typename std::remove_reference_t<U> >
private

◆ ReservationSet

template<typename T >
using cuttlefish::UniqueResourceAllocator< T >::ReservationSet = std::unordered_set<Reservation, ReservationHash>

Constructor & Destructor Documentation

◆ UniqueResourceAllocator()

template<typename T >
template<typename Container >
cuttlefish::UniqueResourceAllocator< T >::UniqueResourceAllocator ( const Container &  items)
inlineprivate

Member Function Documentation

◆ Create()

template<typename T >
static UniqueResourceAllocator & cuttlefish::UniqueResourceAllocator< T >::Create ( const std::vector< T > &  pool)
inlinestatic

◆ ExpandPool() [1/3]

template<typename T >
std::vector< T > cuttlefish::UniqueResourceAllocator< T >::ExpandPool ( const T &  t)
inline

◆ ExpandPool() [2/3]

template<typename T >
std::vector< T > cuttlefish::UniqueResourceAllocator< T >::ExpandPool ( std::vector< T >  another_pool)
inline

◆ ExpandPool() [3/3]

template<typename T >
std::vector< T > cuttlefish::UniqueResourceAllocator< T >::ExpandPool ( T &&  t)
inline

◆ New()

template<typename T >
static std::unique_ptr< UniqueResourceAllocator > cuttlefish::UniqueResourceAllocator< T >::New ( const std::vector< T > &  pool)
inlinestatic

◆ operator==()

template<typename T >
bool cuttlefish::UniqueResourceAllocator< T >::operator== ( const UniqueResourceAllocator< T > &  other) const
inlineprivate

◆ Reclaim()

template<typename T >
void cuttlefish::UniqueResourceAllocator< T >::Reclaim ( const T &  t)
inlineprivate

◆ RemoveFromPool()

template<typename T >
const T * cuttlefish::UniqueResourceAllocator< T >::RemoveFromPool ( const typename std::set< T >::iterator  itr)
inlineprivate

◆ Take()

template<typename T >
std::optional< Reservation > cuttlefish::UniqueResourceAllocator< T >::Take ( const T &  t)
inline

◆ TakeAll()

template<typename T >
template<typename Container >
std::optional< ReservationSet > cuttlefish::UniqueResourceAllocator< T >::TakeAll ( const Container &  ts)
inline

◆ TakeRange()

template<typename T >
template<typename V = T>
std::enable_if_t< std::is_integral< V >::value, std::optional< ReservationSet > > cuttlefish::UniqueResourceAllocator< T >::TakeRange ( const T &  start_inclusive,
const T &  end_exclusive 
)
inline

◆ TakeRangeInternal()

template<typename T >
template<typename V = T>
std::enable_if_t< std::is_integral< V >::value, std::optional< ReservationSet > > cuttlefish::UniqueResourceAllocator< T >::TakeRangeInternal ( const T &  start_inclusive,
const T &  end_exclusive 
)
inlineprivate

◆ UniqueConsecutiveItems()

template<typename T >
template<typename V = T>
std::enable_if_t< std::is_integral< V >::value, std::optional< ReservationSet > > cuttlefish::UniqueResourceAllocator< T >::UniqueConsecutiveItems ( const std::size_t  n)
inline

◆ UniqueItem()

template<typename T >
std::optional< Reservation > cuttlefish::UniqueResourceAllocator< T >::UniqueItem ( )
inline

◆ UniqueItems()

template<typename T >
std::optional< ReservationSet > cuttlefish::UniqueResourceAllocator< T >::UniqueItems ( const int  n)
inline

Member Data Documentation

◆ allocated_resources_

template<typename T >
std::unordered_set<T> cuttlefish::UniqueResourceAllocator< T >::allocated_resources_
private

◆ available_resources_

template<typename T >
std::set<T> cuttlefish::UniqueResourceAllocator< T >::available_resources_
private

◆ mutex_

template<typename T >
std::mutex cuttlefish::UniqueResourceAllocator< T >::mutex_
private

The documentation for this class was generated from the following file: