Service function reset
Just like the other library functions, the reset service function takes a predefined format. Here we create the module context at the first call to this function and delete it at the subsequent call. When deleting the context the reset function needs to free all space that has been allocated by the module during the execution of a model. Therefore, every time a task is created it is added to the list of tasks in the module context and it is removed from the list if it is deleted explicitly by a call to the type instance deletion function. As mentioned earlier, even if a module provides deletion functions for all the types that it defines (as in this example) it is required to implement the reset service to free any remaining allocated space because Mosel does not guarantee that the type instance deletion function gets called for every object that has been created by the module.
static void *task_reset(XPRMcontext ctx, void *libctx, int version)
{
s_taskctx *taskctx;
s_task *task;
if(libctx==NULL) /* At start: create the context */
{
taskctx=malloc(sizeof(s_taskctx));
memset(taskctx, 0, sizeof(s_taskctx));
return taskctx;
}
else /* At the end: delete everything */
{
taskctx=libctx;
while(taskctx->firsttask!=NULL)
{
task=taskctx->firsttask;
taskctx->firsttask=task->next;
free(task);
}
free(taskctx);
return NULL;
}
}© 2001-2021 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.
