synchronized (mLock) {
// If this thread has the file, nothing to do.
if (mOwnerThread == Thread.currentThread()) {
return mFile;
}
// Another thread wants file ask for a release.
if (mOwnerThread != null && mOnReleaseRequestCallback != null) {
mOnReleaseRequestCallback.onReleaseRequested(mFile);
}
// Wait until the file is released.
while (mOwnerThread != null) {
try {
mLock.wait();
} catch (InterruptedException ie) {
/* ignore */
}
}
// Update the owner and the callback.
mOwnerThread = Thread.currentThread();
mOnReleaseRequestCallback = callback;
if (DEBUG) {
Log.i(LOG_TAG, "Acquired file: " + mFile + " by thread: " + mOwnerThread);
}
return mFile;
}