mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:50:18 +00:00
Fix external camera HAL crashes
External USB camera hal service crashes when disconnecting the camera. ExternalCameraDeviceSession's desctructor is called and deletes mLock, but mBufferRequestThread is still running and waiting on the same mLock, which causes the "pthread_mutex_lock called on a destroyed mutex" error. Fix the issue by stopping the thread in destructor. Also refactors the functions and remove unused conditions. Bug: 289741662 Test: Test with USB camera Change-Id: I06b1ff6e192a4bca16822785d65d68a6aae53414
This commit is contained in:
@@ -224,10 +224,6 @@ void ExternalCameraDeviceSession::initOutputThread() {
|
||||
}
|
||||
|
||||
void ExternalCameraDeviceSession::closeOutputThread() {
|
||||
closeOutputThreadImpl();
|
||||
}
|
||||
|
||||
void ExternalCameraDeviceSession::closeOutputThreadImpl() {
|
||||
if (mOutputThread != nullptr) {
|
||||
mOutputThread->flush();
|
||||
mOutputThread->requestExitAndWait();
|
||||
@@ -235,6 +231,13 @@ void ExternalCameraDeviceSession::closeOutputThreadImpl() {
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCameraDeviceSession::closeBufferRequestThread() {
|
||||
if (mBufferRequestThread != nullptr) {
|
||||
mBufferRequestThread->requestExitAndWait();
|
||||
mBufferRequestThread.reset();
|
||||
}
|
||||
}
|
||||
|
||||
Status ExternalCameraDeviceSession::initStatus() const {
|
||||
Mutex::Autolock _l(mLock);
|
||||
Status status = Status::OK;
|
||||
@@ -248,7 +251,7 @@ Status ExternalCameraDeviceSession::initStatus() const {
|
||||
ExternalCameraDeviceSession::~ExternalCameraDeviceSession() {
|
||||
if (!isClosed()) {
|
||||
ALOGE("ExternalCameraDeviceSession deleted before close!");
|
||||
close(/*callerIsDtor*/ true);
|
||||
closeImpl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1411,19 +1414,16 @@ Status ExternalCameraDeviceSession::importBufferLocked(int32_t streamId, uint64_
|
||||
}
|
||||
|
||||
ScopedAStatus ExternalCameraDeviceSession::close() {
|
||||
close(false);
|
||||
closeImpl();
|
||||
return fromStatus(Status::OK);
|
||||
}
|
||||
|
||||
void ExternalCameraDeviceSession::close(bool callerIsDtor) {
|
||||
void ExternalCameraDeviceSession::closeImpl() {
|
||||
Mutex::Autolock _il(mInterfaceLock);
|
||||
bool closed = isClosed();
|
||||
if (!closed) {
|
||||
if (callerIsDtor) {
|
||||
closeOutputThreadImpl();
|
||||
} else {
|
||||
closeOutputThread();
|
||||
}
|
||||
closeOutputThread();
|
||||
closeBufferRequestThread();
|
||||
|
||||
Mutex::Autolock _l(mLock);
|
||||
// free all buffers
|
||||
|
||||
Reference in New Issue
Block a user