mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 17:00:19 +02:00
Merge pull request #4984 from Sonicadvance1/shm_guaranteed_or_your_money_back
SHMStats: Add a 16-byte alignment guarantee
This commit is contained in:
2 files changed
+8
-2
No files matched your search
@@ -39,10 +39,12 @@ enum class AppType : uint8_t {
|
||||
WIN_WOW64,
|
||||
};
|
||||
|
||||
// Only append new members to the end of {ThreadStatsHeader, ThreadStats} to allow old tools time to support new information.
|
||||
// FEX isn't guaranteeing /not/ breaking compatibility with versions, but trying to not cause too much churn.
|
||||
struct ThreadStatsHeader {
|
||||
uint8_t Version;
|
||||
AppType app_type;
|
||||
uint8_t _pad[2];
|
||||
uint16_t ThreadStatsSize;
|
||||
char fex_version[48];
|
||||
std::atomic<uint32_t> Head;
|
||||
std::atomic<uint32_t> Size;
|
||||
@@ -63,6 +65,9 @@ struct ThreadStats {
|
||||
uint64_t AccumulatedFloatFallbackCount;
|
||||
};
|
||||
|
||||
// Ensure 16-byte alignment to take advantage of ARM single-copy atomicity.
|
||||
static_assert(sizeof(ThreadStats) % 16 == 0, "Needs to be 16-byte aligned!");
|
||||
|
||||
template<typename T, size_t FlatOffset = 0>
|
||||
class AccumulationBlock final {
|
||||
public:
|
||||
|
||||
@@ -13,10 +13,11 @@ void StatAllocBase::SaveHeader(FEXCore::SHMStats::AppType AppType) {
|
||||
Head = reinterpret_cast<FEXCore::SHMStats::ThreadStatsHeader*>(Base);
|
||||
Head->Size.store(CurrentSize, std::memory_order_relaxed);
|
||||
Head->Version = FEXCore::SHMStats::STATS_VERSION;
|
||||
Head->app_type = AppType;
|
||||
Head->ThreadStatsSize = sizeof(FEXCore::SHMStats::ThreadStats);
|
||||
|
||||
std::string_view GitString = GIT_DESCRIBE_STRING;
|
||||
strncpy(Head->fex_version, GitString.data(), std::min(GitString.size(), sizeof(Head->fex_version)));
|
||||
Head->app_type = AppType;
|
||||
|
||||
Stats = reinterpret_cast<FEXCore::SHMStats::ThreadStats*>(reinterpret_cast<uint64_t>(Base) + sizeof(FEXCore::SHMStats::ThreadStatsHeader));
|
||||
|
||||
|
||||
Reference in new issue
Block a user