mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2024-12-31 23:15:43 +00:00
parent
bef0df2f0b
commit
c81fe43ac0
|
@ -381,7 +381,7 @@ struct SoundIo {
|
|||
/// a message instructing the user how to configure their system to allow
|
||||
/// real-time priority threads. This must be set to a function not NULL.
|
||||
/// To silence the warning, assign this to a function that does nothing.
|
||||
void (*emit_rtprio_warning)(void);
|
||||
void (*emit_rtprio_warning)(struct SoundIo *);
|
||||
|
||||
/// Optional: JACK info callback.
|
||||
/// By default, libsoundio sets this to an empty function in order to
|
||||
|
@ -389,6 +389,9 @@ struct SoundIo {
|
|||
/// setting this to `NULL` or providing your own function. This is
|
||||
/// registered with JACK regardless of whether ::soundio_connect_backend
|
||||
/// succeeds.
|
||||
/// These functions are called globally from JACK and there is not a way
|
||||
/// to provide access to the SoundIo instance. For more details, see
|
||||
/// https://github.com/jackaudio/jack2/issues/235
|
||||
void (*jack_info_callback)(const char *msg);
|
||||
/// Optional: JACK error callback.
|
||||
/// See SoundIo::jack_info_callback
|
||||
|
|
|
@ -1447,7 +1447,7 @@ static enum SoundIoError outstream_start_alsa(struct SoundIoPrivate *si, struct
|
|||
|
||||
enum SoundIoError err;
|
||||
SOUNDIO_ATOMIC_FLAG_TEST_AND_SET(osa->thread_exit_flag);
|
||||
if ((err = soundio_os_thread_create(outstream_thread_run, os, soundio->emit_rtprio_warning, &osa->thread)))
|
||||
if ((err = soundio_os_thread_create(outstream_thread_run, os, soundio, &osa->thread)))
|
||||
return err;
|
||||
|
||||
return 0;
|
||||
|
@ -1749,7 +1749,7 @@ static enum SoundIoError instream_start_alsa(struct SoundIoPrivate *si, struct S
|
|||
|
||||
SOUNDIO_ATOMIC_FLAG_TEST_AND_SET(isa->thread_exit_flag);
|
||||
enum SoundIoError err;
|
||||
if ((err = soundio_os_thread_create(instream_thread_run, is, soundio->emit_rtprio_warning, &isa->thread))) {
|
||||
if ((err = soundio_os_thread_create(instream_thread_run, is, soundio, &isa->thread))) {
|
||||
instream_destroy_alsa(si, is);
|
||||
return err;
|
||||
}
|
||||
|
|
12
src/dummy.c
12
src/dummy.c
|
@ -219,10 +219,8 @@ static enum SoundIoError outstream_start_dummy(struct SoundIoPrivate *si, struct
|
|||
struct SoundIo *soundio = &si->pub;
|
||||
assert(!osd->thread);
|
||||
SOUNDIO_ATOMIC_FLAG_TEST_AND_SET(osd->abort_flag);
|
||||
int err;
|
||||
if ((err = soundio_os_thread_create(playback_thread_run, os,
|
||||
soundio->emit_rtprio_warning, &osd->thread)))
|
||||
{
|
||||
enum SoundIoError err;
|
||||
if ((err = soundio_os_thread_create(playback_thread_run, os, soundio, &osd->thread))) {
|
||||
return err;
|
||||
}
|
||||
return SoundIoErrorNone;
|
||||
|
@ -334,10 +332,8 @@ static enum SoundIoError instream_start_dummy(struct SoundIoPrivate *si, struct
|
|||
struct SoundIo *soundio = &si->pub;
|
||||
assert(!isd->thread);
|
||||
SOUNDIO_ATOMIC_FLAG_TEST_AND_SET(isd->abort_flag);
|
||||
int err;
|
||||
if ((err = soundio_os_thread_create(capture_thread_run, is,
|
||||
soundio->emit_rtprio_warning, &isd->thread)))
|
||||
{
|
||||
enum SoundIoError err;
|
||||
if ((err = soundio_os_thread_create(capture_thread_run, is, soundio, &isd->thread))) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
|
|
14
src/os.c
14
src/os.c
|
@ -186,8 +186,8 @@ static void *run_pthread(void *userdata) {
|
|||
|
||||
int soundio_os_thread_create(
|
||||
void (*run)(void *arg), void *arg,
|
||||
void (*emit_rtprio_warning)(void),
|
||||
struct SoundIoOsThread ** out_thread)
|
||||
struct SoundIo *soundio,
|
||||
struct SoundIoOsThread **out_thread)
|
||||
{
|
||||
*out_thread = NULL;
|
||||
|
||||
|
@ -206,9 +206,9 @@ int soundio_os_thread_create(
|
|||
soundio_os_thread_destroy(thread);
|
||||
return SoundIoErrorSystemResources;
|
||||
}
|
||||
if (emit_rtprio_warning) {
|
||||
if (soundio) {
|
||||
if (!SetThreadPriority(thread->handle, THREAD_PRIORITY_TIME_CRITICAL)) {
|
||||
emit_rtprio_warning();
|
||||
soundio->emit_rtprio_warning(soundio);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
@ -219,7 +219,7 @@ int soundio_os_thread_create(
|
|||
}
|
||||
thread->attr_init = true;
|
||||
|
||||
if (emit_rtprio_warning) {
|
||||
if (soundio) {
|
||||
int max_priority = sched_get_priority_max(SCHED_FIFO);
|
||||
if (max_priority == -1) {
|
||||
soundio_os_thread_destroy(thread);
|
||||
|
@ -241,8 +241,8 @@ int soundio_os_thread_create(
|
|||
}
|
||||
|
||||
if ((err = pthread_create(&thread->id, &thread->attr, run_pthread, thread))) {
|
||||
if (err == EPERM && emit_rtprio_warning) {
|
||||
emit_rtprio_warning();
|
||||
if (err == EPERM && soundio) {
|
||||
soundio->emit_rtprio_warning(soundio);
|
||||
err = pthread_create(&thread->id, NULL, run_pthread, thread);
|
||||
}
|
||||
if (err) {
|
||||
|
|
5
src/os.h
5
src/os.h
|
@ -19,10 +19,11 @@ int soundio_os_init(void);
|
|||
double soundio_os_get_time(void);
|
||||
|
||||
struct SoundIoOsThread;
|
||||
struct SoundIo;
|
||||
int soundio_os_thread_create(
|
||||
void (*run)(void *arg), void *arg,
|
||||
void (*emit_rtprio_warning)(void),
|
||||
struct SoundIoOsThread ** out_thread);
|
||||
struct SoundIo *soundio, // pass NULL to disable real time priority
|
||||
struct SoundIoOsThread **out_thread);
|
||||
|
||||
void soundio_os_thread_destroy(struct SoundIoOsThread *thread);
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ static void default_backend_disconnect_cb(struct SoundIo *soundio, enum SoundIoE
|
|||
}
|
||||
|
||||
static struct SoundIoAtomicFlag rtprio_seen = SOUNDIO_ATOMIC_FLAG_INIT;
|
||||
static void default_emit_rtprio_warning(void) {
|
||||
static void default_emit_rtprio_warning(struct SoundIo *soundio) {
|
||||
if (!SOUNDIO_ATOMIC_FLAG_TEST_AND_SET(rtprio_seen)) {
|
||||
fprintf(stderr, "warning: unable to set high priority thread: Operation not permitted\n");
|
||||
fprintf(stderr, "See "
|
||||
|
|
Loading…
Reference in a new issue