misc: fix issues pointed out by msvc (#7316)
* do not move constant variables
* applet_manager: avoid possible use after move
* use constant references where pointed out by msvc
* extra_hid: initialize response
* ValidateSaveState: passing slot separately is not necessary
* common: mark HashCombine as nodiscard
* cityhash: remove use of using namespace std
* Prefix all size_t with std::
done automatically by executing regex replace `([^:0-9a-zA-Z_])size_t([^0-9a-zA-Z_])` -> `$1std::size_t$2`
based on 7d8f115
* shared_memory.cpp: fix log error format
* fix compiling with pch off
This commit is contained in:
parent
6069fac76d
commit
c8c2beaeff
73 changed files with 181 additions and 167 deletions
|
@ -30,7 +30,7 @@ namespace Common {
|
|||
#ifdef __APPLE__
|
||||
static std::string GetCPUString() {
|
||||
char buf[128];
|
||||
size_t buf_len = sizeof(buf);
|
||||
std::size_t buf_len = sizeof(buf);
|
||||
if (sysctlbyname("machdep.cpu.brand_string", &buf, &buf_len, NULL, 0) == -1) {
|
||||
return "Unknown";
|
||||
}
|
||||
|
|
|
@ -63,15 +63,15 @@ struct ABIFrameInfo {
|
|||
};
|
||||
|
||||
inline ABIFrameInfo ABI_CalculateFrameSize(std::bitset<64> regs, std::size_t frame_size) {
|
||||
const size_t gprs_count = (regs & ABI_ALL_GPRS).count();
|
||||
const size_t fprs_count = (regs & ABI_ALL_FPRS).count();
|
||||
const std::size_t gprs_count = (regs & ABI_ALL_GPRS).count();
|
||||
const std::size_t fprs_count = (regs & ABI_ALL_FPRS).count();
|
||||
|
||||
const size_t gprs_size = (gprs_count + 1) / 2 * 16;
|
||||
const size_t fprs_size = fprs_count * 16;
|
||||
const std::size_t gprs_size = (gprs_count + 1) / 2 * 16;
|
||||
const std::size_t fprs_size = fprs_count * 16;
|
||||
|
||||
size_t total_size = 0;
|
||||
std::size_t total_size = 0;
|
||||
total_size += gprs_size;
|
||||
const size_t fprs_base_subtraction = total_size;
|
||||
const std::size_t fprs_base_subtraction = total_size;
|
||||
total_size += fprs_size;
|
||||
total_size += frame_size;
|
||||
|
||||
|
@ -100,11 +100,11 @@ inline void ABI_PushRegisters(oaknut::CodeGenerator& code, std::bitset<64> regs,
|
|||
}
|
||||
|
||||
if (!gprs.empty()) {
|
||||
for (size_t i = 0; i < gprs.size() - 1; i += 2) {
|
||||
for (std::size_t i = 0; i < gprs.size() - 1; i += 2) {
|
||||
code.STP(gprs[i], gprs[i + 1], SP, i * sizeof(u64));
|
||||
}
|
||||
if (gprs.size() % 2 == 1) {
|
||||
const size_t i = gprs.size() - 1;
|
||||
const std::size_t i = gprs.size() - 1;
|
||||
code.STR(gprs[i], SP, i * sizeof(u64));
|
||||
}
|
||||
}
|
||||
|
@ -121,11 +121,11 @@ inline void ABI_PushRegisters(oaknut::CodeGenerator& code, std::bitset<64> regs,
|
|||
}
|
||||
|
||||
if (!fprs.empty()) {
|
||||
for (size_t i = 0; i < fprs.size() - 1; i += 2) {
|
||||
for (std::size_t i = 0; i < fprs.size() - 1; i += 2) {
|
||||
code.STP(fprs[i], fprs[i + 1], SP, frame_info.fprs_offset + i * (sizeof(u64) * 2));
|
||||
}
|
||||
if (fprs.size() % 2 == 1) {
|
||||
const size_t i = fprs.size() - 1;
|
||||
const std::size_t i = fprs.size() - 1;
|
||||
code.STR(fprs[i], SP, frame_info.fprs_offset + i * (sizeof(u64) * 2));
|
||||
}
|
||||
}
|
||||
|
@ -159,11 +159,11 @@ inline void ABI_PopRegisters(oaknut::CodeGenerator& code, std::bitset<64> regs,
|
|||
}
|
||||
|
||||
if (!gprs.empty()) {
|
||||
for (size_t i = 0; i < gprs.size() - 1; i += 2) {
|
||||
for (std::size_t i = 0; i < gprs.size() - 1; i += 2) {
|
||||
code.LDP(gprs[i], gprs[i + 1], SP, i * sizeof(u64));
|
||||
}
|
||||
if (gprs.size() % 2 == 1) {
|
||||
const size_t i = gprs.size() - 1;
|
||||
const std::size_t i = gprs.size() - 1;
|
||||
code.LDR(gprs[i], SP, i * sizeof(u64));
|
||||
}
|
||||
}
|
||||
|
@ -180,11 +180,11 @@ inline void ABI_PopRegisters(oaknut::CodeGenerator& code, std::bitset<64> regs,
|
|||
}
|
||||
|
||||
if (!fprs.empty()) {
|
||||
for (size_t i = 0; i < fprs.size() - 1; i += 2) {
|
||||
for (std::size_t i = 0; i < fprs.size() - 1; i += 2) {
|
||||
code.LDP(fprs[i], fprs[i + 1], SP, frame_info.fprs_offset + i * (sizeof(u64) * 2));
|
||||
}
|
||||
if (fprs.size() % 2 == 1) {
|
||||
const size_t i = fprs.size() - 1;
|
||||
const std::size_t i = fprs.size() - 1;
|
||||
code.LDR(fprs[i], SP, frame_info.fprs_offset + i * (sizeof(u64) * 2));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
namespace Common {
|
||||
|
||||
namespace detail {
|
||||
constexpr size_t DefaultCapacity = 0x1000;
|
||||
constexpr std::size_t DefaultCapacity = 0x1000;
|
||||
} // namespace detail
|
||||
|
||||
template <typename T, size_t Capacity = detail::DefaultCapacity>
|
||||
template <typename T, std::size_t Capacity = detail::DefaultCapacity>
|
||||
class SPSCQueue {
|
||||
static_assert((Capacity & (Capacity - 1)) == 0, "Capacity must be a power of two.");
|
||||
|
||||
|
@ -74,7 +74,7 @@ private:
|
|||
|
||||
template <PushMode Mode, typename... Args>
|
||||
bool Emplace(Args&&... args) {
|
||||
const size_t write_index = m_write_index.load(std::memory_order::relaxed);
|
||||
const std::size_t write_index = m_write_index.load(std::memory_order::relaxed);
|
||||
|
||||
if constexpr (Mode == PushMode::Try) {
|
||||
// Check if we have free slots to write to.
|
||||
|
@ -92,7 +92,7 @@ private:
|
|||
}
|
||||
|
||||
// Determine the position to write to.
|
||||
const size_t pos = write_index % Capacity;
|
||||
const std::size_t pos = write_index % Capacity;
|
||||
|
||||
// Emplace into the queue.
|
||||
new (std::addressof(m_data[pos])) T(std::forward<Args>(args)...);
|
||||
|
@ -109,7 +109,7 @@ private:
|
|||
|
||||
template <PopMode Mode>
|
||||
bool Pop(T& t, [[maybe_unused]] std::stop_token stop_token = {}) {
|
||||
const size_t read_index = m_read_index.load(std::memory_order::relaxed);
|
||||
const std::size_t read_index = m_read_index.load(std::memory_order::relaxed);
|
||||
|
||||
if constexpr (Mode == PopMode::Try) {
|
||||
// Check if the queue is empty.
|
||||
|
@ -136,7 +136,7 @@ private:
|
|||
}
|
||||
|
||||
// Determine the position to read from.
|
||||
const size_t pos = read_index % Capacity;
|
||||
const std::size_t pos = read_index % Capacity;
|
||||
|
||||
// Pop the data off the queue, moving it.
|
||||
t = std::move(m_data[pos]);
|
||||
|
@ -162,7 +162,7 @@ private:
|
|||
std::mutex consumer_cv_mutex;
|
||||
};
|
||||
|
||||
template <typename T, size_t Capacity = detail::DefaultCapacity>
|
||||
template <typename T, std::size_t Capacity = detail::DefaultCapacity>
|
||||
class MPSCQueue {
|
||||
public:
|
||||
template <typename... Args>
|
||||
|
@ -202,7 +202,7 @@ private:
|
|||
std::mutex write_mutex;
|
||||
};
|
||||
|
||||
template <typename T, size_t Capacity = detail::DefaultCapacity>
|
||||
template <typename T, std::size_t Capacity = detail::DefaultCapacity>
|
||||
class MPMCQueue {
|
||||
public:
|
||||
template <typename... Args>
|
||||
|
|
|
@ -40,11 +40,9 @@
|
|||
#define WORDS_BIGENDIAN 1
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef uint8_t uint8;
|
||||
typedef uint32_t uint32;
|
||||
typedef uint64_t uint64;
|
||||
typedef std::uint8_t uint8;
|
||||
typedef std::uint32_t uint32;
|
||||
typedef std::uint64_t uint64;
|
||||
|
||||
namespace Common {
|
||||
|
||||
|
@ -152,19 +150,19 @@ static uint64 HashLen17to32(const char* s, std::size_t len) {
|
|||
|
||||
// Return a 16-byte hash for 48 bytes. Quick and dirty.
|
||||
// Callers do best to use "random-looking" values for a and b.
|
||||
static pair<uint64, uint64> WeakHashLen32WithSeeds(uint64 w, uint64 x, uint64 y, uint64 z, uint64 a,
|
||||
uint64 b) {
|
||||
static std::pair<uint64, uint64> WeakHashLen32WithSeeds(uint64 w, uint64 x, uint64 y, uint64 z,
|
||||
uint64 a, uint64 b) {
|
||||
a += w;
|
||||
b = Rotate(b + a + z, 21);
|
||||
uint64 c = a;
|
||||
a += x;
|
||||
a += y;
|
||||
b += Rotate(a, 44);
|
||||
return make_pair(a + z, b + c);
|
||||
return std::make_pair(a + z, b + c);
|
||||
}
|
||||
|
||||
// Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
|
||||
static pair<uint64, uint64> WeakHashLen32WithSeeds(const char* s, uint64 a, uint64 b) {
|
||||
static std::pair<uint64, uint64> WeakHashLen32WithSeeds(const char* s, uint64 a, uint64 b) {
|
||||
return WeakHashLen32WithSeeds(Fetch64(s), Fetch64(s + 8), Fetch64(s + 16), Fetch64(s + 24), a,
|
||||
b);
|
||||
}
|
||||
|
@ -207,8 +205,8 @@ uint64 CityHash64(const char* s, std::size_t len) {
|
|||
uint64 x = Fetch64(s + len - 40);
|
||||
uint64 y = Fetch64(s + len - 16) + Fetch64(s + len - 56);
|
||||
uint64 z = HashLen16(Fetch64(s + len - 48) + len, Fetch64(s + len - 24));
|
||||
pair<uint64, uint64> v = WeakHashLen32WithSeeds(s + len - 64, len, z);
|
||||
pair<uint64, uint64> w = WeakHashLen32WithSeeds(s + len - 32, y + k1, x);
|
||||
std::pair<uint64, uint64> v = WeakHashLen32WithSeeds(s + len - 64, len, z);
|
||||
std::pair<uint64, uint64> w = WeakHashLen32WithSeeds(s + len - 32, y + k1, x);
|
||||
x = x * k1 + Fetch64(s);
|
||||
|
||||
// Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
|
||||
|
@ -276,7 +274,7 @@ uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed) {
|
|||
|
||||
// We expect len >= 128 to be the common case. Keep 56 bytes of state:
|
||||
// v, w, x, y, and z.
|
||||
pair<uint64, uint64> v, w;
|
||||
std::pair<uint64, uint64> v, w;
|
||||
uint64 x = Uint128Low64(seed);
|
||||
uint64 y = Uint128High64(seed);
|
||||
uint64 z = len * k1;
|
||||
|
|
|
@ -38,7 +38,7 @@ bool DynamicLibrary::Load(std::string_view filename) {
|
|||
if (!handle) {
|
||||
DWORD error_message_id = GetLastError();
|
||||
LPSTR message_buffer = nullptr;
|
||||
size_t size =
|
||||
std::size_t size =
|
||||
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr, error_message_id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
|
|
|
@ -1159,7 +1159,7 @@ std::size_t IOFile::ReadImpl(void* data, std::size_t length, std::size_t data_si
|
|||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static std::size_t pread(int fd, void* buf, size_t count, uint64_t offset) {
|
||||
static std::size_t pread(int fd, void* buf, std::size_t count, uint64_t offset) {
|
||||
long unsigned int read_bytes = 0;
|
||||
OVERLAPPED overlapped = {0};
|
||||
HANDLE file = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
|
||||
|
|
|
@ -37,7 +37,7 @@ static inline u64 ComputeStructHash64(const T& data) noexcept {
|
|||
* Combines the seed parameter with the provided hash, producing a new unique hash
|
||||
* Implementation from: http://boost.sourceforge.net/doc/html/boost/hash_combine.html
|
||||
*/
|
||||
inline u64 HashCombine(const u64 seed, const u64 hash) {
|
||||
[[nodiscard]] inline u64 HashCombine(const u64 seed, const u64 hash) {
|
||||
return seed ^ (hash + 0x9e3779b9 + (seed << 6) + (seed >> 2));
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ void CondvarWait(Condvar& cv, Lock& lock, std::stop_token token, Pred&& pred) {
|
|||
namespace std {
|
||||
namespace polyfill {
|
||||
|
||||
using stop_state_callback = size_t;
|
||||
using stop_state_callback = std::size_t;
|
||||
|
||||
class stop_state {
|
||||
public:
|
||||
|
|
|
@ -31,9 +31,9 @@ template <class T>
|
|||
class SlotVector {
|
||||
public:
|
||||
~SlotVector() noexcept {
|
||||
size_t index = 0;
|
||||
std::size_t index = 0;
|
||||
for (u64 bits : stored_bitset) {
|
||||
for (size_t bit = 0; bits; ++bit, bits >>= 1) {
|
||||
for (std::size_t bit = 0; bits; ++bit, bits >>= 1) {
|
||||
if ((bits & 1) != 0) {
|
||||
values[index + bit].object.~T();
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
ResetStorageBit(id.index);
|
||||
}
|
||||
|
||||
size_t size() const noexcept {
|
||||
std::size_t size() const noexcept {
|
||||
return values_capacity - free_list.size();
|
||||
}
|
||||
|
||||
|
@ -126,12 +126,12 @@ private:
|
|||
return free_index;
|
||||
}
|
||||
|
||||
void Reserve(size_t new_capacity) noexcept {
|
||||
void Reserve(std::size_t new_capacity) noexcept {
|
||||
Entry* const new_values = new Entry[new_capacity];
|
||||
size_t index = 0;
|
||||
std::size_t index = 0;
|
||||
for (u64 bits : stored_bitset) {
|
||||
for (size_t bit = 0; bits; ++bit, bits >>= 1) {
|
||||
const size_t i = index + bit;
|
||||
for (std::size_t bit = 0; bits; ++bit, bits >>= 1) {
|
||||
const std::size_t i = index + bit;
|
||||
if ((bits & 1) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ private:
|
|||
|
||||
stored_bitset.resize((new_capacity + 63) / 64);
|
||||
|
||||
const size_t old_free_size = free_list.size();
|
||||
const std::size_t old_free_size = free_list.size();
|
||||
free_list.resize(old_free_size + (new_capacity - values_capacity));
|
||||
std::iota(free_list.begin() + old_free_size, free_list.end(),
|
||||
static_cast<u32>(values_capacity));
|
||||
|
@ -155,7 +155,7 @@ private:
|
|||
}
|
||||
|
||||
Entry* values = nullptr;
|
||||
size_t values_capacity = 0;
|
||||
std::size_t values_capacity = 0;
|
||||
|
||||
std::vector<u64> stored_bitset;
|
||||
std::vector<u32> free_list;
|
||||
|
@ -165,7 +165,7 @@ private:
|
|||
|
||||
template <>
|
||||
struct std::hash<Common::SlotId> {
|
||||
size_t operator()(const Common::SlotId& id) const noexcept {
|
||||
std::size_t operator()(const Common::SlotId& id) const noexcept {
|
||||
return std::hash<u32>{}(id.index);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -23,23 +23,23 @@ namespace Common {
|
|||
|
||||
// a cache which evicts the least recently used item when it is full
|
||||
// the cache elements are statically allocated.
|
||||
template <class Key, class Value, size_t Size>
|
||||
template <class Key, class Value, std::size_t Size>
|
||||
class StaticLRUCache {
|
||||
public:
|
||||
using key_type = Key;
|
||||
using value_type = Value;
|
||||
using list_type = std::list<std::pair<Key, size_t>>;
|
||||
using list_type = std::list<std::pair<Key, std::size_t>>;
|
||||
using array_type = std::array<Value, Size>;
|
||||
|
||||
StaticLRUCache() = default;
|
||||
|
||||
~StaticLRUCache() = default;
|
||||
|
||||
size_t size() const {
|
||||
std::size_t size() const {
|
||||
return m_list.size();
|
||||
}
|
||||
|
||||
constexpr size_t capacity() const {
|
||||
constexpr std::size_t capacity() const {
|
||||
return m_array.size();
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
// lookup value in the cache
|
||||
auto i = find(key);
|
||||
if (i == m_list.cend()) {
|
||||
size_t next_index = size();
|
||||
std::size_t next_index = size();
|
||||
// insert item into the cache, but first check if it is full
|
||||
if (next_index >= capacity()) {
|
||||
// cache is full, evict the least recently used item
|
||||
|
@ -97,10 +97,10 @@ private:
|
|||
[&key](const auto& el) { return el.first == key; });
|
||||
}
|
||||
|
||||
size_t evict() {
|
||||
std::size_t evict() {
|
||||
// evict item from the end of most recently used list
|
||||
typename list_type::iterator i = --m_list.end();
|
||||
size_t evicted_index = i->second;
|
||||
std::size_t evicted_index = i->second;
|
||||
m_list.erase(i);
|
||||
return evicted_index;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Common {
|
||||
|
||||
template <size_t N>
|
||||
template <std::size_t N>
|
||||
struct StringLiteral {
|
||||
constexpr StringLiteral(const char (&str)[N]) {
|
||||
std::copy_n(str, N, value);
|
||||
|
|
|
@ -101,7 +101,7 @@ void SetCurrentThreadName(const char* name) {
|
|||
#elif defined(__linux__)
|
||||
// Linux limits thread names to 15 characters and will outright reject any
|
||||
// attempt to set a longer name with ERANGE.
|
||||
std::string truncated(name, std::min(strlen(name), static_cast<size_t>(15)));
|
||||
std::string truncated(name, std::min(strlen(name), static_cast<std::size_t>(15)));
|
||||
if (int e = pthread_setname_np(pthread_self(), truncated.c_str())) {
|
||||
errno = e;
|
||||
LOG_ERROR(Common, "Failed to set thread name to '{}': {}", truncated, GetLastErrorMsg());
|
||||
|
|
|
@ -25,7 +25,7 @@ class StatefulThreadWorker {
|
|||
static constexpr bool with_state = !std::is_same_v<StateType, void>;
|
||||
|
||||
struct DummyCallable {
|
||||
int operator()(size_t) const noexcept {
|
||||
int operator()(std::size_t) const noexcept {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
@ -33,12 +33,13 @@ class StatefulThreadWorker {
|
|||
using Task =
|
||||
std::conditional_t<with_state, UniqueFunction<void, StateType*>, UniqueFunction<void>>;
|
||||
using StateMaker =
|
||||
std::conditional_t<with_state, std::function<StateType(size_t)>, DummyCallable>;
|
||||
std::conditional_t<with_state, std::function<StateType(std::size_t)>, DummyCallable>;
|
||||
|
||||
public:
|
||||
explicit StatefulThreadWorker(size_t num_workers, std::string_view name, StateMaker func = {})
|
||||
explicit StatefulThreadWorker(std::size_t num_workers, std::string_view name,
|
||||
StateMaker func = {})
|
||||
: workers_queued{num_workers}, thread_name{name} {
|
||||
const auto lambda = [this, func](std::stop_token stop_token, size_t index) {
|
||||
const auto lambda = [this, func](std::stop_token stop_token, std::size_t index) {
|
||||
Common::SetCurrentThreadName(thread_name.data());
|
||||
{
|
||||
[[maybe_unused]] std::conditional_t<with_state, StateType, int> state{func(index)};
|
||||
|
@ -69,7 +70,7 @@ public:
|
|||
wait_condition.notify_all();
|
||||
};
|
||||
threads.reserve(num_workers);
|
||||
for (size_t i = 0; i < num_workers; ++i) {
|
||||
for (std::size_t i = 0; i < num_workers; ++i) {
|
||||
threads.emplace_back(lambda, i);
|
||||
}
|
||||
}
|
||||
|
@ -110,10 +111,10 @@ private:
|
|||
std::mutex queue_mutex;
|
||||
std::condition_variable_any condition;
|
||||
std::condition_variable wait_condition;
|
||||
std::atomic<size_t> work_scheduled{};
|
||||
std::atomic<size_t> work_done{};
|
||||
std::atomic<size_t> workers_stopped{};
|
||||
std::atomic<size_t> workers_queued{};
|
||||
std::atomic<std::size_t> work_scheduled{};
|
||||
std::atomic<std::size_t> work_done{};
|
||||
std::atomic<std::size_t> workers_stopped{};
|
||||
std::atomic<std::size_t> workers_queued{};
|
||||
std::string_view thread_name;
|
||||
std::vector<std::jthread> threads;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue