d->cleanupInfo = nullptr;
d->ownData = false;
d->roData = false;
- d->ref = 1;
+ d->ref.setOwned();
}
VBitmap VBitmap::copy(const VRect& r) const
#define VECTOR_FALLTHROUGH
+#include<atomic>
class RefCount
{
public:
- inline RefCount(){}
inline RefCount(int i):atomic(i){}
inline bool ref() {
- int count = atomic;
+ int count = atomic.load();
if (count == 0) // !isSharable
return false;
if (count != -1) // !isStatic
- atomic++;
+ atomic.fetch_add(1);
return true;
}
inline bool deref() {
- int count = atomic;
+ int count = atomic.load();
if (count == 0) // !isSharable
return false;
if (count == -1) // isStatic
return true;
- return --atomic;
+ atomic.fetch_sub(1);
+ return --count;
}
bool isShared() const
{
- int count = atomic;
+ int count = atomic.load();
return (count != 1) && (count != 0);
}
bool isStatic() const
{
// Persistent object, never deleted
- return atomic == -1;
+ int count = atomic.load();
+ return count == -1;
}
inline int count()const{return atomic;}
- void setOwned() { atomic = 1; }
- void setUnsharable() { atomic = 0; }
+ void setOwned() { atomic.store(1); }
private:
- int atomic;
+ std::atomic<int> atomic;
};
template <typename T>
*/
struct VMatrixData {
+ VMatrixData(): ref(-1),
+ type(VMatrix::MatrixType::None),
+ dirty(VMatrix::MatrixType::None),
+ m11(1), m12(0), m13(0),
+ m21(0), m22(1), m23(0),
+ mtx(0), mty(0), m33(1){}
RefCount ref;
VMatrix::MatrixType type;
VMatrix::MatrixType dirty;
float m21, m22, m23;
float mtx, mty, m33;
};
-static const struct VMatrixData shared_empty = {RefCount(-1),
- VMatrix::MatrixType::None,
- VMatrix::MatrixType::None,
- 1, 0, 0,
- 0, 1, 0,
- 0, 0, 1};
+
+static const struct VMatrixData shared_empty;
+
inline float VMatrix::determinant() const
{
return d->m11*(d->m33*d->m22 - d->mty*d->m23) -
VMatrix::VMatrix(bool init V_UNUSED)
{
d = new VMatrixData;
- memcpy(d, &shared_empty, sizeof(VMatrixData));
d->ref.setOwned();
}
struct VPathData
{
+ VPathData():ref(-1),
+ m_points(),
+ m_elements(),
+ m_segments(0),
+ mStartPoint(),
+ mNewSegment(true){}
+
void copy(VPathData *o);
void moveTo(const VPointF &pt);
void lineTo(const VPointF &pt);
}
-static const struct VPathData shared_empty = {RefCount(-1),
- std::vector<VPointF>(),
- std::vector<VPath::Element>(),
- 0,
- VPointF(),
- true};
+static const struct VPathData shared_empty;
inline void VPath::cleanUp(VPathData *d)
{
{
VPath other;
- other.d = new VPathData(shared_empty);
+ other.d = new VPathData;
other.d->m_points = d->m_points;
other.d->m_elements = d->m_elements;
other.d->m_segments = d->m_segments;
V_BEGIN_NAMESPACE
static VRegionPrivate regionPrivate = {{0,0,0,0}, NULL};
-const VRegion::VRegionData VRegion::shared_empty = {RefCount(-1), ®ionPrivate};
+const VRegion::VRegionData VRegion::shared_empty;
inline VRect box_to_rect(box_type_t *box)
{
void detach();
struct VRegionData {
+ VRegionData():ref(-1),rgn(nullptr){}
RefCount ref;
VRegionPrivate *rgn;
};
struct VRleData
{
+ VRleData():ref(-1), impl(){}
RefCount ref;
VRleImpl impl;
};
-static const struct VRleData shared_empty = {RefCount(-1),
- VRleImpl()};
+static const struct VRleData shared_empty;
inline void VRle::cleanUp(VRleData *d)
{