mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2025-07-22 22:38:44 +00:00
os: make sure tv_nsec is less than 1,000,000,000
This commit is contained in:
parent
e587851048
commit
60b731ab4f
|
@ -57,6 +57,12 @@ int main(int argc, char **argv) {
|
||||||
soundio_output_device_create(device, SoundIoSampleFormatFloat, 0.1, NULL,
|
soundio_output_device_create(device, SoundIoSampleFormatFloat, 0.1, NULL,
|
||||||
write_callback, underrun_callback, &output_device);
|
write_callback, underrun_callback, &output_device);
|
||||||
|
|
||||||
|
if ((err = soundio_output_device_start(output_device)))
|
||||||
|
panic("unable to start device: %s", soundio_error_string(err));
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
soundio_wait_events(soundio);
|
||||||
|
|
||||||
soundio_output_device_destroy(output_device);
|
soundio_output_device_destroy(output_device);
|
||||||
soundio_device_unref(device);
|
soundio_device_unref(device);
|
||||||
soundio_destroy(soundio);
|
soundio_destroy(soundio);
|
||||||
|
|
16
src/os.cpp
16
src/os.cpp
|
@ -229,6 +229,12 @@ int soundio_os_thread_create(
|
||||||
soundio_os_thread_destroy(thread);
|
soundio_os_thread_destroy(thread);
|
||||||
return SoundIoErrorSystemResources;
|
return SoundIoErrorSystemResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((err = pthread_attr_setschedpolicy(&thread->attr, SCHED_FIFO))) {
|
||||||
|
soundio_os_thread_destroy(thread);
|
||||||
|
return SoundIoErrorSystemResources;
|
||||||
|
}
|
||||||
|
|
||||||
struct sched_param param;
|
struct sched_param param;
|
||||||
param.sched_priority = max_priority;
|
param.sched_priority = max_priority;
|
||||||
if ((err = pthread_attr_setschedparam(&thread->attr, ¶m))) {
|
if ((err = pthread_attr_setschedparam(&thread->attr, ¶m))) {
|
||||||
|
@ -236,10 +242,6 @@ int soundio_os_thread_create(
|
||||||
return SoundIoErrorSystemResources;
|
return SoundIoErrorSystemResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = pthread_attr_setschedpolicy(&thread->attr, SCHED_FIFO))) {
|
|
||||||
soundio_os_thread_destroy(thread);
|
|
||||||
return SoundIoErrorSystemResources;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = pthread_create(&thread->id, &thread->attr, run_pthread, thread))) {
|
if ((err = pthread_create(&thread->id, &thread->attr, run_pthread, thread))) {
|
||||||
|
@ -478,19 +480,21 @@ void soundio_os_cond_timed_wait(struct SoundIoOsCond *cond,
|
||||||
target_mutex = &locked_mutex->id;
|
target_mutex = &locked_mutex->id;
|
||||||
} else {
|
} else {
|
||||||
target_mutex = &cond->default_mutex_id;
|
target_mutex = &cond->default_mutex_id;
|
||||||
assert_no_err(pthread_mutex_lock(&cond->default_mutex_id));
|
assert_no_err(pthread_mutex_lock(target_mutex));
|
||||||
}
|
}
|
||||||
// this time is absolute
|
// this time is absolute
|
||||||
struct timespec tms;
|
struct timespec tms;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &tms);
|
clock_gettime(CLOCK_MONOTONIC, &tms);
|
||||||
tms.tv_nsec += (seconds * 1000000000L);
|
tms.tv_nsec += (seconds * 1000000000L);
|
||||||
|
tms.tv_sec += tms.tv_nsec / 1000000000L;
|
||||||
|
tms.tv_nsec = tms.tv_nsec % 1000000000L;
|
||||||
int err;
|
int err;
|
||||||
if ((err = pthread_cond_timedwait(&cond->id, target_mutex, &tms))) {
|
if ((err = pthread_cond_timedwait(&cond->id, target_mutex, &tms))) {
|
||||||
assert(err != EPERM);
|
assert(err != EPERM);
|
||||||
assert(err != EINVAL);
|
assert(err != EINVAL);
|
||||||
}
|
}
|
||||||
if (!locked_mutex)
|
if (!locked_mutex)
|
||||||
assert_no_err(pthread_mutex_unlock(&cond->default_mutex_id));
|
assert_no_err(pthread_mutex_unlock(target_mutex));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,8 @@ void soundio_destroy(struct SoundIo *soundio) {
|
||||||
destroy(soundio);
|
destroy(soundio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void default_on_devices_change(struct SoundIo *) { }
|
||||||
|
|
||||||
struct SoundIo * soundio_create(void) {
|
struct SoundIo * soundio_create(void) {
|
||||||
soundio_os_init();
|
soundio_os_init();
|
||||||
struct SoundIo *soundio = create<SoundIo>();
|
struct SoundIo *soundio = create<SoundIo>();
|
||||||
|
@ -82,6 +84,7 @@ struct SoundIo * soundio_create(void) {
|
||||||
soundio_destroy(soundio);
|
soundio_destroy(soundio);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
soundio->on_devices_change = default_on_devices_change;
|
||||||
return soundio;
|
return soundio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,3 +322,8 @@ void soundio_output_device_destroy(SoundIoOutputDevice *output_device) {
|
||||||
soundio_device_unref(output_device->device);
|
soundio_device_unref(output_device->device);
|
||||||
destroy(output_device);
|
destroy(output_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int soundio_output_device_start(struct SoundIoOutputDevice *output_device) {
|
||||||
|
SoundIo *soundio = output_device->device->soundio;
|
||||||
|
return soundio->output_device_start(soundio, output_device);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue