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 ()
 
ThreadCounteroperator= (const ThreadCounter &)=delete
 
ThreadCounteroperator= (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 35 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 104 of file recorder_writer.cpp.

105{
106 QMutexLocker lock(&inUseMutex);
107 if (setUsedImpl(inUse - 1)) {
108 // Emit signal to GUI that the value has been changed
109 Q_EMIT notifyInUseChange(false);
110 }
111}
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 74 of file recorder_writer.cpp.

75{
76 return threads;
77}
unsigned int threads

References threads.

◆ getUsed()

unsigned int ThreadCounter::getUsed ( ) const

Definition at line 113 of file recorder_writer.cpp.

114{
115 return inUse;
116}

References inUse.

◆ incUsedAndNotify()

void ThreadCounter::incUsedAndNotify ( )

Definition at line 95 of file recorder_writer.cpp.

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

57{
58 auto oldValue = threads;
59 threads = static_cast<unsigned int>(
60 qBound(1, value, static_cast<int>(ThreadSystemValue::MaxThreadCount))
61 );
62 return oldValue != threads;
63}
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 65 of file recorder_writer.cpp.

66{
67 auto oldValue = get();
68 if (set(value)) {
69 // Emit signal to GUI that the value has been changed
70 Q_EMIT notifyValueChange(oldValue < get());
71 }
72}
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 79 of file recorder_writer.cpp.

80{
81 QMutexLocker lock(&inUseMutex);
82 return setUsedImpl(value);
83}

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

◆ setUsedAndNotify()

void ThreadCounter::setUsedAndNotify ( int value)

Definition at line 85 of file recorder_writer.cpp.

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

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

◆ setUsedImpl()

bool ThreadCounter::setUsedImpl ( int value)
private

Definition at line 118 of file recorder_writer.cpp.

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

References inUse, threads, and value().

Member Data Documentation

◆ inUse

unsigned int ThreadCounter::inUse
private

Definition at line 64 of file recorder_writer.h.

◆ inUseMutex

QMutex ThreadCounter::inUseMutex
private

Definition at line 65 of file recorder_writer.h.

◆ threads

unsigned int ThreadCounter::threads
private

Definition at line 63 of file recorder_writer.h.


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