tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type > Class Template Reference

`#include <concurrent_lru_cache.h>`

Inheritance diagram for tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >:
Collaboration diagram for tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >:

## Classes

struct | aggregator_operation
class | handle_object
struct | map_value_type
struct | retrieve_aggregator_operation
struct | signal_end_of_usage_aggregator_operation

## Public Types

typedef handle_object | handle

## Public Member Functions

| concurrent_lru_cache (value_function_type f, std::size_t number_of_lru_history_items)
handle_object | operator[] (key_type k)

## Private Types

typedef concurrent_lru_cache | self_type
typedef value_functor_type | value_function_type
typedef std::size_t | ref_counter_type
typedef std::map< key_type, map_value_type > | map_storage_type
typedef std::list< typename map_storage_type::iterator > | lru_list_type
typedef aggregator_operation | aggregated_operation_type
typedef tbb::internal::aggregating_functor< self_type, aggregated_operation_type > | aggregator_function_type
typedef tbb::internal::aggregator< aggregator_function_type, aggregated_operation_type > | aggregator_type

## Private Member Functions

void | signal_end_of_usage (typename map_storage_type::reference value_ref)
void | handle_operations (aggregator_operation *op_list)
map_storage_type::reference | retrieve_serial (key_type k, bool &is_new_value_needed)
void | signal_end_of_usage_serial (typename map_storage_type::reference map_record_ref)
Private Member Functions inherited from tbb::internal::no_assign
void | operator= (const no_assign &)=delete
| no_assign (const no_assign &)=default
| no_assign ()=default

## Private Attributes

value_function_type | my_value_function
const std::size_t | my_number_of_lru_history_items
map_storage_type | my_map_storage
lru_list_type | my_lru_list
aggregator_type | my_aggregator

## Friends

class | tbb::internal::aggregating_functor< self_type, aggregated_operation_type >

## Detailed Description

### template<typename key_type, typename value_type, typename value_functor_type = value_type (*)(key_type)>
class tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >

Definition at line 44 of file concurrent_lru_cache.h.

## Member Typedef Documentation

## aggregated_operation_type

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

typedef aggregator_operation tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::aggregated_operation_type

private

Definition at line 65 of file concurrent_lru_cache.h.

## aggregator_function_type

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

typedef tbb::internal::aggregating_functor<self_type,aggregated_operation_type> tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::aggregator_function_type

private

Definition at line 67 of file concurrent_lru_cache.h.

## aggregator_type

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

typedef tbb::internal::aggregator<aggregator_function_type, aggregated_operation_type> tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::aggregator_type

private

Definition at line 69 of file concurrent_lru_cache.h.

## handle

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

typedef handle_object tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::handle

Definition at line 79 of file concurrent_lru_cache.h.

## lru_list_type

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

typedef std::list<typename map_storage_type::iterator> tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::lru_list_type

private

Definition at line 51 of file concurrent_lru_cache.h.

## map_storage_type

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

typedef std::map<key_type, map_value_type> tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::map_storage_type

private

Definition at line 49 of file concurrent_lru_cache.h.

## ref_counter_type

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

typedef std::size_t tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::ref_counter_type

private

Definition at line 48 of file concurrent_lru_cache.h.

## self_type

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

typedef concurrent_lru_cache tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::self_type

private

Definition at line 46 of file concurrent_lru_cache.h.

## value_function_type

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

typedef value_functor_type tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::value_function_type

private

Definition at line 47 of file concurrent_lru_cache.h.

## Constructor & Destructor Documentation

## concurrent_lru_cache()

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::concurrent_lru_cache | ( | value_function_type | f,
|  | std::size_t | number_of_lru_history_items
| ) |  |

inline

Definition at line 82 of file concurrent_lru_cache.h.

: my_value_function(f),my_number_of_lru_history_items(number_of_lru_history_items)
{
my_aggregator.initialize_handler(aggregator_function_type(this));
}

References tbb::interface6::internal::aggregator< handler_type, operation_type >::initialize_handler(), and tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_aggregator.

Here is the call graph for this function:

## Member Function Documentation

## handle_operations()

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

void tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::handle_operations | ( | aggregator_operation * | op_list | ) |

inline private

Definition at line 229 of file concurrent_lru_cache.h.

{
while(op_list){
op_list->cast_and_handle(*this);
aggregator_operation* tmp = op_list;
op_list=op_list->next;
tbb::internal::itt_store_word_with_release(tmp->status, uintptr_t(1));
}
}

References tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::aggregator_operation::cast_and_handle(), tbb::internal::itt_store_word_with_release(), tbb::interface6::internal::aggregated_operation< Derived >::next, and tbb::interface6::internal::aggregated_operation< Derived >::status.

Here is the call graph for this function:

## operator[]()

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

handle_object tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::operator[] | ( | key_type | k | ) |

inline

Definition at line 88 of file concurrent_lru_cache.h.

{
retrieve_aggregator_operation op(k);
my_aggregator.execute(&op);
if (op.is_new_value_needed()){
op.result().second.my_value = my_value_function(k);
__TBB_store_with_release(op.result().second.my_is_ready, true);
}else{
tbb::internal::spin_wait_while_eq(op.result().second.my_is_ready,false);
}
return handle_object(*this,op.result());
}

References tbb::internal::__TBB_store_with_release(), tbb::interface6::internal::aggregator< handler_type, operation_type >::execute(), tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::retrieve_aggregator_operation::is_new_value_needed(), tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_aggregator, tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_value_function, tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::retrieve_aggregator_operation::result(), and tbb::internal::spin_wait_while_eq().

Here is the call graph for this function:

## retrieve_serial()

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

map_storage_type::reference tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::retrieve_serial | ( | key_type | k,
|  | bool & | is_new_value_needed
| ) |  |

inline private

Definition at line 239 of file concurrent_lru_cache.h.

{
typename map_storage_type::iterator it = my_map_storage.find(k);
if (it == my_map_storage.end()){
it = my_map_storage.insert(it,std::make_pair(k,map_value_type(value_type(),0,my_lru_list.end(),false)));
is_new_value_needed = true;
}else {
typename lru_list_type::iterator list_it = it->second.my_lru_list_iterator;
if (list_it!=my_lru_list.end()) {
__TBB_ASSERT(!it->second.my_ref_counter,"item to be evicted should not have a live references");
//item is going to be used. Therefore it is not a subject for eviction
//so - remove it from LRU history.
my_lru_list.erase(list_it);
it->second.my_lru_list_iterator= my_lru_list.end();
}
}
++(it->second.my_ref_counter);
return *it;
}

References __TBB_ASSERT, tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_lru_list, and tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_map_storage.

Referenced by tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::retrieve_aggregator_operation::handle().

Here is the caller graph for this function:

## signal_end_of_usage()

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

void tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::signal_end_of_usage | ( | typename map_storage_type::reference | value_ref | ) |

inline private

Definition at line 100 of file concurrent_lru_cache.h.

{
signal_end_of_usage_aggregator_operation op(value_ref);
my_aggregator.execute(&op);
}

References tbb::interface6::internal::aggregator< handler_type, operation_type >::execute(), and tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_aggregator.

Referenced by tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::handle_object::operator=(), and tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::handle_object::~handle_object().

Here is the call graph for this function:
Here is the caller graph for this function:

## signal_end_of_usage_serial()

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

void tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::signal_end_of_usage_serial | ( | typename map_storage_type::reference | map_record_ref | ) |

inline private

Definition at line 258 of file concurrent_lru_cache.h.

