diff options
author | Chih-Chung Chang <chihchung@google.com> | 2009-06-24 19:59:31 +0800 |
---|---|---|
committer | Chih-Chung Chang <chihchung@google.com> | 2009-06-25 11:03:55 +0800 |
commit | d2d6bc7552ee88063c0c26cffed87624e8aac478 (patch) | |
tree | 37d9656e830a9debdb26ad32a99fc1cba719bac5 | |
parent | c8be159ba67931ae38c552fc7b9da6084ca5a60a (diff) | |
download | frameworks_native-d2d6bc7552ee88063c0c26cffed87624e8aac478.zip frameworks_native-d2d6bc7552ee88063c0c26cffed87624e8aac478.tar.gz frameworks_native-d2d6bc7552ee88063c0c26cffed87624e8aac478.tar.bz2 |
Only remove client after the hardware is teared down, so a new client
is rejected before old client is done.
Also check mUsers in all cases to make sure there are no existing client.
-rw-r--r-- | camera/libcameraservice/CameraService.cpp | 20 | ||||
-rw-r--r-- | camera/libcameraservice/CameraService.h | 2 |
2 files changed, 11 insertions, 11 deletions
diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp index e945056..105d4d2 100644 --- a/camera/libcameraservice/CameraService.cpp +++ b/camera/libcameraservice/CameraService.cpp @@ -98,7 +98,7 @@ sp<ICamera> CameraService::connect(const sp<ICameraClient>& cameraClient) LOGD("CameraService::connect E (pid %d, client %p)", callingPid, cameraClient->asBinder().get()); - Mutex::Autolock lock(mLock); + Mutex::Autolock lock(mServiceLock); sp<Client> client; if (mClient != 0) { sp<Client> currentClient = mClient.promote(); @@ -125,13 +125,14 @@ sp<ICamera> CameraService::connect(const sp<ICameraClient>& cameraClient) LOGD("New client (pid %d) connecting, old reference was dangling...", callingPid); mClient.clear(); - if (mUsers > 0) { - LOGD("Still have client, rejected"); - return client; - } } } + if (mUsers > 0) { + LOGD("Still have client, rejected"); + return client; + } + // create a new Client object client = new Client(this, cameraClient, callingPid); mClient = client; @@ -152,7 +153,7 @@ void CameraService::removeClient(const sp<ICameraClient>& cameraClient) // destructor won't be called with the lock held. sp<Client> client; - Mutex::Autolock lock(mLock); + Mutex::Autolock lock(mServiceLock); if (mClient == 0) { // This happens when we have already disconnected. @@ -390,8 +391,6 @@ void CameraService::Client::disconnect() // from the user directly, or called by the destructor. if (mHardware == 0) return; - mCameraService->removeClient(mCameraClient); - LOGD("hardware teardown"); // Before destroying mHardware, we must make sure it's in the // idle state. @@ -402,6 +401,7 @@ void CameraService::Client::disconnect() mHardware->release(); mHardware.clear(); + mCameraService->removeClient(mCameraClient); mCameraService->decUsers(); LOGD("Client::disconnect() X (pid %d)", callingPid); @@ -661,7 +661,7 @@ sp<CameraService::Client> CameraService::Client::getClientFromCookie(void* user) sp<Client> client = 0; CameraService *service = static_cast<CameraService*>(user); if (service != NULL) { - Mutex::Autolock ourLock(service->mLock); + Mutex::Autolock ourLock(service->mServiceLock); if (service->mClient != 0) { client = service->mClient.promote(); if (client == 0) { @@ -1104,7 +1104,7 @@ status_t CameraService::dump(int fd, const Vector<String16>& args) result.append(buffer); write(fd, result.string(), result.size()); } else { - AutoMutex lock(&mLock); + AutoMutex lock(&mServiceLock); if (mClient != 0) { sp<Client> currentClient = mClient.promote(); sprintf(buffer, "Client (%p) PID: %d\n", diff --git a/camera/libcameraservice/CameraService.h b/camera/libcameraservice/CameraService.h index 729e539..8b8b54c 100644 --- a/camera/libcameraservice/CameraService.h +++ b/camera/libcameraservice/CameraService.h @@ -199,7 +199,7 @@ private: virtual void incUsers(); virtual void decUsers(); - mutable Mutex mLock; + mutable Mutex mServiceLock; wp<Client> mClient; #if DEBUG_HEAP_LEAKS |