[alsa-devel] [PATCH 26/29] ALSA: oxfw: Add support AMDTP in-stream

Clemens Ladisch clemens at ladisch.de
Tue Nov 25 13:04:09 CET 2014


Takashi Sakamoto wrote:
> On Nov 24 2014 22:54, Clemens Ladisch wrote:
>> In theory, it would be possible to use atomic_t to synchronize multiple
>> streams, but this requires that
>> 1. two CPUs that start a stream at the same time do not both think they
>>    are the first, ... and
>> 2. when one CPU is still starting a stream, code on all other CPUs must
>>    be able to work correctly, without synchronization.  [...]
>
> If I rewrite your pseudo code, like this:
>
>>    void start_some_substream(...)
>>    {
>>        if (atomic_inc_and_test(substreams)) {
>>            mutex_lock();
>>            // lots of stuff to start DMA ...
>
>              if (wait_for_first_packet() == ETIMEDOUT) {
>                  stop_dma();
>                  release_streams();
>                  mutex_unlock();
>                  return ETIMEDOUT;
>              }
>>            mutex_unlock();
>>        }
>>        ...
>>    }

This is an even better example of why atomic_t is incorrect:  when the
startup fails, the second call to start_some_substream() at the same
time, which just sees that substreams>0, cannot notice the error, and
thinks its own substream has been started successfully.


Regards,
Clemens


More information about the Alsa-devel mailing list