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

#include <recorder_writer.h>

+ Inheritance diagram for ThreadCounter:

Signals

void notifyInUseChange (bool valueWasIncreased)
 
void notifyValueChange (bool valueWasIncreased)
 

Public Member Functions

void decUsedAndNotify ()
 
unsigned int get () const
 
unsigned int getUsed () const
 
void incUsedAndNotify ()
 
ThreadCounter & operator= (const ThreadCounter &)=delete
 
ThreadCounter & operator= (ThreadCounter &&)=delete
 
bool set (int value)
 
void setAndNotify (int value)
 
bool setUsed (int value)
 
void setUsedAndNotify (int value)
 
 ThreadCounter ()=default
 
 ThreadCounter (const ThreadCounter &)=delete
 
 ThreadCounter (ThreadCounter &&)=delete
 

Private Member Functions

bool setUsedImpl (int value)
 

Private Attributes

unsigned int inUse
 
QMutex inUseMutex
 
unsigned int threads
 

Detailed Description

Definition at line 38 of file recorder_writer.h.

Constructor & Destructor Documentation

◆ ThreadCounter() [1/3]

ThreadCounter::ThreadCounter ( )
default

◆ ThreadCounter() [2/3]

ThreadCounter::ThreadCounter ( const ThreadCounter & )
delete

◆ ThreadCounter() [3/3]

ThreadCounter::ThreadCounter ( ThreadCounter && )
delete

Member Function Documentation

◆ decUsedAndNotify()

void ThreadCounter::decUsedAndNotify ( )

Definition at line 107 of file recorder_writer.cpp.

108{
109 QMutexLocker lock(&inUseMutex);
110 if (setUsedImpl(inUse - 1)) {
111 // Emit signal to GUI that the value has been changed
112 Q_EMIT notifyInUseChange(false);
113 }
114}
bool setUsedImpl(int value)
unsigned int inUse
void notifyInUseChange(bool valueWasIncreased)

References inUse, inUseMutex, notifyInUseChange(), and setUsedImpl().

◆ get()

unsigned int ThreadCounter::get ( ) const

Definition at line 77 of file recorder_writer.cpp.

78{
79 return threads;
80}
unsigned int threads

References threads.

◆ getUsed()

unsigned int ThreadCounter::getUsed ( ) const

Definition at line 116 of file recorder_writer.cpp.

117{
118 return inUse;
119}

References inUse.

◆ incUsedAndNotify()

void ThreadCounter::incUsedAndNotify ( )

Definition at line 98 of file recorder_writer.cpp.

99{
100 QMutexLocker lock(&inUseMutex);
101 auto oldValue = getUsed();
102 if (setUsedImpl(inUse + 1)) {
103 // Emit signal to GUI that the value has been changed
104 Q_EMIT notifyInUseChange(oldValue < getUsed());
105 }
106}
unsigned int getUsed() const

References getUsed(), inUse, inUseMutex, notifyInUseChange(), and setUsedImpl().

◆ notifyInUseChange

void ThreadCounter::notifyInUseChange ( bool valueWasIncreased)
signal

◆ notifyValueChange

void ThreadCounter::notifyValueChange ( bool valueWasIncreased)
signal

◆ operator=() [1/2]

ThreadCounter & ThreadCounter::operator= ( const ThreadCounter & )
delete

◆ operator=() [2/2]

ThreadCounter & ThreadCounter::operator= ( ThreadCounter && )
delete

◆ set()

bool ThreadCounter::set ( int value)

Definition at line 59 of file recorder_writer.cpp.

60{
61 auto oldValue = threads;
62 threads = static_cast<unsigned int>(
63 qBound(1, value, static_cast<int>(ThreadSystemValue::MaxThreadCount))
64 );
65 return oldValue != threads;
66}
float value(const T *src, size_t ch)
const unsigned int MaxThreadCount

References ThreadSystemValue::MaxThreadCount, threads, and value().

◆ setAndNotify()

void ThreadCounter::setAndNotify ( int value)

Definition at line 68 of file recorder_writer.cpp.

69{
70 auto oldValue = get();
71 if (set(value)) {
72 // Emit signal to GUI that the value has been changed
73 Q_EMIT notifyValueChange(oldValue < get());
74 }
75}
unsigned int get() const
void notifyValueChange(bool valueWasIncreased)
bool set(int value)

References get(), notifyValueChange(), set(), and value().

◆ setUsed()

bool ThreadCounter::setUsed ( int value)

Definition at line 82 of file recorder_writer.cpp.

83{
84 QMutexLocker lock(&inUseMutex);
85 return setUsedImpl(value);
86}

References inUseMutex, setUsedImpl(), and value().

◆ setUsedAndNotify()

void ThreadCounter::setUsedAndNotify ( int value)

Definition at line 88 of file recorder_writer.cpp.

89{
90 QMutexLocker lock(&inUseMutex);
91 auto oldValue = getUsed();
92 if (setUsedImpl(value)) {
93 // Emit signal to GUI that the value has been changed
94 Q_EMIT notifyInUseChange(oldValue < getUsed());
95 }
96}

References getUsed(), inUseMutex, notifyInUseChange(), setUsedImpl(), and value().

◆ setUsedImpl()

bool ThreadCounter::setUsedImpl ( int value)
private

Definition at line 121 of file recorder_writer.cpp.

122{
123 auto oldValue = inUse;
124 inUse = static_cast<unsigned int>(
125 qBound(0, value, static_cast<int>(threads))
126 );
127 return oldValue != inUse;
128}

References inUse, threads, and value().

Member Data Documentation

◆ inUse

unsigned int ThreadCounter::inUse
private

Definition at line 67 of file recorder_writer.h.

◆ inUseMutex

QMutex ThreadCounter::inUseMutex
private

Definition at line 68 of file recorder_writer.h.

◆ threads

unsigned int ThreadCounter::threads
private

Definition at line 66 of file recorder_writer.h.


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