[core] Use an actor model for tile worker concurrency
This commit is contained in:
42
test/actor/actor_ref.cpp
Normal file
42
test/actor/actor_ref.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <mbgl/actor/actor.hpp>
|
||||
#include <mbgl/actor/thread_pool.hpp>
|
||||
|
||||
#include <mbgl/test/util.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
TEST(ActorRef, CanOutliveActor) {
|
||||
// An ActorRef can outlive its actor. Doing does not extend the actor's lifetime.
|
||||
// Sending a message to an ActorRef whose actor has died is a no-op.
|
||||
|
||||
struct Test {
|
||||
bool& died;
|
||||
|
||||
Test(ActorRef<Test>, bool& died_)
|
||||
: died(died_) {
|
||||
}
|
||||
|
||||
~Test() {
|
||||
died = true;
|
||||
}
|
||||
|
||||
void receive() {
|
||||
FAIL();
|
||||
}
|
||||
};
|
||||
|
||||
ThreadPool pool { 1 };
|
||||
bool died = false;
|
||||
|
||||
ActorRef<Test> test = [&] () {
|
||||
return Actor<Test>(pool, std::ref(died)).self();
|
||||
}();
|
||||
|
||||
EXPECT_TRUE(died);
|
||||
test.invoke(&Test::receive);
|
||||
}
|
||||
Reference in New Issue
Block a user