Krita Source Code Documentation
Loading...
Searching...
No Matches
KisShared Class Reference

#include <kis_shared.h>

+ Inheritance diagram for KisShared:

Public Member Functions

bool deref ()
 
bool ref ()
 
int refCount ()
 
QAtomicInt * sharedWeakReference ()
 

Protected Member Functions

 KisShared ()
 
 ~KisShared ()
 

Private Member Functions

 KisShared (const KisShared &)
 
KisSharedoperator= (const KisShared &)
 

Private Attributes

QAtomicInt _ref
 
QAtomicInt * _sharedWeakReference
 

Detailed Description

Definition at line 13 of file kis_shared.h.

Constructor & Destructor Documentation

◆ KisShared() [1/2]

KisShared::KisShared ( const KisShared & )
private

◆ KisShared() [2/2]

KisShared::KisShared ( )
protected

NOTE: The description of how Weak shared pointers system works:

Every KisShared object has his own _sharedWeakReference pointer. This pointer holds QAtomicInt counter. When KisShared constructs itself, it increments _sharedWeakReference by one. When it dies - it decrements it. This is the only way how the number in the counter can become odd. Obviously, when the number falls to zero, the counter object is deleted.

When a weak shared pointer is created, it gets the pointer and increments the counter by 2, so the parity of the number is kept unchanged. Now the counter is shared between the KisShared and KisWeakSharedPtr and the latter one can check the correctness of the pointer by checking parity!

We can defer creation of a weak reference until better days... It gives us 41% better performance. ;)

Definition at line 28 of file kis_shared.cpp.

29{
35}
QAtomicInt * _sharedWeakReference
Definition kis_shared.h:45

References _sharedWeakReference.

◆ ~KisShared()

KisShared::~KisShared ( )
protected

Check no-one references us

Definition at line 37 of file kis_shared.cpp.

38{
42 Q_ASSERT(_ref == 0);
43
46}
QAtomicInt _ref
Definition kis_shared.h:44

References _ref, and _sharedWeakReference.

Member Function Documentation

◆ deref()

bool KisShared::deref ( )
inline

Definition at line 28 of file kis_shared.h.

28 {
29 Q_ASSERT(_ref > 0);
30 return _ref.deref();
31 }

◆ operator=()

KisShared & KisShared::operator= ( const KisShared & )
private

◆ ref()

bool KisShared::ref ( )
inline

Definition at line 25 of file kis_shared.h.

25 {
26 return _ref.ref();
27 }

◆ refCount()

int KisShared::refCount ( )
inline

Definition at line 22 of file kis_shared.h.

22 {
23 return _ref;
24 }

◆ sharedWeakReference()

QAtomicInt * KisShared::sharedWeakReference ( )
inline

Definition at line 34 of file kis_shared.h.

34 {
36 _sharedWeakReference = new QAtomicInt();
38 }
39
41 }

Member Data Documentation

◆ _ref

QAtomicInt KisShared::_ref
private

Definition at line 44 of file kis_shared.h.

◆ _sharedWeakReference

QAtomicInt* KisShared::_sharedWeakReference
private

Definition at line 45 of file kis_shared.h.


The documentation for this class was generated from the following files: