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

#include <kis_lock_free_lod_counter.h>

Public Member Functions

void addLod (int newLod)
 
int readLod () const
 
void removeLod ()
 
void testingClear ()
 

Static Private Member Functions

static int packLod (int counter, int lod)
 
static void unpackLod (int value, int *counter, int *lod)
 

Private Attributes

QAtomicInt m_num
 

Detailed Description

Definition at line 13 of file kis_lock_free_lod_counter.h.

Member Function Documentation

◆ addLod()

void KisLockFreeLodCounter::addLod ( int newLod)
inline

Definition at line 16 of file kis_lock_free_lod_counter.h.

16 {
17 int oldValue = 0;
18 int newValue = 0;
19
20 do {
21 oldValue = m_num;
22
23 int counter;
24 int lod;
25 unpackLod(oldValue, &counter, &lod);
26
27 if (!counter) {
28 lod = newLod;
29 } else {
30 Q_ASSERT(lod == newLod);
31 }
32
33 counter++;
34 newValue = packLod(counter, lod);
35 } while(!m_num.testAndSetOrdered(oldValue, newValue));
36 }
static int packLod(int counter, int lod)
static void unpackLod(int value, int *counter, int *lod)

References m_num, packLod(), and unpackLod().

◆ packLod()

static int KisLockFreeLodCounter::packLod ( int counter,
int lod )
inlinestaticprivate

Definition at line 69 of file kis_lock_free_lod_counter.h.

69 {
70 return (counter << 8) | (lod & 0xFF);
71 }

◆ readLod()

int KisLockFreeLodCounter::readLod ( ) const
inline

Definition at line 56 of file kis_lock_free_lod_counter.h.

56 {
57 int counter = 0;
58 int lod = 0;
59 unpackLod(m_num, &counter, &lod);
60
61 return counter ? lod : -1;
62 }

References m_num, and unpackLod().

◆ removeLod()

void KisLockFreeLodCounter::removeLod ( )
inline

Definition at line 38 of file kis_lock_free_lod_counter.h.

38 {
39 int oldValue = 0;
40 int newValue = 0;
41
42 do {
43 oldValue = m_num;
44
45 int counter;
46 int lod;
47 unpackLod(oldValue, &counter, &lod);
48
49 Q_ASSERT(counter > 0);
50
51 counter--;
52 newValue = packLod(counter, lod);
53 } while(!m_num.testAndSetOrdered(oldValue, newValue));
54 }

References m_num, packLod(), and unpackLod().

◆ testingClear()

void KisLockFreeLodCounter::testingClear ( )
inline

Definition at line 64 of file kis_lock_free_lod_counter.h.

64 {
65 m_num = 0;
66 }

References m_num.

◆ unpackLod()

static void KisLockFreeLodCounter::unpackLod ( int value,
int * counter,
int * lod )
inlinestaticprivate

Definition at line 73 of file kis_lock_free_lod_counter.h.

73 {
74 *lod = value & 0xFF;
75 *counter = value >> 8;
76 }
float value(const T *src, size_t ch)

References value().

Member Data Documentation

◆ m_num

QAtomicInt KisLockFreeLodCounter::m_num
private

Definition at line 79 of file kis_lock_free_lod_counter.h.


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