Commit b3c09c15 authored by Deike Kleberg's avatar Deike Kleberg
Browse files

Adapt resource handle feature to grid_t.

parent b6484766
......@@ -91,7 +91,7 @@ void modelRun ()
gridDefYsize(gridID3, nlat-2);
gridDefXvals(gridID3, lons);
gridDefYvals(gridID3, lats);
gridTestNamespace ();
reshArrayPrint ();
namespaceSetActive ( 0 );
......
......@@ -210,10 +210,11 @@ int namespaceGetNumber ( void );
void namespaceSetActive ( int );
int namespaceGetActive ( void );
void gridTestNamespace ( void );
void zaxisTestNamespace ( void );
void taxisTestNamespace ( void );
void reshArrayPrint ( void );
/* CDI control routines */
char *cdiStringError(int cdiErrno);
......
This diff is collapsed.
......@@ -41,7 +41,7 @@ void namespaceShowbits ( int n, char *name )
int namespaceIdxEncode ( namespaceTuple_t tin )
{
assert(tin.nsp < NUM_NAMESPACES && tin.idx < NUM_IDX);
assert ( tin.nsp < NUM_NAMESPACES && tin.idx < NUM_IDX);
return ( tin.nsp << idxbits ) + tin.idx;
}
......
......@@ -74,6 +74,9 @@ void arrayNew ( void )
}
/**************************************************************/
static
void arrayInitPointer ( void )
{
......@@ -100,6 +103,10 @@ void arrayInitPointer ( void )
}
}
/**************************************************************/
static
void arrayDelete ( void )
{
......@@ -117,6 +124,10 @@ void arrayDelete ( void )
if ( freeListHead ) free ( freeListHead );
}
/**************************************************************/
static
void arrayInitialize ( void )
{
......@@ -138,6 +149,9 @@ void arrayInitialize ( void )
}
/**************************************************************/
void *reshGetVal ( cdiResH idx )
{
void *p = NULL;
......@@ -170,6 +184,9 @@ void *reshGetVal ( cdiResH idx )
}
/**************************************************************/
resOps * reshGetOps ( cdiResH idx )
{
resOps *ops = NULL;
......@@ -201,8 +218,11 @@ resOps * reshGetOps ( cdiResH idx )
return ops;
}
void
arraySizeExtend()
/**************************************************************/
void arraySizeExtend()
{
int newArraySize;
int i, nsp, code;
......@@ -233,7 +253,9 @@ arraySizeExtend()
}
/* Create an index from a pointer */
/**************************************************************/
int reshPut ( void *p, resOps *ops )
{
int idx = -1;
......@@ -246,6 +268,10 @@ int reshPut ( void *p, resOps *ops )
assert ( p );
ARRAY_INIT();
nsp = namespaceGetActive ();
ARRAY_LOCK();
if ( !freeListHead[nsp] ) arraySizeExtend();
......@@ -263,6 +289,8 @@ int reshPut ( void *p, resOps *ops )
}
/**************************************************************/
void
reshRemove ( cdiResH idx)
......@@ -279,3 +307,65 @@ reshRemove ( cdiResH idx)
ARRAY_UNLOCK();
}
/**************************************************************/
int reshCountType ( resOps * ops )
{
int countType = 0;
long i;
int nsp;
nsp = namespaceGetActive ();
ARRAY_INIT();
ARRAY_LOCK();
for ( i = 0; i < arraySizeAllocated[nsp]; i++ )
if ( arrayResources[nsp][i].ptr )
if ( arrayResources[nsp][i].ops == ops )
countType++;
ARRAY_UNLOCK();
return countType;
}
/**************************************************************/
void reshArrayPrint ()
{
int i, j, temp;
node * curr;
if ( arrayInit )
{
temp = namespaceGetActive ();
for ( i = 0; i < namespaceGetNumber (); i++ )
{
namespaceSetActive ( i );
fprintf ( stdout, "\n" );
fprintf ( stdout, "##################################\n" );
fprintf ( stdout, "#\n" );
fprintf ( stdout, "# namespace=%d\n", i );
fprintf ( stdout, "#\n" );
fprintf ( stdout, "##################################\n" );
for ( j = 0; j < arraySizeAllocated[i]; j++)
{
curr = &arrayResources[i][j];
if ( curr->ptr )
curr->ops->valPrint ( curr->ptr );
}
}
namespaceSetActive ( temp );
}
}
......@@ -15,10 +15,12 @@ typedef int cdiResH;
/* return 0 on equality, not 0 otherwise */
typedef int ( * valCompareFunc )( void *, void * );
typedef void ( * valDestroyFunc ) ( void * );
typedef void ( * valPrintFunc ) ( void * );
typedef struct {
valCompareFunc valCompare;
valDestroyFunc valDestroy;
valPrintFunc valPrint;
}resOps;
int
......@@ -33,4 +35,6 @@ reshGetOps ( cdiResH );
void
reshRemove ( cdiResH );
int reshCountType ( resOps * );
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment