1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0029195: OCAF - ensure thread safety for different documents.

OCAF persistence architecture modification to satisfy multi-threading criteria.
This commit is contained in:
mpv
2020-08-26 10:15:22 +03:00
committed by abv
parent c3e0e1de43
commit d9d03f10c3
39 changed files with 570 additions and 606 deletions

View File

@@ -28,6 +28,14 @@
IMPLEMENT_STANDARD_RTTIEXT(CDM_Application,Standard_Transient)
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
CDM_Application::CDM_Application()
{
myMessenger = new Message_Messenger;
}
//=======================================================================
//function : SetDocumentVersion
//purpose :
@@ -58,10 +66,7 @@ void CDM_Application::SetReferenceCounter
Handle(Message_Messenger) CDM_Application::MessageDriver()
{
static Handle(Message_Messenger) theMessenger;
if(theMessenger.IsNull())
theMessenger = Message::DefaultMessenger();
return theMessenger;
return myMessenger;
}
//=======================================================================
@@ -79,10 +84,10 @@ void CDM_Application::Write(const Standard_ExtString aString)
//purpose :
//=======================================================================
void CDM_Application::BeginOfUpdate (const Handle(CDM_Document)& aDocument)
void CDM_Application::BeginOfUpdate (const Handle(CDM_Document)& /*aDocument*/)
{
TCollection_ExtendedString updating("Updating:");
updating+=aDocument->Presentation();
TCollection_ExtendedString updating("Updating: ");
updating += "Document";
Write(updating.ToExtString());
}
@@ -92,17 +97,17 @@ void CDM_Application::BeginOfUpdate (const Handle(CDM_Document)& aDocument)
//=======================================================================
void CDM_Application::EndOfUpdate
(const Handle(CDM_Document)& aDocument,
(const Handle(CDM_Document)& /*aDocument*/,
const Standard_Boolean theStatus,
const TCollection_ExtendedString& /*ErrorString*/)
{
TCollection_ExtendedString message;
if (theStatus)
message="Updated:";
message="Updated: ";
else
message="Error during updating:";
message="Error during updating: ";
message+=aDocument->Presentation();
message+="Document";
Write(message.ToExtString());
}
@@ -128,6 +133,15 @@ TCollection_AsciiString CDM_Application::Version() const
return TCollection_AsciiString();
}
//=======================================================================
//function : MetaDataLookUpTable
//purpose : returns the MetaData LookUpTable
//=======================================================================
CDM_MetaDataLookUpTable* CDM_Application::MetaDataLookUpTable()
{
return &myMetaDataLookUpTable;
}
//=======================================================================
//function : DumpJson
//purpose :

View File

@@ -26,6 +26,7 @@
#include <Standard_ExtString.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <CDM_MetaDataLookUpTable.hxx>
#include <Message_ProgressIndicator.hxx>
class CDM_Reference;
@@ -68,6 +69,9 @@ public:
//! Returns the application version.
Standard_EXPORT virtual TCollection_AsciiString Version() const;
//! Returns MetaData LookUpTable
Standard_EXPORT virtual CDM_MetaDataLookUpTable* MetaDataLookUpTable();
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
@@ -79,13 +83,12 @@ friend class CDM_MetaData;
protected:
Standard_EXPORT CDM_Application();
Standard_EXPORT void SetDocumentVersion (const Handle(CDM_Document)& aDocument, const Handle(CDM_MetaData)& aMetaData) const;
Standard_EXPORT void SetReferenceCounter (const Handle(CDM_Document)& aDocument, const Standard_Integer aReferenceCounter);
private:
@@ -97,7 +100,8 @@ private:
//! returns -1 if the metadata has no modification counter.
Standard_EXPORT virtual Standard_Integer DocumentVersion (const Handle(CDM_MetaData)& aMetaData) = 0;
Handle(Message_Messenger) myMessenger;
CDM_MetaDataLookUpTable myMetaDataLookUpTable;
};

View File

