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 36 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 94 of file recorder_writer.cpp.

95{
96 QMutexLocker lock(&inUseMutex);
97 if (setUsedImpl(inUse - 1)) {
98 // Emit signal to GUI that the value has been changed
99 Q_EMIT notifyInUseChange(false);
100 }
101}
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 64 of file recorder_writer.cpp.

65{
66 return threads;
67}
unsigned int threads

References threads.

◆ getUsed()

unsigned int ThreadCounter::getUsed ( ) const

Definition at line 103 of file recorder_writer.cpp.

104{
105 return inUse;
106}

References inUse.

◆ incUsedAndNotify()

void ThreadCounter::incUsedAndNotify ( )

Definition at line 85 of file recorder_writer.cpp.

86{
87 QMutexLocker lock(&inUseMutex);
88 auto oldValue = getUsed();
89 if (setUsedImpl(inUse + 1)) {
90 // Emit signal to GUI that the value has been changed
91 Q_EMIT notifyInUseChange(oldValue < getUsed());
92 }
93}
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 46 of file recorder_writer.cpp.

47{
48 auto oldValue = threads;
49 threads = static_cast<unsigned int>(
50 qBound(1, value, static_cast<int>(ThreadSystemValue::MaxThreadCount))
51 );
52 return oldValue != threads;
53}
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 55 of file recorder_writer.cpp.

56{
57 auto oldValue = get();
58 if (set(value)) {
59 // Emit signal to GUI that the value has been changed
60 Q_EMIT notifyValueChange(oldValue < get());
61 }
62}
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 69 of file recorder_writer.cpp.

70{
71 QMutexLocker lock(&inUseMutex);
72 return setUsedImpl(value);
73}

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

◆ setUsedAndNotify()

void ThreadCounter::setUsedAndNotify ( int value)

Definition at line 75 of file recorder_writer.cpp.

76{
77 QMutexLocker lock(&inUseMutex);
78 auto oldValue = getUsed();
79 if (setUsedImpl(value)) {
80 // Emit signal to GUI that the value has been changed
81 Q_EMIT notifyInUseChange(oldValue < getUsed());
82 }
83}

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

◆ setUsedImpl()

bool ThreadCounter::setUsedImpl ( int value)
private

Definition at line 108 of file recorder_writer.cpp.

109{
110 auto oldValue = inUse;
111 inUse = static_cast<unsigned int>(
112 qBound(0, value, static_cast<int>(threads))
113 );
114 return oldValue != inUse;
115}

References inUse, threads, and value().

Member Data Documentation

◆ inUse

unsigned int ThreadCounter::inUse
private

Definition at line 65 of file recorder_writer.h.

◆ inUseMutex

QMutex ThreadCounter::inUseMutex
private

Definition at line 66 of file recorder_writer.h.

◆ threads

unsigned int ThreadCounter::threads
private

Definition at line 64 of file recorder_writer.h.


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