Skip to content
Snippets Groups Projects
TellActorFromAnywhereTest.cpp 981 B
Newer Older
  • Learn to ignore specific revisions
  • // SPDX-License-Identifier: LGPL-3.0-or-later
    
    // Copyright © 2020-2021 Florian Schmaus
    
    #include <thread>
    
    #include "Actor.hpp"
    #include "BinaryPrivateSemaphore.hpp"
    
    #include "CallerEnvironment.hpp"
    
    #include "emper-common.h"
    
    class SignallingActor : public Actor<unsigned int> {
     private:
    	BinaryPrivateSemaphore& bps;
    
     protected:
    	void receive(UNUSED_ARG unsigned int signalCount) override { bps.signal(); }
    
     public:
    	SignallingActor(BinaryPrivateSemaphore& bps) : bps(bps){};
    };
    
    
    void emperTest() {
    
    	// Heap allocate the Actor and the BPS until we have a way to
    	// cleanly terminate the Actor.
    	auto* bps = new BinaryPrivateSemaphore();
    	auto* signallingActor = new SignallingActor(*bps);
    	signallingActor->start();
    
    
    	// TODO: Use std::jthread once EMPER uses C++20.
    
    	std::thread signallingThread([&] { signallingActor->tell<CallerEnvironment::ANYWHERE>(1); });
    
    
    	// TODO: Remove this once we use std::jthread when EMPER uses C++20.
    	signallingThread.join();
    }