The threading model now copes better with active validation threads while closing documents.
This commit is contained in:
parent
8be8af2aa0
commit
62efcae940
|
@ -1,4 +1,5 @@
|
||||||
#include "wx/wx.h"
|
#include "wx/wx.h"
|
||||||
|
#include "xmlctrl.h"
|
||||||
#include "validationthread.h"
|
#include "validationthread.h"
|
||||||
#include "wrapxerces.h"
|
#include "wrapxerces.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -31,17 +32,23 @@ void *ValidationThread::Entry()
|
||||||
{
|
{
|
||||||
std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
|
std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
|
||||||
|
|
||||||
|
{
|
||||||
|
//wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
|
||||||
if ( *myReleasePtr || TestDestroy() )
|
if ( *myReleasePtr || TestDestroy() )
|
||||||
{
|
{
|
||||||
Exit();
|
Exit();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool res = validator->validateMemory (
|
bool res = validator->validateMemory (
|
||||||
myBuffer.c_str(),
|
myBuffer.c_str(),
|
||||||
mySystem.c_str(),
|
mySystem.c_str(),
|
||||||
myBuffer.size() );
|
myBuffer.size() );
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
//wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
|
||||||
if ( *myReleasePtr || TestDestroy() )
|
if ( *myReleasePtr || TestDestroy() )
|
||||||
{
|
{
|
||||||
Exit();
|
Exit();
|
||||||
|
@ -60,13 +67,16 @@ void *ValidationThread::Entry()
|
||||||
*myPositionPtr = std::make_pair ( 0, 0 );
|
*myPositionPtr = std::make_pair ( 0, 0 );
|
||||||
*myMessagePtr = "";
|
*myMessagePtr = "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidationThread::OnExit()
|
void ValidationThread::OnExit()
|
||||||
{
|
{
|
||||||
if ( *myReleasePtr )
|
{
|
||||||
return;
|
//wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
|
||||||
|
if ( *myReleasePtr )
|
||||||
*myFinishedPtr = true;
|
return;
|
||||||
|
*myFinishedPtr = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,10 +68,12 @@ XmlCtrl::XmlCtrl (
|
||||||
validationThread = NULL;
|
validationThread = NULL;
|
||||||
validationStarted = false;
|
validationStarted = false;
|
||||||
validationFinished = false;
|
validationFinished = false;
|
||||||
validationRelease = false;
|
|
||||||
grammarFound = false;
|
grammarFound = false;
|
||||||
validationRequired = (buffer) ? true : false; // NULL for plain XML template
|
validationRequired = (buffer) ? true : false; // NULL for plain XML template
|
||||||
|
|
||||||
|
validationReleasePtr = new bool;
|
||||||
|
*validationReleasePtr = false;
|
||||||
|
|
||||||
currentMaxLine = 1;
|
currentMaxLine = 1;
|
||||||
|
|
||||||
applyProperties ( propertiesParameter );
|
applyProperties ( propertiesParameter );
|
||||||
|
@ -122,6 +124,28 @@ XmlCtrl::XmlCtrl (
|
||||||
IndicatorSetForeground ( 0, *wxRED );
|
IndicatorSetForeground ( 0, *wxRED );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
XmlCtrl::~XmlCtrl()
|
||||||
|
{
|
||||||
|
attributeMap.clear();
|
||||||
|
elementMap.clear();
|
||||||
|
entitySet.clear();
|
||||||
|
|
||||||
|
if ( validationStarted && !validationFinished )
|
||||||
|
{
|
||||||
|
*validationReleasePtr = true;
|
||||||
|
|
||||||
|
// don't delete validationReleasePtr because the thread will check the value before exiting
|
||||||
|
// this means that 1 variable of type bool will be leaked in this case
|
||||||
|
// the alternative is waiting for the validation thread to finish, which can take anything up to several minutes
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete validationReleasePtr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// taken from wxStyledNotebook (c) Eran Ifrah <eranif@bezeqint.net>
|
// taken from wxStyledNotebook (c) Eran Ifrah <eranif@bezeqint.net>
|
||||||
static wxColor LightColour ( const wxColour& color, int percent )
|
static wxColor LightColour ( const wxColour& color, int percent )
|
||||||
{
|
{
|
||||||
|
@ -2028,18 +2052,18 @@ bool XmlCtrl::backgroundValidate (
|
||||||
wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
|
wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
|
||||||
if ( validationStarted && !validationFinished )
|
if ( validationStarted && !validationFinished )
|
||||||
{
|
{
|
||||||
validationRelease = true;
|
*validationReleasePtr = true;
|
||||||
return true; // wait for next idle cycle call from main app frame
|
return true; // wait for next idle cycle call from main app frame
|
||||||
}
|
}
|
||||||
validationRequired = false;
|
validationRequired = false;
|
||||||
|
|
||||||
validationRelease = false;
|
*validationReleasePtr = false;
|
||||||
validationThread = new ValidationThread(
|
validationThread = new ValidationThread(
|
||||||
buffer,
|
buffer,
|
||||||
system,
|
system,
|
||||||
&validationFinished,
|
&validationFinished,
|
||||||
&validationSuccess,
|
&validationSuccess,
|
||||||
&validationRelease,
|
validationReleasePtr,
|
||||||
&validationPosition,
|
&validationPosition,
|
||||||
&validationMessage
|
&validationMessage
|
||||||
);
|
);
|
||||||
|
|
|
@ -107,15 +107,7 @@ class XmlCtrl: public wxStyledTextCtrl
|
||||||
const wxPoint &position = wxDefaultPosition,
|
const wxPoint &position = wxDefaultPosition,
|
||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
long style = 0 );
|
long style = 0 );
|
||||||
~XmlCtrl()
|
~XmlCtrl();
|
||||||
{
|
|
||||||
attributeMap.clear();
|
|
||||||
elementMap.clear();
|
|
||||||
entitySet.clear();
|
|
||||||
|
|
||||||
// don't delete thread in case it's gone - just set the release flag
|
|
||||||
validationRelease = true;
|
|
||||||
}
|
|
||||||
int getType();
|
int getType();
|
||||||
int getParentCloseAngleBracket ( int pos, int range = USHRT_MAX * 4 );
|
int getParentCloseAngleBracket ( int pos, int range = USHRT_MAX * 4 );
|
||||||
void applyProperties (
|
void applyProperties (
|
||||||
|
@ -157,8 +149,8 @@ class XmlCtrl: public wxStyledTextCtrl
|
||||||
ValidationThread *validationThread;
|
ValidationThread *validationThread;
|
||||||
bool validationStarted,
|
bool validationStarted,
|
||||||
validationFinished,
|
validationFinished,
|
||||||
validationSuccess,
|
validationSuccess;
|
||||||
validationRelease;
|
bool *validationReleasePtr;
|
||||||
std::pair<int, int> validationPosition;
|
std::pair<int, int> validationPosition;
|
||||||
std::string validationMessage;
|
std::string validationMessage;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue