Skip to content

Commit

Permalink
comp: add comp_get_copy_limits with lock
Browse files Browse the repository at this point in the history
Typical use of existing comp_get_copy_limits() requires to lock
the buffers for the operation to ensure consistent readings.

Grouping the operations in a function simplifies the components
code. It also guarantees correct double lock with dedicated flags
and helps avoid a common bug in client code where single flags
variable is used for both locks. When both buffers are shared
between cores, and single variable is used, the rsil in second lock
returns int level 5 set by the first lock. Later, during unlocking
the original level returned by the first lock is not restored, the
dsp stays on level 5.

Signed-off-by: Marcin Maka <marcin.maka@linux.intel.com>
  • Loading branch information
Marcin Maka authored and lgirdwood committed Apr 7, 2020
1 parent f00c445 commit c94b070
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/include/sof/audio/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,31 @@ static inline void comp_overrun(struct comp_dev *dev, struct comp_buffer *sink,
void comp_get_copy_limits(struct comp_buffer *source, struct comp_buffer *sink,
struct comp_copy_limits *cl);

/**
* Version of comp_get_copy_limits that locks both buffers to guarantee
* consistent state readings.
*
* @param[in] source Source buffer.
* @param[in] sink Sink buffer
* @param[out] cl Current copy limits.
*/
static inline
void comp_get_copy_limits_with_lock(struct comp_buffer *source,
struct comp_buffer *sink,
struct comp_copy_limits *cl)
{
uint32_t source_flags = 0;
uint32_t sink_flags = 0;

buffer_lock(source, &source_flags);
buffer_lock(sink, &sink_flags);

comp_get_copy_limits(source, sink, cl);

buffer_unlock(sink, sink_flags);
buffer_unlock(source, source_flags);
}

/**
* Called by component in params() function in order to set and update some of
* downstream (playback) or upstream (capture) buffer parameters with pcm
Expand Down

0 comments on commit c94b070

Please sign in to comment.