[pulseaudio-tickets] [Bug 56735] pa_mainloop_quit() can't make pa_mainloop_run exit

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Sat Nov 24 08:12:01 PST 2012


https://bugs.freedesktop.org/show_bug.cgi?id=56735

--- Comment #15 from Tanu Kaskinen <tanuk at iki.fi> ---
(In reply to comment #14)
> (In reply to comment #13)
> > (In reply to comment #12)
> > [...]
> > > 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.

I'm not very enthusiastic about doing this.

> B.T.W signal handler is not elegant to make mainloop quit. it's just a hack
> method.

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 comment #10)
> 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.

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.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/pulseaudio-bugs/attachments/20121124/3b65aa8c/attachment.html>


More information about the pulseaudio-bugs mailing list