Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TConcurrentQueryManager.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Utility/Concurrent/TAtomicQuasiQueue.h>
6#include <Common/assertion.h>
7
8#include <vector>
9#include <utility>
10#include <iterator>
11
12#if PH_DEBUG
13#include <thread>
14#endif
15
16namespace ph::editor
17{
18
19template<typename Target>
21{
22public:
27
31 void processQueries(Target& target);
32
33private:
34 TAtomicQuasiQueue<TQuery<Target>> m_queries;
35 std::vector<TQuery<Target>> m_queryCache;
36
37#if PH_DEBUG
38 std::thread::id m_processingThreadId;
39#endif
40};
41
42template<typename Target>
44{
45 m_queries.enqueue(std::move(query));
46}
47
48template<typename Target>
50{
51#if PH_DEBUG
52 if(m_processingThreadId == std::thread::id{})
53 {
54 m_processingThreadId = std::this_thread::get_id();
55 }
56 PH_ASSERT(std::this_thread::get_id() == m_processingThreadId);
57#endif
58
59 TQuery<Target> query;
60 while(m_queries.tryDequeue(&query))
61 {
62 // The query can simply be skipped if canceled
63 if(query.isCanceled())
64 {
65 continue;
66 }
67
68 if(!query.run(target))
69 {
70 m_queryCache.push_back(std::move(query));
71 }
72 }
73
74 // Queue queries that were not finished back
75 m_queries.enqueueBulk(std::make_move_iterator(m_queryCache.begin()), m_queryCache.size());
76 m_queryCache.clear();
77}
78
79}// end namespace ph::editor
Definition TConcurrentQueryManager.h:21
void processQueries(Target &target)
Process all added queries. Need to be called on the same thread consistently.
Definition TConcurrentQueryManager.h:49
void addQuery(TQuery< Target > query)
Add a query from any thread.
Definition TConcurrentQueryManager.h:43
Definition TQuery.h:29
bool isCanceled() const
Whether the query is canceled.
Definition TQuery.ipp:88
void clear()
Clear the underlying query performer. After this call, isEmpty() is true.
Definition TQuery.h:99
bool run(Target &target)
Definition TQuery.ipp:40
Definition ph_editor.h:10