-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathMeshCache.h
66 lines (46 loc) · 1.35 KB
/
MeshCache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include "MeshWorkQueue.h"
#include "StudioMesh.h"
// qt
#include <QMutex>
// std
#include <list>
#include <map>
namespace shapeworks {
// mesh cache type
using CacheMap = std::map<MeshWorkItem, MeshHandle>;
// LRU list
using CacheList = std::list<MeshWorkItem>;
/**
* @brief Thread safe cache for meshes index by shape
*
* The MeshCache implements a std::map keyed by shape (list of points) with MeshHandle values.
* It is thread-safe and can be used from any thread.
*/
class MeshCache {
public:
MeshCache();
void set_cache_enabled(bool enabled) { cache_enabled_ = enabled; }
void set_memory_percent(int percent) { cache_memory_percent_ = percent; }
MeshHandle get_mesh(const MeshWorkItem& vector);
void insert_mesh(const MeshWorkItem& item, MeshHandle mesh);
void clear();
private:
void freeSpaceForAmount(size_t allocation);
static long long get_total_physical_memory();
static long long get_total_addressable_memory();
static long long get_total_addressable_physical_memory();
// mesh cache
CacheMap mesh_cache_;
// lrc list
CacheList cache_list_;
// size of memory in use by the cache
size_t current_memory_size_ = 0;
// maximum memory
long long max_memory_ = 0;
// for concurrent access
QMutex mutex_;
bool cache_enabled_ = true;
int cache_memory_percent_ = 0;
};
} // namespace shapeworks