Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ad71fd5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "audio: Fix handling of a thread exit command with a bad cookie" into main am: 759fb986

parents 0e660316 759fb986
Loading
Loading
Loading
Loading
+18 −12
Original line number Original line Diff line number Diff line
@@ -180,17 +180,20 @@ StreamInWorkerLogic::Status StreamInWorkerLogic::cycle() {
    StreamDescriptor::Reply reply{};
    StreamDescriptor::Reply reply{};
    reply.status = STATUS_BAD_VALUE;
    reply.status = STATUS_BAD_VALUE;
    switch (command.getTag()) {
    switch (command.getTag()) {
        case Tag::halReservedExit:
        case Tag::halReservedExit: {
            if (const int32_t cookie = command.get<Tag::halReservedExit>();
            const int32_t cookie = command.get<Tag::halReservedExit>();
                cookie == (mContext->getInternalCommandCookie() ^ getTid())) {
            if (cookie == (mContext->getInternalCommandCookie() ^ getTid())) {
                mDriver->shutdown();
                mDriver->shutdown();
                setClosed();
                setClosed();
                // This is an internal command, no need to reply.
                return Status::EXIT;
            } else {
            } else {
                LOG(WARNING) << __func__ << ": EXIT command has a bad cookie: " << cookie;
                LOG(WARNING) << __func__ << ": EXIT command has a bad cookie: " << cookie;
            }
            }
            if (cookie != 0) {  // This is an internal command, no need to reply.
                return Status::EXIT;
            } else {
                break;
                break;
            }
        }
        case Tag::getStatus:
        case Tag::getStatus:
            populateReply(&reply, mIsConnected);
            populateReply(&reply, mIsConnected);
            break;
            break;
@@ -400,17 +403,20 @@ StreamOutWorkerLogic::Status StreamOutWorkerLogic::cycle() {
    reply.status = STATUS_BAD_VALUE;
    reply.status = STATUS_BAD_VALUE;
    using Tag = StreamDescriptor::Command::Tag;
    using Tag = StreamDescriptor::Command::Tag;
    switch (command.getTag()) {
    switch (command.getTag()) {
        case Tag::halReservedExit:
        case Tag::halReservedExit: {
            if (const int32_t cookie = command.get<Tag::halReservedExit>();
            const int32_t cookie = command.get<Tag::halReservedExit>();
                cookie == (mContext->getInternalCommandCookie() ^ getTid())) {
            if (cookie == (mContext->getInternalCommandCookie() ^ getTid())) {
                mDriver->shutdown();
                mDriver->shutdown();
                setClosed();
                setClosed();
                // This is an internal command, no need to reply.
                return Status::EXIT;
            } else {
            } else {
                LOG(WARNING) << __func__ << ": EXIT command has a bad cookie: " << cookie;
                LOG(WARNING) << __func__ << ": EXIT command has a bad cookie: " << cookie;
            }
            }
            if (cookie != 0) {  // This is an internal command, no need to reply.
                return Status::EXIT;
            } else {
                break;
                break;
            }
        }
        case Tag::getStatus:
        case Tag::getStatus:
            populateReply(&reply, mIsConnected);
            populateReply(&reply, mIsConnected);
            break;
            break;
+1 −1
Original line number Original line Diff line number Diff line
@@ -90,7 +90,7 @@ class StreamContext {
                  std::weak_ptr<sounddose::StreamDataProcessorInterface> streamDataProcessor,
                  std::weak_ptr<sounddose::StreamDataProcessorInterface> streamDataProcessor,
                  DebugParameters debugParameters)
                  DebugParameters debugParameters)
        : mCommandMQ(std::move(commandMQ)),
        : mCommandMQ(std::move(commandMQ)),
          mInternalCommandCookie(std::rand()),
          mInternalCommandCookie(std::rand() | 1 /* make sure it's not 0 */),
          mReplyMQ(std::move(replyMQ)),
          mReplyMQ(std::move(replyMQ)),
          mFormat(format),
          mFormat(format),
          mChannelLayout(channelLayout),
          mChannelLayout(channelLayout),