mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-03 18:12:14 +02:00
Use reference counting across services
This commit is contained in:
parent
a4e427823e
commit
4b359be16b
@ -73,6 +73,7 @@ enum {
|
||||
LibnxError_InitFail_Time,
|
||||
LibnxError_TooManyDevOpTabs,
|
||||
LibnxError_AppletFailedToInitialize,
|
||||
LibnxError_ApmFailedToInitialize,
|
||||
};
|
||||
|
||||
/// libnx nvidia error codes
|
||||
|
@ -79,6 +79,9 @@ Result appletInitialize(void)
|
||||
if (__nx_applet_type == AppletType_None)
|
||||
return 0;
|
||||
|
||||
if (R_FAILED(apmInitialize()))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_ApmFailedToInitialize);
|
||||
|
||||
Result rc = 0;
|
||||
|
||||
g_appletResourceUserId = 0;
|
||||
@ -213,9 +216,6 @@ Result appletInitialize(void)
|
||||
if (R_SUCCEEDED(rc))
|
||||
rc = _appletSetPerformanceModeChangedNotification(1);
|
||||
|
||||
if (R_SUCCEEDED(rc))
|
||||
rc = apmInitialize();
|
||||
|
||||
// Official apps aren't known to use apmSetPerformanceConfiguration with mode=1.
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
// This is broken with the regular "apm" service.
|
||||
@ -240,8 +240,6 @@ void appletExit(void)
|
||||
{
|
||||
if (atomicDecrement64(&g_refCnt) == 0)
|
||||
{
|
||||
apmExit();
|
||||
|
||||
//TODO: Enable this somehow later with more condition(s)?
|
||||
/*if (__nx_applet_type == AppletType_LibraryApplet)
|
||||
_appletExitProcessAndReturn();*/
|
||||
@ -270,6 +268,8 @@ void appletExit(void)
|
||||
serviceClose(&g_appletProxySession);
|
||||
serviceClose(&g_appletSrv);
|
||||
g_appletResourceUserId = 0;
|
||||
|
||||
apmExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,9 @@ Result hidInitialize(void)
|
||||
if (serviceIsActive(&g_hidSrv))
|
||||
return 0;
|
||||
|
||||
if (R_FAILED(appletInitialize()))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize);
|
||||
|
||||
Result rc;
|
||||
Handle sharedmem_handle;
|
||||
u64 AppletResourceUserId;
|
||||
@ -86,6 +89,8 @@ void hidExit(void)
|
||||
serviceClose(&g_hidIAppletResource);
|
||||
serviceClose(&g_hidSrv);
|
||||
shmemClose(&g_hidSharedmem);
|
||||
|
||||
appletExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,9 @@ Result irsInitialize(void)
|
||||
if (serviceIsActive(&g_irsSrv))
|
||||
return 0;
|
||||
|
||||
if (R_FAILED(appletInitialize()))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize);
|
||||
|
||||
Result rc;
|
||||
Handle sharedmem_handle;
|
||||
u64 AppletResourceUserId=0;
|
||||
@ -80,6 +83,7 @@ void irsExit(void)
|
||||
|
||||
serviceClose(&g_irsSrv);
|
||||
shmemClose(&g_irsSharedmem);
|
||||
appletExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,9 @@ Result viInitialize(ViServiceType servicetype)
|
||||
if (serviceIsActive(&g_viSrv))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);
|
||||
|
||||
if (R_FAILED(appletInitialize()))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_AppletFailedToInitialize);
|
||||
|
||||
Result rc = 0;
|
||||
|
||||
if (servicetype == ViServiceType_Default || servicetype == ViServiceType_Manager) {
|
||||
@ -36,8 +39,7 @@ Result viInitialize(ViServiceType servicetype)
|
||||
g_viServiceType = 1;
|
||||
}
|
||||
|
||||
if ((servicetype == ViServiceType_Default && R_FAILED(rc)) || servicetype == ViServiceType_Application)
|
||||
{
|
||||
if ((servicetype == ViServiceType_Default && R_FAILED(rc)) || servicetype == ViServiceType_Application) {
|
||||
rc = smGetService(&g_viSrv, "vi:u");
|
||||
g_viServiceType = 0;
|
||||
}
|
||||
@ -85,6 +87,7 @@ void viExit(void)
|
||||
serviceClose(&g_viIHOSBinderDriverIndirect);
|
||||
|
||||
serviceClose(&g_viSrv);
|
||||
appletExit();
|
||||
}
|
||||
|
||||
Service* viGetSessionService(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user