Skip to content

[Question] How is waiting managed for LINUX_ALSA thread? #464

@am00ma

Description

@am00ma

Hi,

I was looking through the code, as an example of how to use the alsa API, I was wondering where the waiting occurs as:

  1. The read, write functions are non blocking: result = snd_pcm_open(&phandle, name.c_str(), stream, openMode | SND_PCM_NONBLOCK);
  2. The callback handler is a tight loop:
    while (*isRunning == true)
    {
        pthread_testcancel();
        object->callbackEvent();
    }
  1. The only waiting is to handle stopping the stream:
    if (stream_.state == STREAM_STOPPED)
    {
        MUTEX_LOCK(&stream_.mutex);
        while (!apiInfo->runnable) pthread_cond_wait(&apiInfo->runnable_cv, &stream_.mutex);
        ...
    }
  1. There is no handling of EAGAIN, only EPIPE:
        if (result < (int)stream_.bufferSize)
        {
            // Either an error or overrun occurred.
            if (result == -EPIPE)
            {
                ...

Any insight would be much appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions