Commit 202826e1 authored by Florian Prill's avatar Florian Prill
Browse files

[cdi-tiles] changed locking mechanism st. the original vlist of a stream is...

[cdi-tiles] changed locking mechanism st. the original vlist of a stream is locked as soon as it is attached to the stream.
parent d97cfadb
...@@ -1047,8 +1047,17 @@ void streamClose(int streamID) ...@@ -1047,8 +1047,17 @@ void streamClose(int streamID)
taxisDestroy(vlistInqTaxis(vlistID)); taxisDestroy(vlistInqTaxis(vlistID));
} }
vlist_unlock(vlistID);
vlistDestroy(vlistID); vlistDestroy(vlistID);
/* decrease lock counter of the original vlist by 1 */
if ( streamptr->vlistIDorig != CDI_UNDEFID ) {
/* Note: Here we have to check if the original vlist still
* exists. If, for example, the garbage collection routine
* reshListDestruct takes care of the destruction of objects,
* then the original vlist might have been destroyed
* beforehand. */
if (reshExists(streamptr->vlistIDorig, &vlistOps) != 0)
vlist_unlock(streamptr->vlistIDorig);
}
} }
stream_delete_entry(streamptr); stream_delete_entry(streamptr);
...@@ -2158,6 +2167,11 @@ void cdiStreamSetupVlist(stream_t *streamptr, int vlistID, int vlistIDorig) ...@@ -2158,6 +2167,11 @@ void cdiStreamSetupVlist(stream_t *streamptr, int vlistID, int vlistIDorig)
int nvars = vlistNvars(vlistID); int nvars = vlistNvars(vlistID);
streamptr->vlistID = vlistID; streamptr->vlistID = vlistID;
streamptr->vlistIDorig = vlistIDorig; streamptr->vlistIDorig = vlistIDorig;
/* increase lock counter of the original vlist by 1 */
if ( CDI_Debug ) Message("attach vlist=%d to stream, stream vlist=%d", vlistIDorig, vlistID);
vlist_lock(vlistIDorig);
for (int varID = 0; varID < nvars; varID++ ) for (int varID = 0; varID < nvars; varID++ )
{ {
int gridID = vlistInqVarGrid(vlistID, varID); int gridID = vlistInqVarGrid(vlistID, varID);
......
...@@ -169,7 +169,7 @@ void vlist_lock(int vlistID) ...@@ -169,7 +169,7 @@ void vlist_lock(int vlistID)
if ( !vlistptr->locked ) if ( !vlistptr->locked )
{ {
vlistptr->locked = 1; vlistptr->locked += 1;
reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE); reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
} }
} }
...@@ -181,7 +181,7 @@ void vlist_unlock(int vlistID) ...@@ -181,7 +181,7 @@ void vlist_unlock(int vlistID)
if ( vlistptr->locked ) if ( vlistptr->locked )
{ {
vlistptr->locked = 0; vlistptr->locked -= 1;
reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE); reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
} }
} }
...@@ -194,7 +194,7 @@ void vlist_unlock(int vlistID) ...@@ -194,7 +194,7 @@ void vlist_unlock(int vlistID)
@Example @Example
Here is an example using @func{vlistCreate} to create a variable list Here is an example using @func{vlistCreate} to create a variable list
and add a variable with @func{vlistDefVar}. and add a variable with @func{vlistDefVar.
@Source @Source
#include "cdi.h" #include "cdi.h"
...@@ -218,15 +218,15 @@ int vlistCreate(void) ...@@ -218,15 +218,15 @@ int vlistCreate(void)
VLIST_INIT(); VLIST_INIT();
vlist_t *vlistptr = vlist_new_entry(CDI_UNDEFID); vlist_t *vlistptr = vlist_new_entry(CDI_UNDEFID);
if ( CDI_Debug ) Message("create vlistID = %d", vlistptr->self);
return (vlistptr->self); return (vlistptr->self);
} }
static void static void
vlist_delete(vlist_t *vlistptr) vlist_delete(vlist_t *vlistptr)
{ {
if ( CDI_Debug ) Message("call to vlist_delete");
int vlistID = vlistptr->self; int vlistID = vlistptr->self;
if ( CDI_Debug ) Message("call to vlist_delete, vlistID = %d", vlistID);
vlistDelAtts(vlistID, CDI_GLOBAL); vlistDelAtts(vlistID, CDI_GLOBAL);
...@@ -277,7 +277,7 @@ void vlistDestroy(int vlistID) ...@@ -277,7 +277,7 @@ void vlistDestroy(int vlistID)
{ {
vlist_t *vlistptr = vlist_to_pointer(vlistID); vlist_t *vlistptr = vlist_to_pointer(vlistID);
if ( vlistptr->locked ) if ( vlistptr->locked != 0 )
Warning("Destroying of a locked object (vlistID=%d) failed!", vlistID); Warning("Destroying of a locked object (vlistID=%d) failed!", vlistID);
else else
vlist_delete(vlistptr); vlist_delete(vlistptr);
...@@ -338,6 +338,7 @@ void vlistCopy(int vlistID2, int vlistID1) ...@@ -338,6 +338,7 @@ void vlistCopy(int vlistID2, int vlistID1)
{ {
vlist_t *vlistptr1 = vlist_to_pointer(vlistID1); vlist_t *vlistptr1 = vlist_to_pointer(vlistID1);
vlist_t *vlistptr2 = vlist_to_pointer(vlistID2); vlist_t *vlistptr2 = vlist_to_pointer(vlistID2);
if ( CDI_Debug ) Message("call to vlistCopy, vlistIDs %d -> %d", vlistID1, vlistID2);
var_t *vars1 = vlistptr1->vars; var_t *vars1 = vlistptr1->vars;
var_t *vars2 = vlistptr2->vars; var_t *vars2 = vlistptr2->vars;
...@@ -390,11 +391,10 @@ The function @func{vlistDuplicate} duplicates the variable list from vlistID1. ...@@ -390,11 +391,10 @@ The function @func{vlistDuplicate} duplicates the variable list from vlistID1.
*/ */
int vlistDuplicate(int vlistID) int vlistDuplicate(int vlistID)
{ {
if ( CDI_Debug ) Message("call to vlistDuplicate");
int vlistIDnew = vlistCreate(); int vlistIDnew = vlistCreate();
vlistCopy(vlistIDnew, vlistID); vlistCopy(vlistIDnew, vlistID);
/* lock the old vlist */
vlist_lock(vlistID);
vlist_unlock(vlistIDnew);
return (vlistIDnew); return (vlistIDnew);
} }
......
...@@ -1770,7 +1770,7 @@ void vlistDefVarIntKey(int vlistID, int varID, const char *name, int value) ...@@ -1770,7 +1770,7 @@ void vlistDefVarIntKey(int vlistID, int varID, const char *name, int value)
if (vlistptr == NULL) Error("Internal error!"); if (vlistptr == NULL) Error("Internal error!");
int idx; int idx;
if ( vlistptr->locked ) if ( vlistptr->locked != 0 )
Error("User defined vlist object (vlistID=%d) isn't allowed!\n" Error("User defined vlist object (vlistID=%d) isn't allowed!\n"
"Need a CDI internal vlist object from streamInqVlist(streamID).", vlistID); "Need a CDI internal vlist object from streamInqVlist(streamID).", vlistID);
...@@ -1832,7 +1832,7 @@ void vlistDefVarDblKey(int vlistID, int varID, const char *name, double value) ...@@ -1832,7 +1832,7 @@ void vlistDefVarDblKey(int vlistID, int varID, const char *name, double value)
if (vlistptr == NULL) Error("Internal error!"); if (vlistptr == NULL) Error("Internal error!");
int idx; int idx;
if ( vlistptr->locked ) if ( vlistptr->locked != 0 )
Error("User defined vlist object (vlistID=%d) isn't allowed!\n" Error("User defined vlist object (vlistID=%d) isn't allowed!\n"
"Need a CDI internal vlist object from streamInqVlist(streamID).", vlistID); "Need a CDI internal vlist object from streamInqVlist(streamID).", vlistID);
......
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