data-loop: use new thread interface

This commit is contained in:
Wim Taymans 2021-07-05 10:10:36 +02:00
parent bfa3c6c137
commit 6b73d49780
2 changed files with 11 additions and 9 deletions

View file

@ -29,6 +29,7 @@
#include "pipewire/log.h" #include "pipewire/log.h"
#include "pipewire/data-loop.h" #include "pipewire/data-loop.h"
#include "pipewire/private.h" #include "pipewire/private.h"
#include "pipewire/thread.h"
#define NAME "data-loop" #define NAME "data-loop"
@ -203,13 +204,15 @@ SPA_EXPORT
int pw_data_loop_start(struct pw_data_loop *loop) int pw_data_loop_start(struct pw_data_loop *loop)
{ {
if (!loop->running) { if (!loop->running) {
int err; struct pw_thread *thr;
loop->running = true; loop->running = true;
if ((err = pthread_create(&loop->thread, NULL, do_loop, loop)) != 0) { thr = pw_thread_utils_create(NULL, do_loop, loop);
pw_log_error(NAME" %p: can't create thread: %s", loop, strerror(err)); loop->thread = (pthread_t)thr;
if (thr == NULL) {
pw_log_error(NAME" %p: can't create thread: %m", loop);
loop->running = false; loop->running = false;
return -err; return -errno;
} }
} }
return 0; return 0;
@ -235,7 +238,7 @@ int pw_data_loop_stop(struct pw_data_loop *loop)
pthread_cancel(loop->thread); pthread_cancel(loop->thread);
} }
pw_log_debug(NAME": %p join", loop); pw_log_debug(NAME": %p join", loop);
pthread_join(loop->thread, NULL); pw_thread_utils_join((struct pw_thread*)loop->thread, NULL);
pw_log_debug(NAME": %p joined", loop); pw_log_debug(NAME": %p joined", loop);
} }
pw_log_debug(NAME": %p stopped", loop); pw_log_debug(NAME": %p stopped", loop);
@ -260,9 +263,9 @@ bool pw_data_loop_in_thread(struct pw_data_loop * loop)
* On posix based systems this returns a pthread_t * * On posix based systems this returns a pthread_t *
*/ */
SPA_EXPORT SPA_EXPORT
void *pw_data_loop_get_thread(struct pw_data_loop * loop) struct pw_thread *pw_data_loop_get_thread(struct pw_data_loop * loop)
{ {
return loop->running ? &loop->thread : NULL; return loop->running ? (struct pw_thread*)loop->thread : NULL;
} }
SPA_EXPORT SPA_EXPORT

View file

@ -86,9 +86,8 @@ int pw_data_loop_stop(struct pw_data_loop *loop);
/** Check if the current thread is the processing thread */ /** Check if the current thread is the processing thread */
bool pw_data_loop_in_thread(struct pw_data_loop *loop); bool pw_data_loop_in_thread(struct pw_data_loop *loop);
/** Get the thread object */ /** Get the thread object */
void *pw_data_loop_get_thread(struct pw_data_loop *loop); struct pw_thread *pw_data_loop_get_thread(struct pw_data_loop *loop);
/** invoke func in the context of the thread or in the caller thread when /** invoke func in the context of the thread or in the caller thread when
* the loop is not running. Since 0.3.3 */ * the loop is not running. Since 0.3.3 */