@@ -14,16 +14,17 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef CDM_PresentationDirectory_HeaderFile
#define CDM_PresentationDirectory_HeaderFile
#ifndef CDM_ApplicationDirectory_HeaderFile
#define CDM_ApplicationDirectory_HeaderFile
#include <TCollection_ExtendedString.hxx>
#include <CDM_Document.hxx>
#include <TCollection_ExtendedString.hxx>
#include <CDM_Application.hxx>
#include <TColStd_MapIntegerHasher.hxx>
#include <NCollection_DataMap.hxx>
#include <Standard_ThreadId.hxx>
#include <NCollection_DefaultHasher.hxx>
typedef NCollection_DataMap<TCollection_ExtendedString,Handle(CDM_Document),TCollection_ExtendedString> CDM_PresentationDirectory;
typedef NCollection_DataMap<TCollection_ExtendedString,Handle(CDM_Document),TCollection_ExtendedString>::Iterator CDM_DataMapIteratorOfPresentationDirectory;
typedef NCollection_DefaultHasher<Standard_ThreadId> CDM_MapThreadIDHasher;
typedef NCollection_DataMap<Standard_ThreadId,Handle(CDM_Application),CDM_MapThreadIDHasher> CDM_ApplicationDirectory;
typedef NCollection_DataMap<Standard_ThreadId,Handle(CDM_Application),CDM_MapThreadIDHasher>::Iterator CDM_DataMapIteratorOfApplicationDirectory;
#endif

View File

@@ -1,20 +0,0 @@
// Copyright (c) 2015 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef CDM_DataMapIteratorOfPresentationDirectory_HeaderFile
#define CDM_DataMapIteratorOfPresentationDirectory_HeaderFile
#include <CDM_PresentationDirectory.hxx>
#endif

View File

@@ -23,7 +23,6 @@
#include <CDM_ListOfDocument.hxx>
#include <CDM_MetaData.hxx>
#include <CDM_NamesDirectory.hxx>
#include <CDM_PresentationDirectory.hxx>
#include <CDM_Reference.hxx>
#include <CDM_ReferenceIterator.hxx>
#include <Resource_Manager.hxx>
@@ -40,11 +39,6 @@
IMPLEMENT_STANDARD_RTTIEXT(CDM_Document,Standard_Transient)
static CDM_PresentationDirectory& getPresentations() {
static CDM_PresentationDirectory thePresentations;
return thePresentations;
}
//=======================================================================
//function : CDM_Document
//purpose :
@@ -52,7 +46,6 @@ static CDM_PresentationDirectory& getPresentations() {
CDM_Document::CDM_Document():
myResourcesAreLoaded (Standard_False),
myValidPresentation (Standard_False),
myVersion (1),
myActualReferenceIdentifier (0),
myStorageVersion (0),
@@ -229,11 +222,6 @@ Handle(CDM_Reference) CDM_Document::Reference
return theReference;
}
static CDM_ListOfDocument& getListOfDocumentToUpdate() {
static CDM_ListOfDocument theListOfDocumentToUpdate;
return theListOfDocumentToUpdate;
}
//=======================================================================
//function : IsInSession
//purpose :
@@ -286,25 +274,23 @@ TCollection_ExtendedString CDM_Document::Name
//function : UpdateFromDocuments
//purpose :
//=======================================================================
void CDM_Document::UpdateFromDocuments(const Standard_Address aModifContext) const
{
Standard_Boolean StartUpdateCycle=getListOfDocumentToUpdate().IsEmpty();
CDM_ListOfDocument aListOfDocumentsToUpdate;
Standard_Boolean StartUpdateCycle = aListOfDocumentsToUpdate.IsEmpty();
CDM_ListIteratorOfListOfReferences it(myFromReferences);
for(; it.More() ; it.Next()) {
Handle(CDM_Document) theFromDocument=it.Value()->FromDocument();
CDM_ListIteratorOfListOfDocument itUpdate;
for(; itUpdate.More(); itUpdate.Next()) {
if(itUpdate.Value() == theFromDocument) break;
if(itUpdate.Value()->ShallowReferences(theFromDocument)) {
getListOfDocumentToUpdate().InsertBefore(theFromDocument,itUpdate);
aListOfDocumentsToUpdate.InsertBefore(theFromDocument,itUpdate);
break;
}
}
if(!itUpdate.More()) getListOfDocumentToUpdate().Append(theFromDocument);
if(!itUpdate.More()) aListOfDocumentsToUpdate.Append(theFromDocument);
theFromDocument->Update(this,it.Value()->ReferenceIdentifier(),aModifContext);
}
@@ -314,15 +300,15 @@ void CDM_Document::UpdateFromDocuments(const Standard_Address aModifContext) con
Handle(CDM_Application) theApplication;
TCollection_ExtendedString ErrorString;
while(!getListOfDocumentToUpdate().IsEmpty()) {
theDocumentToUpdate=getListOfDocumentToUpdate().First();
while(!aListOfDocumentsToUpdate.IsEmpty()) {
theDocumentToUpdate = aListOfDocumentsToUpdate.First();
theApplication=theDocumentToUpdate->Application();
ErrorString.Clear();
theApplication->BeginOfUpdate(theDocumentToUpdate);
theApplication->EndOfUpdate (theDocumentToUpdate,
theDocumentToUpdate->Update(ErrorString),
ErrorString);
getListOfDocumentToUpdate().RemoveFirst();
aListOfDocumentsToUpdate.RemoveFirst();
}
}
}
@@ -519,104 +505,6 @@ Standard_ExtString CDM_Document::Comment() const
return myComments(1).ToExtString();
}
//=======================================================================
//function : Presentation
//purpose :
//=======================================================================
Standard_ExtString CDM_Document::Presentation()
{
if(!myValidPresentation) ComputePresentation();
return myPresentation.ToExtString();
}
//=======================================================================
//function : UnvalidPresentation
//purpose :
//=======================================================================
void CDM_Document::UnvalidPresentation()
{
if(myValidPresentation) {
getPresentations().UnBind(myPresentation);
myValidPresentation=Standard_False;
}
}
//=======================================================================
//function : ComputePresentation
//purpose :
//=======================================================================
void CDM_Document::ComputePresentation()
{
TCollection_ExtendedString presentation("");
static Standard_Integer theUnnamedDocuments(0);
static CDM_NamesDirectory theNames;
if(!myMetaData.IsNull()) {
presentation += myMetaData->Name();
if(!theNames.IsBound(presentation)) theNames.Bind(presentation,0);
Standard_Integer range = theNames(presentation);
range += 1;
theNames(presentation) = range;
if(range != 1) {
presentation += "<";
presentation += range;
presentation += ">";
}
}
else {
presentation = "Document_";
presentation += ++theUnnamedDocuments;
}
if(getPresentations().IsBound(presentation)) {
TCollection_ExtendedString Test = presentation;
Test += "!";
Standard_Integer Count=0;
while (getPresentations().IsBound(Test)) {
Count++;
Test = presentation; Test+= "!"; Test+= Count;
}
presentation = Test;
}
myPresentation = TCollection_ExtendedString(presentation);
myValidPresentation = Standard_True;
getPresentations().Bind(presentation,this);
}
//=======================================================================
//function : FindFromPresentation
//purpose :
//=======================================================================
Handle(CDM_Document) CDM_Document::FindFromPresentation
(const TCollection_ExtendedString& aPresentation)
{
TCollection_ExtendedString x(aPresentation);
if(!getPresentations().IsBound(x)) {
Standard_SStream aMsg;
aMsg <<"No document having this presentation: " << x << " does exist."
<< std::endl << (char)0;
throw Standard_NoSuchObject(aMsg.str().c_str());
}
return getPresentations()(x);
}
//=======================================================================
//function : FindPresentation
//purpose :
//=======================================================================
Standard_Boolean CDM_Document::FindPresentation
(const TCollection_ExtendedString& aPresentation)
{
return getPresentations().IsBound(aPresentation);
}
//=======================================================================
//function : IsStored
//purpose :
@@ -649,7 +537,7 @@ void CDM_Document::SetMetaData(const Handle(CDM_MetaData)& aMetaData)
aMetaData->SetDocument(this);
// Update the document refencing this MetaData:
CDM_DataMapIteratorOfMetaDataLookUpTable it(CDM_MetaData::LookUpTable());
CDM_DataMapIteratorOfMetaDataLookUpTable it(*CDM_MetaData::LookUpTable());
for(;it.More();it.Next()) {
const Handle(CDM_MetaData)& theMetaData=it.Value();
if(theMetaData != aMetaData && theMetaData->IsRetrieved()) {
@@ -660,11 +548,8 @@ void CDM_Document::SetMetaData(const Handle(CDM_MetaData)& aMetaData)
}
}
if(!myMetaData.IsNull()) {
if(myMetaData->Name() != aMetaData->Name()) UnvalidPresentation();
myMetaData->UnsetDocument();
}
else
UnvalidPresentation();
}
myStorageVersion = Modifications();
@@ -684,7 +569,6 @@ void CDM_Document::UnsetIsStored()
{
if(!myMetaData.IsNull()) {
myMetaData->UnsetDocument();
// myMetaData.Nullify();
}
}
@@ -791,7 +675,7 @@ TCollection_ExtendedString CDM_Document::RequestedName()
if(!myMetaData.IsNull())
myRequestedName=myMetaData->Name();
else
myRequestedName=Presentation();
myRequestedName="Document_";
}
myRequestedNameIsDefined=Standard_True;
return myRequestedName;
@@ -912,7 +796,6 @@ void CDM_Document::Close()
RemoveAllReferences();
UnsetIsStored();
myApplication.Nullify();
UnvalidPresentation();
}
@@ -1299,8 +1182,6 @@ void CDM_Document::DumpJson (Standard_OStream& theOStream, Standard_Integer theD
const TCollection_ExtendedString& aComment = aCommentIt.Value();
OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aComment)
}
OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myPresentation)
OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myValidPresentation)
for (CDM_ListOfReferences::Iterator aFromReferenceIt (myFromReferences); aFromReferenceIt.More(); aFromReferenceIt.Next())
{

View File

@@ -25,6 +25,7 @@
#include <TColStd_SequenceOfExtendedString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <Standard_OStream.hxx>
#include <CDM_ListOfDocument.hxx>
class CDM_MetaData;
class CDM_Application;
@@ -216,21 +217,6 @@ public:
//! the comment is an empty string.
Standard_EXPORT Standard_ExtString Comment() const;
//! Returns an alphanumeric string identifying this document
//! in a unique manner in the current process. The presentation
//! may change when the document is stored.
//! Tries to get the 'FileFormat`.Presentation resource
//! This item is used to give a default presentation
//! to the document.
Standard_EXPORT Standard_ExtString Presentation();
//! returns the document having the given alphanumeric presentation.
Standard_EXPORT static Handle(CDM_Document) FindFromPresentation (const TCollection_ExtendedString& aPresentation);
//! indicates whether a document having the given presentation
//! does exist.
Standard_EXPORT static Standard_Boolean FindPresentation (const TCollection_ExtendedString& aPresentation);
Standard_EXPORT Standard_Boolean IsStored() const;
//! returns the value of the modification counter at the
@@ -374,10 +360,6 @@ private:
//! the manager returned by this method will be
//! used to search for the following resource items.
Standard_EXPORT Handle(Resource_Manager) StorageResource();
Standard_EXPORT void ComputePresentation();
Standard_EXPORT void UnvalidPresentation();
Standard_EXPORT void AddToReference (const Handle(CDM_Reference)& aReference);
@@ -385,9 +367,8 @@ private:
Standard_EXPORT void RemoveFromReference (const Standard_Integer aReferenceIdentifier);
TColStd_SequenceOfExtendedString myComments;
TCollection_ExtendedString myPresentation;
Standard_Boolean myValidPresentation;
CDM_ListOfReferences myFromReferences;
CDM_ListOfReferences myToReferences;
Standard_Integer myVersion;
@@ -407,7 +388,6 @@ private:
Standard_Boolean myDescriptionWasFound;
Handle(CDM_Application) myApplication;
Standard_Integer myStorageFormatVersion;
};

