Skip to content

Commit

Permalink
Ensure compile-time initialization of static objects in sysmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
averne committed May 22, 2024
1 parent 5c49c21 commit 8fe69b0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export FZ_VERSION = 2.5.0
export FZ_VERSION = 2.5.1
export FZ_COMMIT = $(shell git rev-parse --short HEAD)
export FZ_TID = 0100000000000F12

Expand Down
33 changes: 29 additions & 4 deletions sysmodule/src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,40 @@ enum FizeauProfileState: std::uint32_t {
Night,
};

struct Context {
bool is_lite = false;
constexpr FizeauSettings default_settings = {
.temperature = DEFAULT_TEMP,
.gamma = DEFAULT_GAMMA,
.saturation = DEFAULT_SAT,
.luminance = DEFAULT_LUMA,
.range = DEFAULT_RANGE,
.filter = ColorFilter_None,
};

bool is_active = false;
struct Context {
bool is_lite = false, is_active = false;

FizeauProfileId internal_profile = FizeauProfileId_Invalid,
external_profile = FizeauProfileId_Invalid;

std::array<FizeauProfile, FizeauProfileId_Total> profiles = {};
std::array<FizeauProfile, FizeauProfileId_Total> profiles = {
FizeauProfile{
.day_settings = default_settings,
.night_settings = default_settings,
},
FizeauProfile{
.day_settings = default_settings,
.night_settings = default_settings,
},
FizeauProfile{
.day_settings = default_settings,
.night_settings = default_settings,
},
FizeauProfile{
.day_settings = default_settings,
.night_settings = default_settings,
},
};

std::array<FizeauProfileState, FizeauProfileId_Total> profile_states = {};

DisplayController::Csc saved_internal_csc = {},
Expand Down
8 changes: 4 additions & 4 deletions sysmodule/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ extern "C" void __appExit(void) {

} // extern "C"

static fz::Context context = {};
static fz::DisplayController disp = {};
static fz::ProfileManager profile(context, disp);
static fz::Server server (context, profile);
static constinit fz::Context context = {};
static constinit fz::DisplayController disp = {};
static constinit fz::ProfileManager profile(context, disp);
static constinit fz::Server server (context, profile);

void delete_chainloader() {
auto rc = fsInitialize();
Expand Down
18 changes: 9 additions & 9 deletions sysmodule/src/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ constexpr float dimmed_luma_internal = -0.1f, dimmed_luma_external = -0.7f; // O

class ProfileManager {
public:
ProfileManager(Context &context, DisplayController &disp): context(context), disp(disp) { }
constexpr ProfileManager(Context &context, DisplayController &disp): context(context), disp(disp) { }

Result initialize();
Result finalize();
Expand All @@ -48,19 +48,19 @@ class ProfileManager {
DisplayController &disp;

UEvent thread_exit_event = {};
Thread transition_thread, event_monitor_thread;
std::uint8_t transition_thread_stack[0x2000] alignas(0x1000),
event_monitor_thread_stack[0x1000] alignas(0x1000);
Thread transition_thread = {}, event_monitor_thread = {};
std::uint8_t transition_thread_stack[0x2000] alignas(0x1000) = {},
event_monitor_thread_stack[0x1000] alignas(0x1000) = {};

PscPmModule psc_module;
PscPmModule psc_module = {};
bool mmio_available = true;
std::uint64_t disp_va_base = 0;

Event operation_mode_event;
AppletOperationMode operation_mode;
Event operation_mode_event = {};
AppletOperationMode operation_mode = {};

Event activity_event;
std::uint64_t activity_tick;
Event activity_event = {};
std::uint64_t activity_tick = {};
bool is_dimming = false;

Mutex commit_mutex = {};
Expand Down
2 changes: 1 addition & 1 deletion sysmodule/src/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Server: public IpcServer {
constexpr static inline int ServiceNumSessions = 2;

public:
Server(Context &context, ProfileManager &profile): context(context), profile(profile) { }
constexpr Server(Context &context, ProfileManager &profile): IpcServer(), context(context), profile(profile) { }

Result initialize() {
return ipcServerInit(this, Server::ServiceName.data(), Server::ServiceNumSessions);
Expand Down

0 comments on commit 8fe69b0

Please sign in to comment.