24template<
typename Value>
37 if (
m_set.insert(value).second)
70template<
typename Key,
typename Value>
76 void set(
const Key &name,
const Value &value)
82 bool get(
const Key &name, Value *result)
const
96 std::vector<Value> result;
99 result.push_back(it->second);
119 template<
typename Key,
typename U,
typename Caller,
typename CallerData>
140 m_queue.push_back(std::move(t));
152 T t = std::move(
m_queue.front());
165 T t = std::move(
m_queue.front());
179 T t = std::move(
m_queue.front());
189 T t = std::move(
m_queue.back());
205 T t = std::move(
m_queue.back());
219 T t = std::move(
m_queue.back());
238template<
typename K,
typename V>
242 LRUCache(
size_t limit,
void (*cache_miss)(
void *data,
const K &key, V *dest),
264 typename cache_type::iterator it =
m_map.find(key);
266 if (it !=
m_map.end()) {
300 typedef typename std::template pair<typename std::template list<K>::iterator, V>
cache_entry_t;
322template<
typename K,
typename V>
327 static_assert(std::is_default_constructible<V>::value,
328 "Value type must be default constructible");
329 static_assert(std::is_constructible<bool, V>::value,
330 "Value type must be convertible to bool");
331 static_assert(std::is_move_assignable<V>::value,
332 "Value type must be move-assignable");
350 const V &
get(const K &key)
const {
352 auto it =
m_new.find(key);
353 if (it !=
m_new.end())
367 void put(
const K &key,
const V &value) {
384 void put(
const K &key, V &&value) {
395 m_new[key] = std::move(value);
404 auto it =
m_new.find(key);
405 if (it !=
m_new.end()) {
406 ret = std::move(it->second);
414 ret = std::move(it->second);
435 assert(
m_new.empty());
440 n += !it.second ? 0 : 1;
473 static constexpr size_t unknown =
static_cast<size_t>(-1);
478 if (!
m_new.empty()) {
501 assert(
m->m_iterating);
503 if (!
m->m_iterating) {
505 m->collect_garbage();
509 auto begin() {
return m->m_values.cbegin(); }
510 auto end() {
return m->m_values.cend(); }
514 assert(
m->m_iterating < std::numeric_limits<
decltype(
m_iterating)>::max());
#define DISABLE_CLASS_COPY(C)
Definition basic_macros.h:26
#define ALLOW_CLASS_MOVE(C)
Definition basic_macros.h:32
Definition exceptions.h:60
Definition container.h:240
size_t m_limit
Definition container.h:299
cache_type m_map
Definition container.h:302
LRUCache(size_t limit, void(*cache_miss)(void *data, const K &key, V *dest), void *data)
Definition container.h:242
void setLimit(size_t limit)
Definition container.h:250
void * m_cache_miss_data
Definition container.h:298
const V * lookupCache(K key)
Definition container.h:262
void invalidate()
Definition container.h:256
std::list< K > m_queue
Definition container.h:304
std::template pair< typename std::template list< K >::iterator, V > cache_entry_t
Definition container.h:300
std::template map< K, cache_entry_t > cache_type
Definition container.h:301
void(* m_cache_miss)(void *data, const K &key, V *dest)
Definition container.h:297
Definition container.h:324
const V & get(const K &key) const
Definition container.h:350
size_t m_garbage
Definition container.h:526
V mapped_type
Definition container.h:335
~ModifySafeMap()
Definition container.h:342
K key_type
Definition container.h:334
void clear()
Definition container.h:459
size_t size() const
Definition container.h:429
auto iter()
Definition container.h:457
void put(const K &key, V &&value)
Definition container.h:384
ModifySafeMap()
Definition container.h:337
V take(const K &key)
Definition container.h:401
static constexpr size_t GC_MIN_SIZE
Definition container.h:528
static constexpr size_t unknown
Definition container.h:473
void put(const K &key, const V &value)
Definition container.h:367
void collect_garbage()
Definition container.h:485
bool empty() const
Definition container.h:445
bool remove(const K &key)
Definition container.h:424
std::map< K, V > m_values
Definition container.h:522
unsigned int m_iterating
Definition container.h:524
static const V null_value
Definition container.h:470
void merge_new()
Definition container.h:476
std::map< K, V > m_new
Definition container.h:523
Definition container.h:72
std::vector< Value > getValues() const
Definition container.h:93
bool get(const Key &name, Value *result) const
Definition container.h:82
std::map< Key, Value > m_values
Definition container.h:106
std::mutex m_mutex
Definition container.h:107
void set(const Key &name, const Value &value)
Definition container.h:76
void clear()
Definition container.h:103
Definition container.h:117
bool empty() const
Definition container.h:124
void push_back(T &&t)
Definition container.h:137
std::deque< T > m_queue
Definition container.h:229
Semaphore m_signal
Definition container.h:231
T pop_front(u32 wait_time_max_ms)
Definition container.h:160
T pop_back(u32 wait_time_max_ms=0)
Definition container.h:184
T pop_frontNoEx()
Definition container.h:173
T pop_backNoEx()
Definition container.h:213
std::deque< T > & getQueue()
Definition container.h:227
std::mutex m_mutex
Definition container.h:230
T pop_backNoEx(u32 wait_time_max_ms)
Definition container.h:200
T pop_frontNoEx(u32 wait_time_max_ms)
Definition container.h:147
void push_back(const T &t)
Definition container.h:130
std::mutex & getMutex()
Definition container.h:225
Notes for RequestQueue usage.
Definition thread.h:85
Definition semaphore.h:18
void post(unsigned int num=1)
Definition semaphore.cpp:70
void wait()
Definition semaphore.cpp:85
Definition container.h:26
u32 size() const
Definition container.h:56
void pop_front()
Definition container.h:45
bool push_back(const Value &value)
Definition container.h:35
std::queue< Value > m_queue
Definition container.h:63
std::set< Value > m_set
Definition container.h:62
const Value & front() const
Definition container.h:51
#define sanity_check(expr)
Definition debug.h:56
std::lock_guard< std::mutex > MutexAutoLock
Definition mutex_auto_lock.h:31
Definition container.h:498
ModifySafeMap< K, V > * m
Definition container.h:518
IterationHelper(ModifySafeMap< K, V > *parent)
Definition container.h:513
~IterationHelper()
Definition container.h:500
auto end()
Definition container.h:510
auto begin()
Definition container.h:509