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