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

Commit 559a766d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "audioflinger: Fix move semantics in PatchPanel"

parents eff70fa3 fa97d9b1
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -81,13 +81,16 @@ private:
    class Endpoint {
    public:
        Endpoint() = default;
        Endpoint(Endpoint&& other) { *this = std::move(other); }
        Endpoint& operator=(Endpoint&& other) {
        Endpoint(const Endpoint&) = delete;
        Endpoint& operator=(const Endpoint&) = delete;
        Endpoint(Endpoint&& other) noexcept { swap(other); }
        Endpoint& operator=(Endpoint&& other) noexcept {
            swap(other);
            return *this;
        }
        ~Endpoint() {
            ALOGE_IF(mHandle != AUDIO_PATCH_HANDLE_NONE,
                    "A non empty Patch Endpoint leaked, handle %d", mHandle);
            *this = other;
            other.mHandle = AUDIO_PATCH_HANDLE_NONE;
            return *this;
        }

        status_t checkTrack(TrackType *trackOrNull) const {
@@ -127,10 +130,19 @@ private:
        }
        void stopTrack() { if (mTrack) mTrack->stop(); }

    private:
        Endpoint(const Endpoint&) = default;
        Endpoint& operator=(const Endpoint&) = default;
        void swap(Endpoint &other) noexcept {
            using std::swap;
            swap(mThread, other.mThread);
            swap(mCloseThread, other.mCloseThread);
            swap(mHandle, other.mHandle);
            swap(mTrack, other.mTrack);
        }

        friend void swap(Endpoint &a, Endpoint &b) noexcept {
            a.swap(b);
        }

    private:
        sp<ThreadType> mThread;
        bool mCloseThread = true;
        audio_patch_handle_t mHandle = AUDIO_PATCH_HANDLE_NONE;