Loading media/mtp/MtpFfsHandle.cpp +7 −13 Original line number Diff line number Diff line Loading @@ -297,9 +297,10 @@ int MtpFfsHandle::start(bool ptp) { } void MtpFfsHandle::close() { auto timeout = std::chrono::seconds(2); std::unique_lock lk(m); cv.wait_for(lk, timeout ,[this]{return child_threads==0;}); // Join all child threads before destruction for (auto& thread : mChildThreads) { thread.join(); } io_destroy(mCtx); closeEndpoints(); Loading Loading @@ -677,12 +678,10 @@ int MtpFfsHandle::sendEvent(mtp_event me) { memcpy(temp, me.data, me.length); me.data = temp; std::unique_lock lk(m); child_threads++; lk.unlock(); std::thread t([this, me]() { return this->doSendEvent(me); }); t.detach(); // Store the thread object for later joining mChildThreads.emplace_back(std::move(t)); return 0; } Loading @@ -692,11 +691,6 @@ void MtpFfsHandle::doSendEvent(mtp_event me) { if (static_cast<unsigned>(ret) != length) PLOG(ERROR) << "Mtp error sending event thread!"; delete[] reinterpret_cast<char*>(me.data); std::unique_lock lk(m); child_threads--; lk.unlock(); cv.notify_one(); } } // namespace android Loading media/mtp/MtpFfsHandle.h +1 −3 Original line number Diff line number Diff line Loading @@ -60,9 +60,7 @@ protected: bool mCanceled; bool mBatchCancel; std::mutex m; std::condition_variable cv; std::atomic<int> child_threads{0}; std::vector<std::thread> mChildThreads; android::base::unique_fd mControl; // "in" from the host's perspective => sink for mtp server Loading Loading
media/mtp/MtpFfsHandle.cpp +7 −13 Original line number Diff line number Diff line Loading @@ -297,9 +297,10 @@ int MtpFfsHandle::start(bool ptp) { } void MtpFfsHandle::close() { auto timeout = std::chrono::seconds(2); std::unique_lock lk(m); cv.wait_for(lk, timeout ,[this]{return child_threads==0;}); // Join all child threads before destruction for (auto& thread : mChildThreads) { thread.join(); } io_destroy(mCtx); closeEndpoints(); Loading Loading @@ -677,12 +678,10 @@ int MtpFfsHandle::sendEvent(mtp_event me) { memcpy(temp, me.data, me.length); me.data = temp; std::unique_lock lk(m); child_threads++; lk.unlock(); std::thread t([this, me]() { return this->doSendEvent(me); }); t.detach(); // Store the thread object for later joining mChildThreads.emplace_back(std::move(t)); return 0; } Loading @@ -692,11 +691,6 @@ void MtpFfsHandle::doSendEvent(mtp_event me) { if (static_cast<unsigned>(ret) != length) PLOG(ERROR) << "Mtp error sending event thread!"; delete[] reinterpret_cast<char*>(me.data); std::unique_lock lk(m); child_threads--; lk.unlock(); cv.notify_one(); } } // namespace android Loading
media/mtp/MtpFfsHandle.h +1 −3 Original line number Diff line number Diff line Loading @@ -60,9 +60,7 @@ protected: bool mCanceled; bool mBatchCancel; std::mutex m; std::condition_variable cv; std::atomic<int> child_threads{0}; std::vector<std::thread> mChildThreads; android::base::unique_fd mControl; // "in" from the host's perspective => sink for mtp server Loading