SmartSpectra C++ SDK
Measure human vitals from video with SmartSpectra C++ SDK.
Loading...
Searching...
No Matches
reactor_with_wait_until_done_impl.hpp
1
2// reactor_with_wait_until_done_impl.hpp
3// Created by greg on 2/20/25.
4// Copyright (C) 2025 Presage Security, Inc.
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 3 of the License, or (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this program; if not, write to the Free Software Foundation,
18// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21// === standard library includes (if any) ===
22// === third-party includes (if any) ===
23#include <glog/logging.h>
24// === local includes (if any) ===
25#include "reactor_with_wait_until_done.hpp"
26
27#pragma once
28
29namespace presage::smartspectra::grpc_bindings {
30
31
32template<typename TReactor>
33void ReactorWithWaitUntilDone<TReactor>::HandleWaitingThreads() {
34 {
35 std::unique_lock<std::mutex> lock(done_mutex);
36 this->done = true;
37 done_cv.notify_all();
38 }
39 if (this->waiting_thread_count > 0) {
40 std::unique_lock<std::mutex> lock(done_mutex);
41 done_cv.wait(lock, [this] { return waiting_thread_count == 0; });
42 }
43}
44
45template<typename TReactor>
46void ReactorWithWaitUntilDone<TReactor>::WaitUntilDone() {
47 std::unique_lock<std::mutex> lock(done_mutex);
48 this->waiting_thread_count++;
49 done_cv.wait(lock, [this] { return this->done; });
50 this->waiting_thread_count--;
51 done_cv.notify_one();
52}
53
54template<typename TReactor>
55void ReactorWithWaitUntilDone<TReactor>::OnDone() {
56 HandleWaitingThreads();
57}
58
59template<typename TReactor>
60void ReactorWithWaitUntilDone<TReactor>::OnCancel() {
61 HandleWaitingThreads();
62 LOG(ERROR) << "RPC Cancelled";
63}
64
65
66} // namespace presage::smartspectra::grpc_bindings