Skip to content

Commit

Permalink
Refs #4554 make sure to have a unique lock object
Browse files Browse the repository at this point in the history
when cloning a workspace. So explicitely declared the copy constructors of every class up to DataItem.
  • Loading branch information
Janik Zikovsky committed Jan 24, 2012
1 parent 2f19428 commit d6ae8f2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/Workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class MANTID_API_DLL Workspace : public Kernel::DataItem
{
public:
Workspace();
Workspace(const Workspace & other);
virtual ~Workspace();

// DataItem interface
Expand Down
8 changes: 8 additions & 0 deletions Code/Mantid/Framework/API/src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ namespace Mantid
if (std::find(m_writeLockedWorkspaces.begin(), m_writeLockedWorkspaces.end(), ws)
== m_writeLockedWorkspaces.end())
{
std::cout << "Write-locking " << ws->name() << std::endl;
// Write-lock it if not already
ws->getLock()->writeLock();
m_writeLockedWorkspaces.push_back(ws);
Expand All @@ -302,6 +303,7 @@ namespace Mantid
if (std::find(m_writeLockedWorkspaces.begin(), m_writeLockedWorkspaces.end(), ws)
== m_writeLockedWorkspaces.end())
{
std::cout << "Read-locking " << ws->name() << std::endl;
// Read-lock it if not already write-locked
ws->getLock()->readLock();
m_readLockedWorkspaces.push_back(ws);
Expand All @@ -324,13 +326,19 @@ namespace Mantid
{
Workspace_sptr ws = m_writeLockedWorkspaces[i];
if (ws)
{
std::cout << "Un-write-locking " << ws->name() << std::endl;
ws->getLock()->unlock();
}
}
for (size_t i=0; i<m_readLockedWorkspaces.size(); i++)
{
Workspace_sptr ws = m_readLockedWorkspaces[i];
if (ws)
{
std::cout << "Un-read-locking " << ws->name() << std::endl;
ws->getLock()->unlock();
}
}

// Don't double-unlock workspaces
Expand Down
16 changes: 13 additions & 3 deletions Code/Mantid/Framework/API/src/Workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ namespace API
{

/// Default constructor
Workspace::Workspace()
: DataItem(),
m_title(), m_comment(), m_name(), m_history()
Workspace::Workspace()
: DataItem(),
m_title(), m_comment(), m_name(), m_history()
{}

/** Copy constructor
* @param other :: workspace to copy
*/
Workspace::Workspace(const Workspace & other)
: DataItem(other),
m_title(other.m_title), m_comment(other.m_comment), m_name(other.m_name), m_history(other.m_history)
{
}


/// Workspace destructor
Workspace::~Workspace()
{
Expand Down
3 changes: 1 addition & 2 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/DataItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ namespace Mantid
class MANTID_KERNEL_DLL DataItem
{
public:
/// Default constructor
DataItem();
/// Destructor
DataItem(const DataItem & other);
virtual ~DataItem();

/** @name Interface */
Expand Down
14 changes: 12 additions & 2 deletions Code/Mantid/Framework/Kernel/src/DataItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ namespace Mantid
m_lock = new Poco::RWLock();
}

/** Copy constructor
*/
DataItem::DataItem(const DataItem & /*other*/)
{
// Always make a unique lock!
m_lock = new Poco::RWLock();
}

/**
* Destructor. Required in cpp do avoid linker errors when other projects try to inherit from DataItem
*/
DataItem::~DataItem()
{
// delete m_lock;
// m_lock = NULL;
delete m_lock;
m_lock = NULL;
}

/** Private method to access the RWLock object.
Expand All @@ -30,6 +38,8 @@ namespace Mantid
*/
Poco::RWLock * DataItem::getLock()
{
if (m_lock == NULL)
m_lock = new Poco::RWLock();
return m_lock;
}

Expand Down

0 comments on commit d6ae8f2

Please sign in to comment.