Skip to content
Snippets Groups Projects
Commit 5cd0b2fa authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Change model search to use atomic operation.

parent 6abedbbd
No related branches found
No related tags found
No related merge requests found
......@@ -146,59 +146,65 @@ int modelSize ( void )
return reshCountType ( &modelOps );
}
int modelInq(int instID, int modelgribID, char *name)
struct modelLoc
{
int modelID = UNDEFID;
size_t len;
int found;
int modelCount;
model_t *modelptr;
int i, * modelResHs;
modelInit ();
modelCount = modelSize();
modelResHs = xmalloc ( modelCount * sizeof ( int ));
reshGetResHListOfType ( modelCount, modelResHs, &modelOps );
char *name;
int instID, modelgribID, resID;
};
for( i = 0; i < modelCount; i++ )
static enum cdiApplyRet
findModelByID(int resID, void *res, void *data)
{
model_t *modelptr = res;
struct modelLoc *ret = data;
int instID = ret->instID, modelgribID = ret->modelgribID;
if (modelptr->used
&& modelptr->instID == instID
&& modelptr->modelgribID == modelgribID)
{
modelID = modelResHs[i];
modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps );
ret->resID = resID;
return CDI_APPLY_STOP;
}
else
return CDI_APPLY_GO_ON;
}
if ( modelptr->used )
static enum cdiApplyRet
findModelByName(int resID, void *res, void *data)
{
model_t *modelptr = res;
struct modelLoc *ret = data;
int instID = ret->instID, modelgribID = ret->modelgribID;
const char *name = ret->name;
if (modelptr->used
&& (instID == -1 || modelptr->instID == instID)
&& (modelgribID == 0 || modelptr->modelgribID == modelgribID)
&& modelptr->name)
{
const char *p = name, *q = modelptr->name;
while (*p != '\0' && *p == *q)
++p, ++q;
if (*p == '\0' || *q == '\0')
{
if ( name && *name )
{
found = 1;
if ( instID != -1 && modelptr->instID != instID ) found = 0;
if ( modelgribID != 0 && modelptr->modelgribID != modelgribID ) found = 0;
if ( found )
{
if ( modelptr->name )
{
len = strlen(modelptr->name);
if ( strncmp(modelptr->name, name, len) == 0 ) break;
len = strlen(name);
if ( strncmp(modelptr->name, name, len) == 0 ) break;
}
}
}
else
{
if ( modelptr->instID == instID &&
modelptr->modelgribID == modelgribID ) break;
}
ret->resID = resID;
return CDI_APPLY_STOP;
}
}
return CDI_APPLY_GO_ON;
}
if ( i == modelCount ) modelID = UNDEFID;
if ( modelResHs ) free ( modelResHs );
int modelInq(int instID, int modelgribID, char *name)
{
modelInit ();
return (modelID);
struct modelLoc searchState = { .name = name, .instID = instID,
.modelgribID = modelgribID,
.resID = UNDEFID };
if (name && *name)
cdiResHFilterApply(&modelOps, findModelByName, &searchState);
else
cdiResHFilterApply(&modelOps, findModelByID, &searchState);
return searchState.resID;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment