mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user