View File

@@ -20,17 +20,16 @@
#include <CDM_MetaData.hxx>
#include <CDM_MetaDataLookUpTable.hxx>
#include <CDM_Reference.hxx>
#include <CDF_Session.hxx>
#include <Standard_Dump.hxx>
#include <CDF_Application.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_Type.hxx>
#include <TCollection_ExtendedString.hxx>
#include <OSD_Thread.hxx>
IMPLEMENT_STANDARD_RTTIEXT(CDM_MetaData,Standard_Transient)
static CDM_MetaDataLookUpTable& getLookUpTable(){
static CDM_MetaDataLookUpTable theLookUpTable;
return theLookUpTable;
}
CDM_MetaData::CDM_MetaData(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aPath,const TCollection_ExtendedString& aFileName,const Standard_Boolean ReadOnly):
myIsRetrieved(Standard_False),
myDocument(NULL),
@@ -75,12 +74,14 @@ Handle(CDM_MetaData) CDM_MetaData::LookUp(const TCollection_ExtendedString& aFol
Handle(CDM_MetaData) theMetaData;
TCollection_ExtendedString aConventionalPath=aPath;
aConventionalPath.ChangeAll('\\','/');
if(!getLookUpTable().IsBound(aConventionalPath)) {
CDM_MetaDataLookUpTable* aLookUpTable = LookUpTable();
if (!aLookUpTable) return theMetaData;
if(!aLookUpTable->IsBound(aConventionalPath)) {
theMetaData = new CDM_MetaData(aFolder,aName,aPath,aFileName,ReadOnly);
getLookUpTable().Bind(aConventionalPath,theMetaData);
aLookUpTable->Bind(aConventionalPath, theMetaData);
}
else
theMetaData = getLookUpTable()(aConventionalPath);
theMetaData = aLookUpTable->Find(aConventionalPath);
return theMetaData;
}
@@ -88,12 +89,14 @@ Handle(CDM_MetaData) CDM_MetaData::LookUp(const TCollection_ExtendedString& aFol
Handle(CDM_MetaData) theMetaData;
TCollection_ExtendedString aConventionalPath=aPath;
aConventionalPath.ChangeAll('\\','/');
if(!getLookUpTable().IsBound(aConventionalPath)) {
CDM_MetaDataLookUpTable* aLookUpTable = LookUpTable();
if (!aLookUpTable) return theMetaData;
if(!aLookUpTable->IsBound(aConventionalPath)) {
theMetaData = new CDM_MetaData(aFolder,aName,aPath,aVersion,aFileName,ReadOnly);
getLookUpTable().Bind(aConventionalPath,theMetaData);
aLookUpTable->Bind(aConventionalPath,theMetaData);
}
else
theMetaData = getLookUpTable()(aConventionalPath);
theMetaData = aLookUpTable->Find(aConventionalPath);
return theMetaData;
}
@@ -130,8 +133,14 @@ Standard_OStream& CDM_MetaData::Print(Standard_OStream& anOStream) const {
Standard_OStream& CDM_MetaData::operator << (Standard_OStream& anOStream) {
return Print(anOStream);
}
const CDM_MetaDataLookUpTable& CDM_MetaData::LookUpTable() {
return getLookUpTable();
CDM_MetaDataLookUpTable* CDM_MetaData::LookUpTable() {
Handle(CDF_Session) aSession = CDF_Session::Create();
Handle(CDF_Application) anApp;
CDM_MetaDataLookUpTable* pLookUpTable(NULL);
if (aSession->FindApplication(OSD_Thread::Current(), anApp))
return anApp->MetaDataLookUpTable();
return pLookUpTable;
}
Standard_Integer CDM_MetaData::DocumentVersion(const Handle(CDM_Application)& anApplication) {
if(myDocumentVersion==0) myDocumentVersion=anApplication->DocumentVersion(this);

View File

@@ -115,7 +115,7 @@ private:
Standard_EXPORT void SetDocument (const Handle(CDM_Document)& aDocument);
Standard_EXPORT static const CDM_MetaDataLookUpTable& LookUpTable();
Standard_EXPORT static CDM_MetaDataLookUpTable* LookUpTable();
Standard_EXPORT Standard_Integer DocumentVersion (const Handle(CDM_Application)& anApplication);

View File

@@ -19,7 +19,7 @@
#include <TCollection_ExtendedString.hxx>
#include <NCollection_DataMap.hxx>
class CDM_MetaData;
typedef NCollection_DataMap<TCollection_ExtendedString,Handle(CDM_MetaData),TCollection_ExtendedString> CDM_MetaDataLookUpTable;
typedef NCollection_DataMap<TCollection_ExtendedString,Handle(CDM_MetaData),TCollection_ExtendedString>::Iterator CDM_DataMapIteratorOfMetaDataLookUpTable;

View File

@@ -2,7 +2,6 @@ CDM_Application.cxx
CDM_Application.hxx
CDM_CanCloseStatus.hxx
CDM_DataMapIteratorOfMetaDataLookUpTable.hxx
CDM_DataMapIteratorOfPresentationDirectory.hxx
CDM_Document.cxx
CDM_Document.hxx
CDM_DocumentHasher.hxx
@@ -17,7 +16,7 @@ CDM_MetaData.cxx
CDM_MetaData.hxx
CDM_MetaDataLookUpTable.hxx
CDM_NamesDirectory.hxx
CDM_PresentationDirectory.hxx
CDM_ApplicationDirectory.hxx
CDM_Reference.cxx
CDM_Reference.hxx
CDM_ReferenceIterator.cxx