mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-17 16:44:22 -04:00
libstrat: convert to experimental new (super-accurate) sf allocation semantics
This commit is contained in:
parent
8314d015f3
commit
f06de12bea
149 changed files with 2852 additions and 1746 deletions
|
@ -22,22 +22,20 @@ namespace ams::pwm {
|
|||
constinit os::SdkMutex g_init_mutex;
|
||||
constinit int g_initialize_count = 0;
|
||||
|
||||
std::shared_ptr<sf::IManager> g_pwm_manager;
|
||||
ams::sf::SharedPointer<pwm::sf::IManager> g_pwm_manager;
|
||||
|
||||
using InternalSession = std::shared_ptr<pwm::sf::IChannelSession>;
|
||||
|
||||
InternalSession &GetInterface(const ChannelSession &session) {
|
||||
pwm::sf::IChannelSession *GetInterface(const ChannelSession &session) {
|
||||
AMS_ASSERT(session._session != nullptr);
|
||||
return *static_cast<InternalSession *>(session._session);
|
||||
return static_cast<pwm::sf::IChannelSession *>(session._session);
|
||||
}
|
||||
}
|
||||
|
||||
void InitializeWith(std::shared_ptr<pwm::sf::IManager> &&sp) {
|
||||
void InitializeWith(ams::sf::SharedPointer<pwm::sf::IManager> sp) {
|
||||
std::scoped_lock lk(g_init_mutex);
|
||||
|
||||
AMS_ABORT_UNLESS(g_initialize_count == 0);
|
||||
|
||||
g_pwm_manager = std::move(sp);
|
||||
g_pwm_manager = sp;
|
||||
|
||||
g_initialize_count = 1;
|
||||
}
|
||||
|
@ -48,38 +46,31 @@ namespace ams::pwm {
|
|||
AMS_ASSERT(g_initialize_count > 0);
|
||||
|
||||
if ((--g_initialize_count) == 0) {
|
||||
g_pwm_manager.reset();
|
||||
g_pwm_manager.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
Result OpenSession(ChannelSession *out, DeviceCode device_code) {
|
||||
/* Allocate the session. */
|
||||
InternalSession *internal_session = new (std::nothrow) InternalSession;
|
||||
AMS_ABORT_UNLESS(internal_session != nullptr);
|
||||
auto session_guard = SCOPE_GUARD { delete internal_session; };
|
||||
|
||||
/* Get the session. */
|
||||
ams::sf::SharedPointer<pwm::sf::IChannelSession> session;
|
||||
{
|
||||
ams::sf::cmif::ServiceObjectHolder object_holder;
|
||||
if (hos::GetVersion() >= hos::Version_6_0_0) {
|
||||
R_TRY(g_pwm_manager->OpenSession2(std::addressof(object_holder), device_code));
|
||||
R_TRY(g_pwm_manager->OpenSession2(std::addressof(session), device_code));
|
||||
} else {
|
||||
R_TRY(g_pwm_manager->OpenSession(std::addressof(object_holder), ConvertToChannelName(device_code)));
|
||||
R_TRY(g_pwm_manager->OpenSession(std::addressof(session), ConvertToChannelName(device_code)));
|
||||
}
|
||||
*internal_session = object_holder.GetServiceObject<sf::IChannelSession>();
|
||||
}
|
||||
|
||||
/* Set output. */
|
||||
out->_session = internal_session;
|
||||
out->_session = session.Detach();
|
||||
|
||||
/* We succeeded. */
|
||||
session_guard.Cancel();
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void CloseSession(ChannelSession &session) {
|
||||
/* Close the session. */
|
||||
delete std::addressof(GetInterface(session));
|
||||
ams::sf::ReleaseSharedObject(GetInterface(session));
|
||||
session._session = nullptr;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue