CheckSameThread.h
// CheckSameThread.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2022
#ifndef Ceda_cxMessage_CheckSameThread_H
#define Ceda_cxMessage_CheckSameThread_H
#include <thread>
namespace ceda
{
class CheckSameThread
{
public:
bool operator()() const
{
if (initialised)
{
return id == std::this_thread::get_id();
}
else
{
initialised = true;
id = std::this_thread::get_id();
return true;
}
}
private:
mutable bool initialised = false;
mutable std::thread::id id;
};
} // namespace ceda
#endif // include guard