[core] allow self closing mailbox/actor

This commit is contained in:
Ivo van Dongen
2017-05-25 09:42:48 +03:00
committed by Ivo van Dongen
parent f0d0e7423b
commit b608d85db7
3 changed files with 36 additions and 3 deletions

View File

@@ -15,7 +15,8 @@ void Mailbox::close() {
// must not block send(). Of the two, the receiving mutex must be acquired first, because that is
// the order that an actor will obtain them when it self-sends a message, and consistent lock
// acquisition order prevents deadlocks.
std::lock_guard<std::mutex> receivingLock(receivingMutex);
// The receiving mutex is recursive to allow a mailbox (and thus the actor) to close itself.
std::lock_guard<std::recursive_mutex> receivingLock(receivingMutex);
std::lock_guard<std::mutex> pushingLock(pushingMutex);
closed = true;
@@ -37,7 +38,7 @@ void Mailbox::push(std::unique_ptr<Message> message) {
}
void Mailbox::receive() {
std::lock_guard<std::mutex> receivingLock(receivingMutex);
std::lock_guard<std::recursive_mutex> receivingLock(receivingMutex);
if (closed) {
return;