This method ends a running application. The operation is implemented in the concrete adapter for the target operating system.
void RiCOSEndApplication(int errorCode)
{
RiCTask* currentThread, *maint;
RiCOSTask_endOfProcess = 1;
#ifdef _OMINSTRUMENT
ARCSD_instance();
ARCSD_closeConnection();
#endif
currentThread = RiCTask_cleanupAllTasks();
#ifdef _OMINSTRUMENT
ARCSD_Destroy();
#endif
RiCTimerManager_cleanup(&RiCSystemTimer);
maint = RiCMainTask();
if (maint) {
RiCOSHandle maintHandle = RiCOSTask_getOSHandle(
RiCTask_getOSTask(maint));
char * maintName = taskName(maintHandle);
int killmainthread = 1;
if (maintName && *maintName) {
if (!strcmp(maintName,"tShell"))
taskRestart(maintHandle);
else
taskDeleteForce(maintHandle);
killmainthread = 0;
}
if (killmainthread) {
RiCTask_destroy(maint);
}
}
if (currentThread) {
RiCOSTaskEndCallBack theOSThreadEnderClb;
void * arg1;
/* Get a callback to end the thread. */
(void)RiCTask_getTaskEndClbk(
currentThread, &theOSThreadEnderClb,
&arg1,RiCTRUE);
RiCOSTask_setEndOSTaskInCleanup(
RiCTask_getOSTask(currentThread), FALSE);
/* Do not really end the os thread because you
are executing on this thread and if you do,
there will be a resource leak. */
RiCTask_destroy(currentThread);
/* Delete the whole object through a virtual
destructor. */
if (theOSThreadEnderClb != NULL) {
(*theOSThreadEnderClb)(arg1);
/* Now end the os thread. */
}
}
/* Make sure that the execution thread is being
ended. */
RiCOSTask_endMyTask((void *) taskIdSelf());
}