From 864fbf531e69666b82792cb88f06e16f7a80835c Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sat, 30 Mar 2013 16:08:14 -0400 Subject: [PATCH] cleanup device support --- devsupApp/src/dbdset.c | 31 +++++++++++++++++++++++++++++++ devsupApp/src/dbfield.c | 2 +- devsupApp/src/pydevsup.h | 4 +++- devsupApp/src/setup.c | 4 +++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/devsupApp/src/dbdset.c b/devsupApp/src/dbdset.c index b1ddb7d..ef4ae1d 100644 --- a/devsupApp/src/dbdset.c +++ b/devsupApp/src/dbdset.c @@ -281,6 +281,37 @@ int isPyRecord(dbCommon *prec) return prec->dset==(dset*)&pydevsupCom || prec->dset==(dset*)&pydevsupCom2; } +/* Called with GIL locked */ +void pyDBD_cleanup(void) +{ + ELLNODE *cur; + while((cur=ellGet(&devices))!=NULL) { + pyDevice *priv=(pyDevice*)cur; + + /* disconnect record by clearing DPVT */ + Py_BEGIN_ALLOW_THREADS { + + dbScanLock(priv->precord); + assert(priv==priv->precord->dpvt); + priv->precord->dpvt = NULL; + dbScanUnlock(priv->precord); + + } Py_END_ALLOW_THREADS + + /* cleanup and dealloc */ + + if(priv->support) + Py_DECREF(priv->support); + if(priv->pyrecord) + Py_DECREF(priv->pyrecord); + if(priv->reason) + Py_DECREF(priv->reason); + priv->support = priv->pyrecord = priv->reason = NULL; + + free(priv); + } +} + #include epicsExportAddress(dset, pydevsupCom); diff --git a/devsupApp/src/dbfield.c b/devsupApp/src/dbfield.c index eb293e8..0e4e267 100644 --- a/devsupApp/src/dbfield.c +++ b/devsupApp/src/dbfield.c @@ -300,7 +300,7 @@ void pyField_setup(PyObject *module) PyModule_AddObject(module, "_Field", (PyObject*)&pyField_type); } -void PyField_cleanup(void) +void pyField_cleanup(void) { size_t i; diff --git a/devsupApp/src/pydevsup.h b/devsupApp/src/pydevsup.h index 9959087..6539d70 100644 --- a/devsupApp/src/pydevsup.h +++ b/devsupApp/src/pydevsup.h @@ -1,9 +1,11 @@ #ifndef PYDEVSUP_H #define PYDEVSUP_H +void pyDBD_cleanup(void); + int pyField_prepare(void); void pyField_setup(PyObject *module); -void PyField_cleanup(void); +void pyField_cleanup(void); int pyRecord_prepare(void); void pyRecord_setup(PyObject *module); diff --git a/devsupApp/src/setup.c b/devsupApp/src/setup.c index 72dcc6c..5e7b261 100644 --- a/devsupApp/src/setup.c +++ b/devsupApp/src/setup.c @@ -75,7 +75,9 @@ static void cleanupPy(void *junk) /* special "fake" hook for shutdown */ pyhook((initHookState)9999); - PyField_cleanup(); + pyDBD_cleanup(); + + pyField_cleanup(); /* release extra reference for hooktable */ Py_DECREF(hooktable);