mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
Added another convenience class to simplify testing
(automates comparisons) fixed some unit tests caused by copy constructor removal git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7302 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
71a02003be
commit
4cab2aaa65
12 changed files with 160 additions and 72 deletions
|
@ -21,26 +21,43 @@ public:
|
|||
RsSharedPtr() : mShared(NULL), mCount(NULL) {}
|
||||
|
||||
RsSharedPtr(T* shared)
|
||||
: mShared(shared), mCount(new int(0))
|
||||
: mShared(shared), mCount(new int(0)), mSharedPtrMutex(new RsMutex("SharedMutex"))
|
||||
{
|
||||
mCount++;
|
||||
}
|
||||
|
||||
RsSharedPtr(const RsSharedPtr<T>& rsp)
|
||||
{
|
||||
rsp.lock();
|
||||
mShared = rsp.mShared;
|
||||
mCount = rsp.mCount;
|
||||
mCount++;
|
||||
mSharedPtrMutex = rsp.mSharedPtrMutex;
|
||||
rsp.unlock();
|
||||
|
||||
}
|
||||
|
||||
void operator=(const RsSharedPtr<T>& rsp)
|
||||
{
|
||||
rsp.lock();
|
||||
mSharedPtrMutex = rsp.mSharedPtrMutex;
|
||||
DecrementAndDeleteIfLast();
|
||||
mShared = rsp.mShared;
|
||||
RepointAndIncrement(rsp.mCount);
|
||||
|
||||
mSharedPtrMutex->unlock();
|
||||
}
|
||||
|
||||
T* release() { mCount--; T* temp = mShared; mShared = NULL; return temp; }
|
||||
T* release() {
|
||||
|
||||
lock();
|
||||
|
||||
mCount--; T* temp = mShared; mShared = NULL;
|
||||
|
||||
unlock();
|
||||
|
||||
return temp;
|
||||
}
|
||||
T* get() { return mShared; }
|
||||
|
||||
T& operator*(){ return *mShared; }
|
||||
|
@ -72,10 +89,14 @@ private:
|
|||
|
||||
}
|
||||
|
||||
void lock() const { mSharedPtrMutex->lock(); }
|
||||
void unlock() const { mSharedPtrMutex->unlock(); }
|
||||
|
||||
private:
|
||||
|
||||
int* mCount;
|
||||
T* mShared;
|
||||
RsMutex* mSharedPtrMutex;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue