OSDN Git Service

ToneGenerator: fix stop/destroy concurrency
authorEric Laurent <elaurent@google.com>
Tue, 26 Mar 2013 23:37:19 +0000 (16:37 -0700)
committerEric Laurent <elaurent@google.com>
Tue, 26 Mar 2013 23:37:19 +0000 (16:37 -0700)
commit09108adeca8cbbf3fbb21f8aea2a2ff250db9531
tree79b462bdab5220f96b077cc656a5a579df9ac344
parent6386b50b67185a966d43ee761acdfe7add569d10
ToneGenerator: fix stop/destroy concurrency

There is a problem if the stopTone() method is called
from two different threads (for instance if the destructor is called
while stopTone() is waiting for the audio callback to finish).

In this case, the second call to stopTone() will not wait for the
condition to be signaled and call clearWaveGens() while the callback
can still be active, thus causing a crash.

There is a similar problem in case of concurrent calls to startTone()
and stopTone().

The fix consists in making sure that stopTone() always waits for call
back completion or timeout and exits before calling clearWaveGens()
if a concurrent start request is detected.

Bug 8163071

Change-Id: I9ddb4390407701dcad5bf83660fd9903f0d72268
media/libmedia/ToneGenerator.cpp