digiKam
Loading...
Searching...
No Matches
recognitiontrainingupdatequeue.h
Go to the documentation of this file.
1
/* ============================================================
2
*
3
* This file is a part of digiKam
4
*
5
* Date : 2024-10-28
6
* Description : Threadsafe queue for submitting face training removal requests.
7
*
8
* SPDX-FileCopyrightText: 2024 by Michael Miller <micahel underscore miller at msn dot com>
9
* SPDX-FileCopyrightText: 2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
10
*
11
* SPDX-License-Identifier: GPL-2.0-or-later
12
*
13
* ============================================================ */
14
15
#pragma once
16
17
// C++ includes
18
19
#include <queue>
20
#include <mutex>
21
#include <condition_variable>
22
23
// Qt includes
24
25
#include <QString>
26
#include <QThread>
27
28
// Local includes
29
30
#include "
digikam_export.h
"
31
32
namespace
Digikam
33
{
34
35
/*
36
template <typename T>
37
class SharedQueue
38
{
39
public:
40
41
SharedQueue();
42
~SharedQueue();
43
44
T& front();
45
void pop_front();
46
47
void push_back(T& item);
48
void push_back(T&& item);
49
50
int size();
51
bool empty();
52
53
private:
54
55
std::deque<T> queue_;
56
std::mutex mutex_;
57
std::condition_variable cond_;
58
};
59
60
template <typename T>
61
SharedQueue<T>::SharedQueue() {}
62
63
template <typename T>
64
SharedQueue<T>::~SharedQueue() {}
65
66
template <typename T>
67
T& SharedQueue<T>::front()
68
{
69
std::unique_lock<std::mutex> mlock(mutex_);
70
71
while (queue_.empty())
72
{
73
cond_.wait(mlock);
74
}
75
76
return queue_.front();
77
}
78
79
template <typename T>
80
void SharedQueue<T>::pop_front()
81
{
82
std::unique_lock<std::mutex> mlock(mutex_);
83
84
while (queue_.empty())
85
{
86
cond_.wait(mlock);
87
}
88
89
queue_.pop_front();
90
}
91
92
template <typename T>
93
void SharedQueue<T>::push_back(T& item)
94
{
95
std::unique_lock<std::mutex> mlock(mutex_);
96
queue_.push_back(item);
97
mlock.unlock(); // Unlock before notificiation to minimize mutex con.
98
cond_.notify_one(); // Notify one waiting thread.
99
}
100
101
template <typename T>
102
void SharedQueue<T>::push_back(T&& item)
103
{
104
std::unique_lock<std::mutex> mlock(mutex_);
105
queue_.push_back(std::move(item));
106
mlock.unlock(); // Unlock before notificiation to minimize mutex con.
107
cond_.notify_one(); // Notify one waiting thread?
108
}
109
110
template <typename T>
111
int SharedQueue<T>::size()
112
{
113
std::unique_lock<std::mutex> mlock(mutex_);
114
int size = queue_.size();
115
mlock.unlock();
116
117
return size;
118
}
119
*/
120
121
// -----------------------------------------------------
122
123
template
<
typename
T>
124
class
SharedQueue;
125
126
class
DIGIKAM_EXPORT
RecognitionTrainingUpdateQueue
127
{
128
public
:
129
130
RecognitionTrainingUpdateQueue
();
131
~RecognitionTrainingUpdateQueue
();
132
133
public
:
134
135
void
push(
const
QString& hash);
136
void
pop();
137
QString front();
138
139
QString endSignal();
140
141
void
registerReaderThread(
const
QThread* thread);
142
void
unregisterReaderThread(
const
QThread* thread);
143
144
private
:
145
146
static
SharedQueue<QString> queue;
147
static
QList<const QThread*> readers;
148
static
int
ref;
149
150
Q_DISABLE_COPY(
RecognitionTrainingUpdateQueue
)
151
};
152
153
}
// namespace Digikam
Digikam::RecognitionTrainingUpdateQueue
Definition
recognitiontrainingupdatequeue.h:127
digikam_export.h
Digikam
Definition
datefolderview.cpp:34
core
libs
facesengine
recognition
recognitiontrainingupdatequeue.h
Generated by
1.9.8