Commit 21a7ca90 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Prepopulate resource lists with default institute entries.

* This also changes the destruction of resource lists, i.e. lists that
  were not explicitly created must not be deleted.
parent 32204535
......@@ -47,8 +47,6 @@ static const resOps instituteOps = {
instituteTxCode
};
static int * instituteInitializedNsp;
static
void instituteDefaultValue ( institute_t * instituteptr )
{
......@@ -74,7 +72,7 @@ institute_t * instituteNewEntry ( void )
return instituteptr;
}
static
void instituteDefaultEntries ( void )
{
cdiResH resH[64];
......@@ -99,34 +97,6 @@ void instituteDefaultEntries ( void )
reshSetStatus(resH[i], &instituteOps, RESH_PRE_ASSIGNED);
}
static
void instituteFinalize ( void )
{
free ( instituteInitializedNsp );
}
static
void instituteInit (void)
{
static int instituteInitialized = 0;
int nsp, nspc;
nspc = namespaceGetNumber ();
if ( !instituteInitialized )
{
instituteInitialized = 1;
instituteInitializedNsp = (int*) xcalloc ( 1, nspc * sizeof ( int ));
atexit ( instituteFinalize );
}
nsp = namespaceGetActive ();
if ( instituteInitializedNsp[nsp] ) return;
instituteInitializedNsp[nsp] = 1;
instituteDefaultEntries();
}
int instituteCount ( void )
{
......@@ -209,9 +179,7 @@ findInstitute(int id, void *res, void *data)
int institutInq(int center, int subcenter, const char *name, const char *longname)
{
instituteInit ();
institute_t * ip_ref = (institute_t*) xmalloc(sizeof (*ip_ref));
institute_t * ip_ref = (institute_t *)xmalloc(sizeof (*ip_ref));
ip_ref->self = UNDEFID;
ip_ref->used = 0;
ip_ref->center = center;
......@@ -232,8 +200,6 @@ int institutDef(int center, int subcenter, const char *name, const char *longnam
{
institute_t * instituteptr;
instituteInit ();
instituteptr = instituteNewEntry();
instituteptr->center = center;
......@@ -249,8 +215,6 @@ int institutInqCenter(int instID)
{
institute_t * instituteptr = NULL;
instituteInit ();
if ( instID != UNDEFID )
instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps );
......@@ -262,8 +226,6 @@ int institutInqSubcenter(int instID)
{
institute_t * instituteptr = NULL;
instituteInit ();
if ( instID != UNDEFID )
instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps );
......@@ -275,8 +237,6 @@ char *institutInqNamePtr(int instID)
{
institute_t * instituteptr = NULL;
instituteInit ();
if ( instID != UNDEFID )
instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps );
......@@ -288,8 +248,6 @@ char *institutInqLongnamePtr(int instID)
{
institute_t * instituteptr = NULL;
instituteInit ();
if ( instID != UNDEFID )
instituteptr = ( institute_t * ) reshGetVal ( instID, &instituteOps );
......@@ -308,8 +266,6 @@ int institutInqNumber(void)
{
int instNum = 0;
instituteInit ();
cdiResHFilterApply(&instituteOps, activeInstitutes, &instNum);
return instNum;
}
......
......@@ -5,6 +5,8 @@ int
instituteUnpack(void *buf, int size, int *position, int,
void *context);
void instituteDefaultEntries(void);
#endif
/*
......
......@@ -812,7 +812,6 @@ pioInit(MPI_Comm commGlob, int nProcsIO, int IOMode,
namespaceSwitchSet(NSSWITCH_FILE_OPEN, NSSW_FUNC(pioFileOpen));
namespaceSwitchSet(NSSWITCH_FILE_CLOSE, NSSW_FUNC(pioFileClose));
cdiPioServer(postCommSetupActions);
namespaceDelete(0);
namespaceNew();
commDestroy ();
if (xtInitByCDI)
......
......@@ -17,12 +17,26 @@
#include "error.h"
#include "file.h"
#include "resource_unpack.h"
#include "institution.h"
enum { MIN_LIST_SIZE = 128 };
static void listInitialize(void);
// ATTENTION: not thread safe yet, namespaces are set in model!
typedef struct listElem {
int next;
const resOps *ops;
void *val;//ptr
int status;
} listElem_t;
static struct
{
int size, freeHead, hasDefaultRes;
listElem_t *resources;
} *resHList;
static int resHListSize = 0;
#if defined (HAVE_LIBPTHREAD)
# include <pthread.h>
......@@ -32,7 +46,15 @@ static pthread_mutex_t listMutex;
# define LIST_LOCK() pthread_mutex_lock(&listMutex)
# define LIST_UNLOCK() pthread_mutex_unlock(&listMutex)
# define LIST_INIT() pthread_once(&listInitThread, listInitialize)
# define LIST_INIT(init0) do { \
pthread_once(&listInitThread, listInitialize); \
pthread_mutex_lock(&listMutex); \
if ((init0) && (!resHList || !resHList[0].resources)) \
reshListCreate(0); \
pthread_mutex_unlock(&listMutex); \
} while (0)
#else
......@@ -40,32 +62,18 @@ static int listInit = 0;
# define LIST_LOCK()
# define LIST_UNLOCK()
# define LIST_INIT() do { \
# define LIST_INIT(init0) do { \
if ( !listInit ) \
{ \
listInitialize(); \
if ((init0) && (!resHList || !resHList[0].resources)) \
reshListCreate(0); \
listInit = 1; \
} \
} while(0)
#endif
typedef struct listElem {
int next;
const resOps *ops;
void *val;//ptr
int status;
} listElem_t;
static struct
{
int size, freeHead;
listElem_t *resources;
} *resHList;
static int resHListSize = 0;
/**************************************************************/
static void
......@@ -87,6 +95,10 @@ listInitResources(int nsp)
p[resHList[nsp].size-1].next = -1;
resHList[nsp].freeHead = 0;
int oldNsp = namespaceGetActive();
namespaceSetActive(nsp);
instituteDefaultEntries();
namespaceSetActive(oldNsp);
}
static inline void
......@@ -100,6 +112,7 @@ reshListClearEntry(int i)
void
reshListCreate(int namespaceID)
{
LIST_INIT(namespaceID != 0);
LIST_LOCK();
if (resHListSize <= namespaceID)
{
......@@ -118,7 +131,6 @@ reshListCreate(int namespaceID)
void
reshListDestruct(int namespaceID)
{
LIST_INIT();
LIST_LOCK();
xassert(resHList && namespaceID >= 0 && namespaceID < resHListSize);
int callerNamespaceID = namespaceGetActive();
......@@ -143,9 +155,9 @@ reshListDestruct(int namespaceID)
static void listDestroy ( void )
{
LIST_LOCK();
for (int i = 0; i < resHListSize; ++i)
if (resHList[i].resources)
namespaceDelete(i);
for (int i = resHListSize; i > 0; --i)
if (resHList[i-1].resources)
namespaceDelete(i-1);
free(resHList);
resHList = NULL;
cdiReset();
......@@ -165,8 +177,6 @@ void listInitialize ( void )
pthread_mutex_init ( &listMutex, &ma);
pthread_mutexattr_destroy(&ma);
#endif
// create default namespace
reshListCreate(0);
/* file is special and has its own table, which needs to be
* created, before we register the listDestroy exit handler */
{
......@@ -176,7 +186,6 @@ void listInitialize ( void )
fileClose_serial(null_id);
}
atexit ( listDestroy );
}
/**************************************************************/
......@@ -213,7 +222,7 @@ int reshPut ( void *p, const resOps *ops )
xassert ( p && ops );
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
......@@ -241,7 +250,7 @@ void reshRemove ( cdiResH resH, const resOps * ops )
int nsp;
namespaceTuple_t nspT;
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
......@@ -274,7 +283,7 @@ reshGetElem(const char *caller, cdiResH resH, const resOps *ops)
namespaceTuple_t nspT;
xassert ( ops );
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
......@@ -316,7 +325,7 @@ void reshGetResHListOfType ( int c, int * resHs, const resOps * ops )
xassert ( resHs && ops );
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
......@@ -339,7 +348,7 @@ cdiResHApply(enum cdiApplyRet (*func)(int id, void *res, const resOps *p,
{
xassert(func);
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
......@@ -361,7 +370,7 @@ cdiResHFilterApply(const resOps *p,
{
xassert(p && func);
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
......@@ -387,7 +396,7 @@ int reshCountType ( const resOps * ops )
xassert ( ops );
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
......@@ -518,7 +527,7 @@ void reshSetStatus ( cdiResH resH, const resOps * ops, int status )
xassert ( ops );
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
......@@ -550,7 +559,7 @@ int reshGetStatus ( cdiResH resH, const resOps * ops )
xassert ( ops );
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
......@@ -590,7 +599,7 @@ void reshUnlock ()
int reshListCompare ( int nsp0, int nsp1 )
{
LIST_INIT();
LIST_INIT(1);
LIST_LOCK();
xassert(resHListSize > nsp0 && resHListSize > nsp1 &&
......@@ -644,7 +653,7 @@ void reshListPrint(FILE *fp)
int i, j, temp;
listElem_t * curr;
LIST_INIT();
LIST_INIT(1);
temp = namespaceGetActive ();
......
......@@ -4,8 +4,9 @@ LOG="${LOG-pio_write.log}"
mpi_task_num="${mpi_task_num-4}"
suffix="${suffix-grb}"
exec 5>&1 6>&2 >"$LOG" 2>&1
../libtool --mode=execute @MPI_LAUNCH@ -n ${mpi_task_num} \
${tool_wrap} ./pio_write ${pio_write_args}
../libtool --mode=execute \
@MPI_LAUNCH@ \
-n ${mpi_task_num} ${tool_wrap} ./pio_write ${pio_write_args}
exec 2>&6 1>&5 5>&- 6>&-
../libtool --mode=execute \
${tool_wrap} ./cksum_read example_0.${suffix} example_0.cksum
......
Markdown is supported
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