ams: prefer construct_at/destroy_at over placement new/explicit destructor

This commit is contained in:
Michael Scire 2021-03-21 20:30:40 -07:00
parent aff0da9427
commit d84dcb653d
49 changed files with 217 additions and 171 deletions

View file

@ -40,7 +40,7 @@ namespace ams::pwm::driver::board::nintendo::nx::impl {
AMS_ABORT_UNLESS(driver_storage != nullptr);
/* Create our driver. */
auto *driver = new (static_cast<PwmDriverImpl *>(driver_storage)) PwmDriverImpl(PwmRegistersPhysicalAddress, PwmRegistersSize, SupportedChannels, util::size(SupportedChannels));
auto *driver = std::construct_at(static_cast<PwmDriverImpl *>(driver_storage), PwmRegistersPhysicalAddress, PwmRegistersSize, SupportedChannels, util::size(SupportedChannels));
/* Register our driver. */
pwm::driver::RegisterDriver(driver);
@ -51,7 +51,7 @@ namespace ams::pwm::driver::board::nintendo::nx::impl {
AMS_ABORT_UNLESS(device_storage != nullptr);
/* Create our driver. */
auto *device = new (static_cast<PwmDeviceImpl *>(device_storage)) PwmDeviceImpl(entry.channel_id);
auto *device = std::construct_at(static_cast<PwmDeviceImpl *>(device_storage), entry.channel_id);
/* Register the device with our driver. */
driver->RegisterDevice(device);

View file

@ -24,8 +24,8 @@ namespace ams::pwm::driver {
Result OpenSessionImpl(ChannelSession *out, IPwmDevice *device) {
/* Construct the session. */
auto *session = new (std::addressof(impl::GetChannelSessionImpl(*out))) impl::ChannelSessionImpl;
auto session_guard = SCOPE_GUARD { session->~ChannelSessionImpl(); };
auto *session = std::construct_at(std::addressof(impl::GetChannelSessionImpl(*out)));
auto session_guard = SCOPE_GUARD { std::destroy_at(session); };
/* Open the session. */
R_TRY(session->Open(device, ddsf::AccessMode_ReadWrite));
@ -52,7 +52,7 @@ namespace ams::pwm::driver {
}
void CloseSession(ChannelSession &session) {
impl::GetOpenChannelSessionImpl(session).~ChannelSessionImpl();
std::destroy_at(std::addressof(impl::GetOpenChannelSessionImpl(session)));
}
void SetPeriod(ChannelSession &session, TimeSpan period) {