Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audio: Add setup method and add reference counter on shutdown #11799

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SPRESENSE
Copy link
Contributor

Summary

Add an 'setup' method on the 'struct audio_ops_s' to notify to the driver that the related device file has been opened and is ready for use.
And also add refcount argument on shutdown method to know how many device file is still opened.

Impact

Audio drivers

Testing

Build check

Add an 'setup' method on the 'struct audio_ops_s' to notify to the
driver that the related device file has been opened and is ready
for use.
And also add refcount argument on shutdown method to know how many
device file is still opened.

if (lower && lower->ops && lower->ops->setup)
{
ret = lower->ops->setup(lower, tmp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cold we call setup only when cref equals 1?

Copy link
Contributor Author

@SPRESENSE SPRESENSE Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe few lower drivers want to know how many users are exists.
So I think this should be kept, how do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you give an example?

@@ -223,7 +235,7 @@ static int audio_close(FAR struct file *filep)
DEBUGASSERT(lower->ops->shutdown != NULL);
audinfo("calling shutdown\n");

lower->ops->shutdown(lower);
lower->ops->shutdown(lower, upper->crefs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's call shutdown when the last reference close and drop opencnt from shutdown prototype

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shutdown is called not only close method, but also SHUTDOWN ioctl, so I think it should be kept.

@@ -534,6 +536,10 @@ typedef CODE void (*audio_callback_t)(FAR void *priv, uint16_t reason,
struct audio_lowerhalf_s;
struct audio_ops_s
{
/* This method is called when the related device file is opened. */

CODE int (*setup)(FAR struct audio_lowerhalf_s *dev, int opencnt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move the new callback to last to keep the source code compatibility, and revert the change from the individual driver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I agree.
I will modify.

@@ -2698,7 +2699,7 @@ static int cxd56_getcaps(struct audio_lowerhalf_s *lower, int type,
*
****************************************************************************/

static int cxd56_shutdown(struct audio_lowerhalf_s *lower)
static int cxd56_shutdown(struct audio_lowerhalf_s *lower, int opencnt)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the commit message you said "refcount" but here you used "opencnt" and in the classd_shutdown() you used only "cnt". I think it is a good idea to use just a single name here.

@acassis
Copy link
Contributor

acassis commented Mar 10, 2024

Please rebase to fix the CI issue, also fix the suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants