thread-mainloop: Add API for running a callback unlocked

This adds API to allow clients to schedule a callback in the mainloop
thread without the mainloop lock being held. This is meant for a case
where the client might be dealing with locking its own objects in
addition to the mainloop thread itself. In this case, it might need ton
control the locking order of the two, to match the order in other
threads, as it might not always be able to allow for its objects to be
locked after the mainloop thread lock.
This commit is contained in:
Arun Raghavan 2019-03-12 12:08:08 +05:30 committed by Georg Chini
parent 824e685ac0
commit 363b1ae69c
4 changed files with 75 additions and 5 deletions

View file

@ -312,6 +312,16 @@ int pa_threaded_mainloop_in_thread(pa_threaded_mainloop *m);
/** Sets the name of the thread. \since 5.0 */
void pa_threaded_mainloop_set_name(pa_threaded_mainloop *m, const char *name);
/** Runs the given callback in the mainloop thread without the lock held. The
* caller is responsible for ensuring that PulseAudio data structures are only
* accessed in a thread-safe way (that is, APIs that take pa_context and
* pa_stream are not thread-safe, and should not accessed without some
* synchronisation). This is the only situation in which
* pa_threaded_mainloop_lock() and pa_threaded_mainloop_unlock() may be used
* in the mainloop thread context. \since 13.0 */
void pa_threaded_mainloop_once_unlocked(pa_threaded_mainloop *m, void (*callback)(pa_threaded_mainloop *m, void *userdata),
void *userdata);
PA_C_DECL_END
#endif