[cpp23] Remove usage of std::aligned_storage in nearby

Deprecated in C++23. Details in https://crbug.com/388068052.

PiperOrigin-RevId: 722745132
This commit is contained in:
hai007
2025-02-03 12:02:21 -08:00
committed by Copybara-Service
parent e76adeab50
commit 97690c6996
4 changed files with 16 additions and 36 deletions
@@ -43,9 +43,8 @@ ThroughputRecorder::ThroughputRecorder(int64_t payload_id)
: payload_id_(payload_id) {}
ThroughputRecorderContainer& ThroughputRecorderContainer::GetInstance() {
static std::aligned_storage_t<sizeof(ThroughputRecorderContainer),
alignof(ThroughputRecorderContainer)>
storage;
alignas(ThroughputRecorderContainer) static char
storage[sizeof(ThroughputRecorderContainer)];
static ThroughputRecorderContainer* env =
new (&storage) ThroughputRecorderContainer();
return *env;
@@ -95,17 +95,10 @@ MultiplexSocket::MultiplexSocket(std::shared_ptr<MediumSocket> physical_socket)
absl::flat_hash_map<std::pair<std::string, Medium>,
MultiplexIncomingConnectionCb>&
MultiplexSocket::GetIncomingConnectionCallbacks() {
static std::aligned_storage_t<
sizeof(absl::flat_hash_map<std::pair<std::string, Medium>,
MultiplexIncomingConnectionCb>),
alignof(absl::flat_hash_map<std::pair<std::string, Medium>,
MultiplexIncomingConnectionCb>)>
storage;
static absl::flat_hash_map<std::pair<std::string, Medium>,
MultiplexIncomingConnectionCb>*
incoming_connection_callbacks =
new (&storage) absl::flat_hash_map<std::pair<std::string, Medium>,
MultiplexIncomingConnectionCb>();
using MapType = absl::flat_hash_map<std::pair<std::string, Medium>,
MultiplexIncomingConnectionCb>;
alignas(MapType) static char storage[sizeof(MapType)];
static MapType* incoming_connection_callbacks = new (&storage) MapType();
return *incoming_connection_callbacks;
}
@@ -121,23 +114,18 @@ MultiplexSocket* MultiplexSocket::CreateIncomingSocket(
static MultiplexSocket* multiplex_incoming_socket = nullptr;
switch (physical_socket->GetMedium()) {
case Medium::BLUETOOTH:
static std::aligned_storage_t<sizeof(MultiplexSocket),
alignof(MultiplexSocket)>
storage_bt;
alignas(MultiplexSocket) static char storage_bt[sizeof(MultiplexSocket)];
multiplex_incoming_socket =
new (&storage_bt) MultiplexSocket(physical_socket);
break;
case Medium::BLE:
static std::aligned_storage_t<sizeof(MultiplexSocket),
alignof(MultiplexSocket)>
storage_ble;
alignas(MultiplexSocket) static char storage_ble[sizeof(MultiplexSocket)];
multiplex_incoming_socket =
new (&storage_ble) MultiplexSocket(physical_socket);
break;
case Medium::WIFI_LAN:
static std::aligned_storage_t<sizeof(MultiplexSocket),
alignof(MultiplexSocket)>
storage_wlan;
alignas(
MultiplexSocket) static char storage_wlan[sizeof(MultiplexSocket)];
multiplex_incoming_socket =
new (&storage_wlan) MultiplexSocket(physical_socket);
break;
@@ -169,23 +157,18 @@ MultiplexSocket* MultiplexSocket::CreateOutgoingSocket(
static MultiplexSocket* multiplex_outgoing_socket = nullptr;
switch (physical_socket->GetMedium()) {
case Medium::BLUETOOTH:
static std::aligned_storage_t<sizeof(MultiplexSocket),
alignof(MultiplexSocket)>
storage_bt;
alignas(MultiplexSocket) static char storage_bt[sizeof(MultiplexSocket)];
multiplex_outgoing_socket =
new (&storage_bt) MultiplexSocket(physical_socket);
break;
case Medium::BLE:
static std::aligned_storage_t<sizeof(MultiplexSocket),
alignof(MultiplexSocket)>
storage_ble;
alignas(MultiplexSocket) static char storage_ble[sizeof(MultiplexSocket)];
multiplex_outgoing_socket =
new (&storage_ble) MultiplexSocket(physical_socket);
break;
case Medium::WIFI_LAN:
static std::aligned_storage_t<sizeof(MultiplexSocket),
alignof(MultiplexSocket)>
storage_wlan;
alignas(
MultiplexSocket) static char storage_wlan[sizeof(MultiplexSocket)];
multiplex_outgoing_socket =
new (&storage_wlan) MultiplexSocket(physical_socket);
break;
@@ -137,7 +137,7 @@ MurocDefs::INTEL_CALLBACK g_intel_event_cb_handle = {IntelEventHandler,
#endif
WifiIntel& WifiIntel::GetInstance() {
static std::aligned_storage_t<sizeof(WifiIntel), alignof(WifiIntel)> storage;
alignas(WifiIntel) static char storage[sizeof(WifiIntel)];
static WifiIntel* instance = new (&storage) WifiIntel();
return *instance;
}
+1 -3
View File
@@ -52,9 +52,7 @@
namespace nearby {
MediumEnvironment& MediumEnvironment::Instance() {
static std::aligned_storage_t<sizeof(MediumEnvironment),
alignof(MediumEnvironment)>
storage;
alignas(MediumEnvironment) static char storage[sizeof(MediumEnvironment)];
static MediumEnvironment* env = new (&storage) MediumEnvironment();
return *env;
}