refs #522, mutex for mutable members (thread safe)

* copy/assignment/lock for mutable members
* also removed redundant in status message (slack discussion MS/KB)
This commit is contained in:
Klaus Basan
2015-11-26 02:31:13 +01:00
parent a4ba45ce75
commit d6733d49bb
13 changed files with 115 additions and 73 deletions

View File

@@ -19,6 +19,24 @@ namespace BlackMisc
{
CUrlList::CUrlList() { }
CUrlList::CUrlList(const CUrlList &other) : CSequence<CUrl>(other)
{
*this = other;
}
CUrlList &CUrlList::operator =(const CUrlList &other)
{
if (this == &other) { return *this; }
QReadLocker readLock(&other.m_lock);
int index = other.m_currentIndexDistributedLoad;
readLock.unlock(); // avoid deadlock
QWriteLocker writeLock(&this->m_lock);
this->m_currentIndexDistributedLoad = index;
return *this;
}
CUrlList::CUrlList(const QStringList &listOfUrls, bool removeDuplicates)
{
QStringList urlList(listOfUrls);

View File

@@ -16,6 +16,7 @@
#include "blackmisc/network/url.h"
#include "blackmisc/collection.h"
#include "blackmisc/sequence.h"
#include <QReadWriteLock>
namespace BlackMisc
{
@@ -32,6 +33,12 @@ namespace BlackMisc
//! Default constructor.
CUrlList();
//! Copy constructor (because of mutex)
CUrlList(const CUrlList &other);
//! Copy assignment (because of mutex)
CUrlList &operator =(const CUrlList &other);
//! By list of URLs
explicit CUrlList(const QStringList &listOfUrls, bool removeDuplicates = true);
@@ -67,6 +74,7 @@ namespace BlackMisc
private:
mutable int m_currentIndexDistributedLoad = -1; //!< index for random access
mutable QReadWriteLock m_lock; //!< lock (because of mutable members)
};
//! URL list with fail support