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 71 of file kis_lock_free_lod_counter.h.

71 {
72 return (counter << 8) | (lod & 0xFF);
73 }

◆ readLod()

int KisLockFreeLodCounter::readLod ( ) const
inline

Definition at line 56 of file kis_lock_free_lod_counter.h.

56 {
57 int value = m_num;
58
59 int counter;
60 int lod;
61 unpackLod(value, &counter, &lod);
62
63 return counter ? lod : -1;
64 }
float value(const T *src, size_t ch)

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

◆ 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 66 of file kis_lock_free_lod_counter.h.

66 {
67 m_num = 0;
68 }

References m_num.

◆ unpackLod()

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

Definition at line 75 of file kis_lock_free_lod_counter.h.

75 {
76 *lod = value & 0xFF;
77 *counter = value >> 8;
78 }

References value().

Member Data Documentation

◆ m_num

QAtomicInt KisLockFreeLodCounter::m_num
private

Definition at line 81 of file kis_lock_free_lod_counter.h.


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