summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2020-12-04 23:57:18 -0800
committerGravatar bunnei2020-12-06 00:27:13 -0800
commit8fd921557fc8e830ee8330fc1dcf6dcc9963c4c2 (patch)
tree9cd1a9781965160a0c22141c57c718fa737a70a9 /src
parenthle: kernel: KAffinityMask: Various style fixes based on code review feedback. (diff)
downloadyuzu-8fd921557fc8e830ee8330fc1dcf6dcc9963c4c2.tar.gz
yuzu-8fd921557fc8e830ee8330fc1dcf6dcc9963c4c2.tar.xz
yuzu-8fd921557fc8e830ee8330fc1dcf6dcc9963c4c2.zip
hle: kernel: KPriorityQueue: Various style fixes based on code review feedback.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/k_priority_queue.h65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/core/hle/kernel/k_priority_queue.h b/src/core/hle/kernel/k_priority_queue.h
index d374f5c00..01a577d0c 100644
--- a/src/core/hle/kernel/k_priority_queue.h
+++ b/src/core/hle/kernel/k_priority_queue.h
@@ -7,6 +7,8 @@
7 7
8#pragma once 8#pragma once
9 9
10#include <array>
11
10#include "common/assert.h" 12#include "common/assert.h"
11#include "common/bit_set.h" 13#include "common/bit_set.h"
12#include "common/bit_util.h" 14#include "common/bit_util.h"
@@ -17,7 +19,7 @@ namespace Kernel {
17class Thread; 19class Thread;
18 20
19template <typename T> 21template <typename T>
20concept KPriorityQueueAffinityMask = !std::is_reference<T>::value && requires(T & t) { 22concept KPriorityQueueAffinityMask = !std::is_reference_v<T> && requires(T & t) {
21 { t.GetAffinityMask() } 23 { t.GetAffinityMask() }
22 ->std::convertible_to<u64>; 24 ->std::convertible_to<u64>;
23 {t.SetAffinityMask(std::declval<u64>())}; 25 {t.SetAffinityMask(std::declval<u64>())};
@@ -29,7 +31,7 @@ concept KPriorityQueueAffinityMask = !std::is_reference<T>::value && requires(T
29}; 31};
30 32
31template <typename T> 33template <typename T>
32concept KPriorityQueueMember = !std::is_reference<T>::value && requires(T & t) { 34concept KPriorityQueueMember = !std::is_reference_v<T> && requires(T & t) {
33 {typename T::QueueEntry()}; 35 {typename T::QueueEntry()};
34 {(typename T::QueueEntry()).Initialize()}; 36 {(typename T::QueueEntry()).Initialize()};
35 {(typename T::QueueEntry()).SetPrev(std::addressof(t))}; 37 {(typename T::QueueEntry()).SetPrev(std::addressof(t))};
@@ -54,8 +56,8 @@ concept KPriorityQueueMember = !std::is_reference<T>::value && requires(T & t) {
54template <typename Member, size_t _NumCores, int LowestPriority, int HighestPriority> 56template <typename Member, size_t _NumCores, int LowestPriority, int HighestPriority>
55requires KPriorityQueueMember<Member> class KPriorityQueue { 57requires KPriorityQueueMember<Member> class KPriorityQueue {
56public: 58public:
57 using AffinityMaskType = typename std::remove_cv<typename std::remove_reference<decltype( 59 using AffinityMaskType = typename std::remove_cv_t<
58 std::declval<Member>().GetAffinityMask())>::type>::type; 60 typename std::remove_reference<decltype(std::declval<Member>().GetAffinityMask())>::type>;
59 61
60 static_assert(LowestPriority >= 0); 62 static_assert(LowestPriority >= 0);
61 static_assert(HighestPriority >= 0); 63 static_assert(HighestPriority >= 0);
@@ -77,12 +79,12 @@ private:
77public: 79public:
78 class KPerCoreQueue { 80 class KPerCoreQueue {
79 private: 81 private:
80 Entry root[NumCores]; 82 std::array<Entry, NumCores> root{};
81 83
82 public: 84 public:
83 constexpr KPerCoreQueue() : root() { 85 constexpr KPerCoreQueue() {
84 for (size_t i = 0; i < NumCores; i++) { 86 for (auto& per_core_root : root) {
85 this->root[i].Initialize(); 87 per_core_root.Initialize();
86 } 88 }
87 } 89 }
88 90
@@ -101,7 +103,7 @@ public:
101 tail_entry.SetNext(member); 103 tail_entry.SetNext(member);
102 this->root[core].SetPrev(member); 104 this->root[core].SetPrev(member);
103 105
104 return (tail == nullptr); 106 return tail == nullptr;
105 } 107 }
106 108
107 constexpr bool PushFront(s32 core, Member* member) { 109 constexpr bool PushFront(s32 core, Member* member) {
@@ -147,21 +149,19 @@ public:
147 }; 149 };
148 150
149 class KPriorityQueueImpl { 151 class KPriorityQueueImpl {
150 private:
151 KPerCoreQueue queues[NumPriority];
152 Common::BitSet64<NumPriority> available_priorities[NumCores];
153
154 public: 152 public:
155 constexpr KPriorityQueueImpl() : queues(), available_priorities() {} 153 constexpr KPriorityQueueImpl() = default;
156 154
157 constexpr void PushBack(s32 priority, s32 core, Member* member) { 155 constexpr void PushBack(s32 priority, s32 core, Member* member) {
158 ASSERT(IsValidCore(core)); 156 ASSERT(IsValidCore(core));
159 ASSERT(IsValidPriority(priority)); 157 ASSERT(IsValidPriority(priority));
160 158
161 if (priority <= LowestPriority) { 159 if (priority > LowestPriority) {
162 if (this->queues[priority].PushBack(core, member)) { 160 return;
163 this->available_priorities[core].SetBit(priority); 161 }
164 } 162
163 if (this->queues[priority].PushBack(core, member)) {
164 this->available_priorities[core].SetBit(priority);
165 } 165 }
166 } 166 }
167 167
@@ -169,10 +169,12 @@ public:
169 ASSERT(IsValidCore(core)); 169 ASSERT(IsValidCore(core));
170 ASSERT(IsValidPriority(priority)); 170 ASSERT(IsValidPriority(priority));
171 171
172 if (priority <= LowestPriority) { 172 if (priority > LowestPriority) {
173 if (this->queues[priority].PushFront(core, member)) { 173 return;
174 this->available_priorities[core].SetBit(priority); 174 }
175 } 175
176 if (this->queues[priority].PushFront(core, member)) {
177 this->available_priorities[core].SetBit(priority);
176 } 178 }
177 } 179 }
178 180
@@ -180,10 +182,12 @@ public:
180 ASSERT(IsValidCore(core)); 182 ASSERT(IsValidCore(core));
181 ASSERT(IsValidPriority(priority)); 183 ASSERT(IsValidPriority(priority));
182 184
183 if (priority <= LowestPriority) { 185 if (priority > LowestPriority) {
184 if (this->queues[priority].Remove(core, member)) { 186 return;
185 this->available_priorities[core].ClearBit(priority); 187 }
186 } 188
189 if (this->queues[priority].Remove(core, member)) {
190 this->available_priorities[core].ClearBit(priority);
187 } 191 }
188 } 192 }
189 193
@@ -246,6 +250,10 @@ public:
246 return nullptr; 250 return nullptr;
247 } 251 }
248 } 252 }
253
254 private:
255 std::array<KPerCoreQueue, NumPriority> queues{};
256 std::array<Common::BitSet64<NumPriority>, NumCores> available_priorities{};
249 }; 257 };
250 258
251private: 259private:
@@ -254,7 +262,7 @@ private:
254 262
255private: 263private:
256 constexpr void ClearAffinityBit(u64& affinity, s32 core) { 264 constexpr void ClearAffinityBit(u64& affinity, s32 core) {
257 affinity &= ~(u64(1ul) << core); 265 affinity &= ~(u64(1) << core);
258 } 266 }
259 267
260 constexpr s32 GetNextCore(u64& affinity) { 268 constexpr s32 GetNextCore(u64& affinity) {
@@ -313,8 +321,7 @@ private:
313 } 321 }
314 322
315public: 323public:
316 constexpr KPriorityQueue() : scheduled_queue(), suggested_queue() { // ... 324 constexpr KPriorityQueue() = default;
317 }
318 325
319 // Getters. 326 // Getters.
320 constexpr Member* GetScheduledFront(s32 core) const { 327 constexpr Member* GetScheduledFront(s32 core) const {