Merge "Fix NativeCallbackThread race condition." into oc-mr1-dev
am: 63643cedf2
Change-Id: I96d6ae526eac5c0e39057d4ae67765e63861f1f9
This commit is contained in:
@@ -274,6 +274,21 @@ public class RadioTunerTest {
|
|||||||
verify(mCallback, timeout(kTuneCallbackTimeoutMs)).onProgramInfoChanged(any());
|
verify(mCallback, timeout(kTuneCallbackTimeoutMs)).onProgramInfoChanged(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStepLoop() {
|
||||||
|
openTuner();
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
Log.d(TAG, "step loop iteration " + (i + 1));
|
||||||
|
|
||||||
|
int ret = mRadioTuner.step(RadioTuner.DIRECTION_DOWN, true);
|
||||||
|
assertEquals(RadioManager.STATUS_OK, ret);
|
||||||
|
verify(mCallback, timeout(kTuneCallbackTimeoutMs)).onProgramInfoChanged(any());
|
||||||
|
|
||||||
|
resetCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTuneAndGetPI() {
|
public void testTuneAndGetPI() {
|
||||||
openTuner();
|
openTuner();
|
||||||
|
|||||||
@@ -48,15 +48,19 @@ void NativeCallbackThread::threadLoop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!mExiting) {
|
while (true) {
|
||||||
ALOGV("Waiting for task...");
|
|
||||||
Task task;
|
Task task;
|
||||||
{
|
{
|
||||||
unique_lock<mutex> lk(mQueueMutex);
|
unique_lock<mutex> lk(mQueueMutex);
|
||||||
mQueueCond.wait(lk);
|
|
||||||
if (mExiting) break;
|
|
||||||
|
|
||||||
if (mQueue.empty()) continue;
|
if (mExiting) break;
|
||||||
|
if (mQueue.empty()) {
|
||||||
|
ALOGV("Waiting for task...");
|
||||||
|
mQueueCond.wait(lk);
|
||||||
|
if (mExiting) break;
|
||||||
|
if (mQueue.empty()) continue;
|
||||||
|
}
|
||||||
|
|
||||||
task = mQueue.front();
|
task = mQueue.front();
|
||||||
mQueue.pop();
|
mQueue.pop();
|
||||||
}
|
}
|
||||||
@@ -74,6 +78,7 @@ void NativeCallbackThread::threadLoop() {
|
|||||||
ALOGE_IF(res != JNI_OK, "Couldn't detach thread");
|
ALOGE_IF(res != JNI_OK, "Couldn't detach thread");
|
||||||
|
|
||||||
ALOGV("Native callback thread %p finished", this);
|
ALOGV("Native callback thread %p finished", this);
|
||||||
|
ALOGD_IF(!mQueue.empty(), "Skipped execution of %zu tasks", mQueue.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeCallbackThread::enqueue(const Task &task) {
|
void NativeCallbackThread::enqueue(const Task &task) {
|
||||||
@@ -84,6 +89,7 @@ void NativeCallbackThread::enqueue(const Task &task) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ALOGV("Adding task to the queue...");
|
||||||
mQueue.push(task);
|
mQueue.push(task);
|
||||||
mQueueCond.notify_one();
|
mQueueCond.notify_one();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user