<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - pa_mainloop_quit() can't make pa_mainloop_run exit"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=56735#c15">Comment # 15</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - pa_mainloop_quit() can't make pa_mainloop_run exit"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=56735">bug 56735</a>
              from <span class="vcard"><a class="email" href="mailto:tanuk@iki.fi" title="Tanu Kaskinen <tanuk@iki.fi>"> <span class="fn">Tanu Kaskinen</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=56735#c14">comment #14</a>)
<span class="quote">> (In reply to <a href="show_bug.cgi?id=56735#c13">comment #13</a>)
> > (In reply to <a href="show_bug.cgi?id=56735#c12">comment #12</a>)
> > [...]
> > > Thanks for your advise.
> > > I have considered using threaded-mainloop, but there's one thing made me
> > > give up.
> > > My program is a real-time recording program, other threads are set to RT
> > > thread.
> > > There isn't an API of threaded-mainloop to set it to run as a RT thread.
> > [...]
> > 
> > You can do this in the context state callback before you actually connect
> > the stream, which is well before the audio work actually begins.

> I think the best way to do so, is to send a special message, for example
> "quit", to m->wakeup_pipe[1], in the poll function, when this special
> message is received, m->quit is set to true, then poll quit cleanly.

> In this model, pa_mainloop_quit() just "tells" pa_mainloop_run() to quit,
> the former API won't modify any private data of PaMainloop.</span >

I'm not very enthusiastic about doing this.

<span class="quote">> B.T.W signal handler is not elegant to make mainloop quit. it's just a hack
> method.</span >

Did you consider Arun's suggestion of using pa_threaded_mainloop and setting up
the scheduling from the context state callback?

Signals certainly are an ugly way to implement the wakeup (I'm assuming that by
"signal handler" you're talking about the same stuff that "man 2 signal" is
talking about). Luckily, that isn't necessary, even if you don't use
pa_threaded_mainloop. I'll answer your earlier question:

(In reply to <a href="show_bug.cgi?id=56735#c10">comment #10</a>)
<span class="quote">> How to create an IO event to quit pa_mainloop_run() ?
> Can you give me some example codes?

> I designed my program based on the callback mechanism of pa_mainloop, so I
> didn't use threaded-mainloop.</span >

pa_mainloop *mainloop = pa_mainloop_new();
pa_mainloop_api *mainloop_api = pa_mainloop_get_api(mainloop);
int pipefds[2] = { -1, -1 };
pipe(pipefds);
pa_io_event *quit_event = mainloop_api->io_new(pipefds[0], PA_IO_EVENT_INPUT,
quit_event_cb, userdata);

Now you can write() to pipefds[1] from any thread, and quit_event_cb() will get
called in the thread where the mainloop runs.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>