Skip to content

Commit 0f9378a

Browse files
committed
[vpdq] Fix VpdqHasher destructor
1 parent fb67712 commit 0f9378a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

vpdq/cpp/vpdq/cpp/hashing/hasher.h

+18-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <vector>
2222

2323
#include <vpdq/cpp/hashing/bufferhasher.h>
24-
#include <vpdq/cpp/hashing/ffmpegwrapper.h>
2524
#include <vpdq/cpp/hashing/vpdqHashType.h>
2625

2726
namespace facebook {
@@ -83,6 +82,12 @@ class VpdqHasher {
8382
**/
8483
void push_back(TFrame&& frame);
8584

85+
/** @brief Stop and join all hashing threads.
86+
*
87+
* @note Not thread safe.
88+
**/
89+
void stop_hashing();
90+
8691
/** @brief Block until all frames are finished hashing and get the final
8792
* result.
8893
*
@@ -98,6 +103,8 @@ class VpdqHasher {
98103
VpdqHasher(VpdqHasher&&) = delete;
99104
VpdqHasher& operator=(VpdqHasher&&) = delete;
100105

106+
~VpdqHasher() { stop_hashing(); }
107+
101108
private:
102109
/** @brief True if hashing is multithreaded, false if singlethreaded.
103110
**/
@@ -210,10 +217,14 @@ void VpdqHasher<TFrame>::push_back(TFrame&& frame) {
210217
}
211218

212219
template <typename TFrame>
213-
std::vector<vpdqFeature> VpdqHasher<TFrame>::finish() {
220+
void VpdqHasher<TFrame>::stop_hashing() {
214221
if (m_multithreaded) {
215222
{
216223
std::lock_guard<std::mutex> lock(m_queue_mutex);
224+
if (m_done_hashing) {
225+
return;
226+
}
227+
217228
m_done_hashing = true;
218229
}
219230

@@ -222,6 +233,11 @@ std::vector<vpdqFeature> VpdqHasher<TFrame>::finish() {
222233
thread.join();
223234
}
224235
}
236+
}
237+
238+
template <typename TFrame>
239+
std::vector<vpdqFeature> VpdqHasher<TFrame>::finish() {
240+
this->stop_hashing();
225241

226242
// Sort out of order frames by frame number
227243
std::sort(
@@ -259,10 +275,6 @@ void VpdqHasher<TFrame>::consumer() {
259275
}
260276
}
261277

262-
// Explicit template instantiation for all frame types.
263-
template class VpdqHasher<GenericFrame>;
264-
template class VpdqHasher<ffmpeg::FFmpegFrame>;
265-
266278
} // namespace hashing
267279
} // namespace vpdq
268280
} // namespace facebook

0 commit comments

Comments
 (0)