diff options
author | alk3pInjection <webmaster@raspii.tech> | 2023-10-13 00:52:15 +0800 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2023-10-13 00:52:15 +0800 |
commit | c7d0a1b674cd4be54c46ad9da1f4c5e9976ef172 (patch) | |
tree | cef9a2a59f57c4c69c6f15662b6b086f8b494205 /media/mtp/MtpFfsHandle.cpp | |
parent | ccf5222c7b1a73a295ca17ec48ae07f36f80a4ce (diff) | |
parent | 1d9991659370204c83b8560bdc721b3c1e07485a (diff) |
Merge tag 'LA.QSSI.13.0.r1-11900-qssi.0' into tachibana-mr1tachibana-mr1
"LA.QSSI.13.0.r1-11900-qssi.0"
Change-Id: I83e77f2b1162311920ba7b553a5eecfa4cd933fb
Diffstat (limited to 'media/mtp/MtpFfsHandle.cpp')
-rw-r--r-- | media/mtp/MtpFfsHandle.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/media/mtp/MtpFfsHandle.cpp b/media/mtp/MtpFfsHandle.cpp index 2ffd7759e0..ef8c9aa789 100644 --- a/media/mtp/MtpFfsHandle.cpp +++ b/media/mtp/MtpFfsHandle.cpp @@ -297,6 +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;}); + io_destroy(mCtx); closeEndpoints(); closeConfig(); @@ -669,6 +673,11 @@ int MtpFfsHandle::sendEvent(mtp_event me) { char *temp = new char[me.length]; 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(); return 0; @@ -680,6 +689,11 @@ 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 |