{
typename map_storage_type::iterator it = my_map_storage.find(map_record_ref.first);
__TBB_ASSERT(it!=my_map_storage.end(),"cache should not return past-end iterators to outer world");
__TBB_ASSERT(&(*it) == &map_record_ref,"dangling reference has been returned to outside world? data race ?");
__TBB_ASSERT( my_lru_list.end()== std::find(my_lru_list.begin(),my_lru_list.end(),it),
"object in use should not be in list of unused objects ");
if (! --(it->second.my_ref_counter)){
//it was the last reference so put it to the LRU history
if (my_lru_list.size()>=my_number_of_lru_history_items){
//evict items in order to get a space
size_t number_of_elements_to_evict = 1 + my_lru_list.size() - my_number_of_lru_history_items;
for (size_t i=0; i<number_of_elements_to_evict; ++i){
typename map_storage_type::iterator it_to_evict = my_lru_list.back();
__TBB_ASSERT(!it_to_evict->second.my_ref_counter,"item to be evicted should not have a live references");
my_lru_list.pop_back();
my_map_storage.erase(it_to_evict);
}
}
my_lru_list.push_front(it);
it->second.my_lru_list_iterator = my_lru_list.begin();
}
}

References __TBB_ASSERT, tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_lru_list, tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_map_storage, and tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_number_of_lru_history_items.

Referenced by tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::signal_end_of_usage_aggregator_operation::handle().

Here is the caller graph for this function:

## Friends And Related Function Documentation

## tbb::internal::aggregating_functor< self_type, aggregated_operation_type >

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

friend class tbb::internal::aggregating_functor< self_type, aggregated_operation_type >

friend

Definition at line 68 of file concurrent_lru_cache.h.

## Member Data Documentation

## my_aggregator

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

aggregator_type tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_aggregator

private

Definition at line 76 of file concurrent_lru_cache.h.

Referenced by tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::concurrent_lru_cache(), tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::operator[](), and tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::signal_end_of_usage().

## my_lru_list

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

lru_list_type tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_lru_list

private

Definition at line 75 of file concurrent_lru_cache.h.

Referenced by tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::retrieve_serial(), and tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::signal_end_of_usage_serial().

## my_map_storage

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

map_storage_type tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_map_storage

private

Definition at line 74 of file concurrent_lru_cache.h.

Referenced by tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::retrieve_serial(), and tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::signal_end_of_usage_serial().

## my_number_of_lru_history_items

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

const std::size_t tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_number_of_lru_history_items

private

Definition at line 73 of file concurrent_lru_cache.h.

Referenced by tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::signal_end_of_usage_serial().

## my_value_function

template<typename key_type , typename value_type , typename value_functor_type = value_type (*)(key_type)>

value_function_type tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::my_value_function

private

Definition at line 72 of file concurrent_lru_cache.h.

Referenced by tbb::interface6::concurrent_lru_cache< key_type, value_type, value_functor_type >::operator[]().

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

- concurrent_lru_cache.h

__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::internal::itt_store_word_with_release
void itt_store_word_with_release(tbb::atomic< T > &dst, U src)
Definition: tbb_profiling.h:157
tbb::interface6::concurrent_lru_cache::my_value_function
value_function_type my_value_function
Definition: concurrent_lru_cache.h:72
tbb::interface6::internal::aggregator::execute
void execute(operation_type *op)
Definition: _aggregator_impl.h:152
tbb::internal::spin_wait_while_eq
void spin_wait_while_eq(const volatile T &location, U value)
Spin WHILE the value of the variable is equal to a given value.
Definition: tbb_machine.h:394
tbb::interface6::concurrent_lru_cache::my_number_of_lru_history_items
const std::size_t my_number_of_lru_history_items
Definition: concurrent_lru_cache.h:73
tbb::interface6::concurrent_lru_cache::my_lru_list
lru_list_type my_lru_list
Definition: concurrent_lru_cache.h:75
tbb::interface6::internal::aggregator::initialize_handler
void initialize_handler(handler_type h)
Definition: _aggregator_impl.h:150
tbb::internal::__TBB_store_with_release
void __TBB_store_with_release(volatile T &location, V value)
Definition: tbb_machine.h:716
tbb::interface6::concurrent_lru_cache::my_aggregator
aggregator_type my_aggregator
Definition: concurrent_lru_cache.h:76
tbb::interface6::concurrent_lru_cache::aggregator_function_type
tbb::internal::aggregating_functor< self_type, aggregated_operation_type > aggregator_function_type
Definition: concurrent_lru_cache.h:67
tbb::interface6::concurrent_lru_cache::my_map_storage
map_storage_type my_map_storage
Definition: concurrent_lru_cache.h:74

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.