Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix initialization-order-fiasco #32854

Merged
merged 12 commits into from
Apr 26, 2024
2 changes: 0 additions & 2 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ class DeviceTypeResolver : public chip::Access::AccessControl::DeviceTypeResolve

namespace chip {

Server Server::sServer;

#if CHIP_CONFIG_ENABLE_SERVER_IM_EVENT
#define CHIP_NUM_EVENT_LOGGING_BUFFERS 3
static uint8_t sInfoEventBuffer[CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE];
Expand Down
8 changes: 5 additions & 3 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,15 @@ class Server
return System::SystemClock().GetMonotonicMicroseconds64() - mInitTimestamp;
}

static Server & GetInstance() { return sServer; }
static Server & GetInstance()
{
static Server * sServer = new Server();
return *sServer;
}

private:
Server() {}

static Server sServer;

void InitFailSafe();
void OnPlatformEvent(const DeviceLayer::ChipDeviceEvent & event);
void CheckServerReadyEvent();
Expand Down
Loading