Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
ResourceCache.cpp
Go to the documentation of this file.
1
2
4
7
9
10namespace Divide {
11
13eastl::set<size_t> ResourceLoadLock::s_loadingHashes;
14
16vector<ResourcePoolBase*> ResourceCache::s_resourcePools;
17
19 : _loadingHash(hash)
20{
21 while (!SetLoading(_loadingHash))
22 {
24 {
26 }
27 else
28 {
30 }
31 }
32}
33
35{
37 {
38 DIVIDE_UNEXPECTED_CALL_MSG( "ResourceLoadLock failed to remove a resource lock!" );
39 }
40}
41
42bool ResourceLoadLock::SetLoading(const size_t hash)
43{
44 {
46 if (s_loadingHashes.find( hash ) != std::cend( s_loadingHashes ))
47 {
48 return false;
49 }
50 }
51
53 if (s_loadingHashes.find(hash) != std::cend(s_loadingHashes))
54 {
55 return false;
56 }
57
58 s_loadingHashes.insert(hash);
59 return true;
60}
61
63{
65 return s_loadingHashes.erase(hash) == 1u;
66}
67
70bool ResourceCache::s_enabled = false;
71
73 : _api(api)
74{
76}
77
79{
80}
81
83{
85 s_resourcePools.push_back( pool );
86}
87
89{
90 s_context = &context;
91 s_renderAPI = renderAPI;
92 s_enabled = true;
93}
94
96{
97 s_enabled = false;
98 Console::printfn(LOCALE_STR("STOP_RESOURCE_CACHE"));
99
100 for ( ResourcePoolBase* pool : s_resourcePools)
101 {
102 pool->processDeletionQueue();
103 }
104}
105
107{
108 for ( ResourcePoolBase* pool : s_resourcePools )
109 {
110 pool->printResources( true );
111 }
112
114}
115
117{
118 for ( ResourcePoolBase* pool : s_resourcePools )
119 {
120 pool->processDeletionQueue();
121 }
122}
123
125{
126 NOP();
127}
128
129} //namespace Divide
#define LOCALE_STR(X)
Definition: Localization.h:91
#define NOP()
#define DIVIDE_UNEXPECTED_CALL_MSG(X)
TaskPool & taskPool(const TaskPoolType type) noexcept
static void OnFrameEnd()
static Mutex s_poolLock
static vector< ResourcePoolBase * > s_resourcePools
static void OnFrameStart()
static void RegisterPool(ResourcePoolBase *pool)
static PlatformContext * s_context
static RenderAPI s_renderAPI
static void Init(RenderAPI renderAPI, PlatformContext &context)
static void PrintLeakedResources()
static eastl::set< size_t > s_loadingHashes
Definition: ResourceCache.h:58
static SharedMutex s_hashLock
Definition: ResourceCache.h:57
static bool SetLoadingFinished(size_t hash)
static bool SetLoading(size_t hash)
ResourceLoadLock(size_t hash, PlatformContext &context)
void threadWaiting()
Definition: TaskPool.cpp:341
bool isMainThread() noexcept
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::lock_guard< mutex > LockGuard
Definition: SharedMutex.h:55
std::mutex Mutex
Definition: SharedMutex.h:40
void PlatformContextIdleCall()
std::shared_mutex SharedMutex
Definition: SharedMutex.h:43
std::unique_lock< mutex > UniqueLock
Definition: SharedMutex.h:52
std::shared_lock< mutex > SharedLock
Definition: SharedMutex.h:49
static void Flush()
Definition: Console.cpp:126
static NO_INLINE void printfn(const char *format, T &&... args)
ResourcePoolBase(RenderAPI api)