22 lines
688 B
C++
22 lines
688 B
C++
#pragma once
|
|
#include "frame_result.hpp"
|
|
#include <atomic>
|
|
#include <stdexcept>
|
|
|
|
namespace cms {
|
|
// One immutable result variable. Readers neither remove nor acknowledge results.
|
|
class LatestResult {
|
|
public:
|
|
void publish(FrameResultPtr result) {
|
|
if(!result)throw std::invalid_argument("Cannot publish a null result");
|
|
std::atomic_store_explicit(&latest_,std::move(result),std::memory_order_release);
|
|
}
|
|
void clear() { std::atomic_store_explicit(&latest_,FrameResultPtr{},std::memory_order_release); }
|
|
FrameResultPtr load() const {
|
|
return std::atomic_load_explicit(&latest_,std::memory_order_acquire);
|
|
}
|
|
private:
|
|
FrameResultPtr latest_;
|
|
};
|
|
}
|