thread/Util: throw exception on error
This commit is contained in:
parent
5598826eaf
commit
12091fcfb1
@ -40,6 +40,8 @@
|
|||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -597,12 +599,13 @@ AudioOutput::Task()
|
|||||||
{
|
{
|
||||||
FormatThreadName("output:%s", name);
|
FormatThreadName("output:%s", name);
|
||||||
|
|
||||||
Error error;
|
try {
|
||||||
if(!SetThreadRealtime(error)) {
|
SetThreadRealtime();
|
||||||
LogError(error);
|
} catch (const std::runtime_error &e) {
|
||||||
LogWarning(output_domain,
|
LogError(e,
|
||||||
"OutputThread could not get realtime scheduling, continuing anyway");
|
"OutputThread could not get realtime scheduling, continuing anyway");
|
||||||
}
|
}
|
||||||
|
|
||||||
SetThreadTimerSlackUS(100);
|
SetThreadTimerSlackUS(100);
|
||||||
|
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
|
@ -27,9 +27,8 @@
|
|||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "Util.hxx"
|
#include "Util.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "system/Error.hxx"
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
@ -77,8 +76,8 @@ SetThreadIdlePriority()
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
void
|
||||||
SetThreadRealtime(Error& error)
|
SetThreadRealtime()
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
struct sched_param sched_param;
|
struct sched_param sched_param;
|
||||||
@ -89,13 +88,7 @@ SetThreadRealtime(Error& error)
|
|||||||
policy |= SCHED_RESET_ON_FORK;
|
policy |= SCHED_RESET_ON_FORK;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(sched_setscheduler(0, policy, &sched_param)==0) {
|
if (sched_setscheduler(0, policy, &sched_param) < 0)
|
||||||
return true;
|
throw MakeErrno("sched_setscheduler failed");
|
||||||
} else {
|
|
||||||
error.FormatErrno("sched_setscheduler failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return true; // on non-linux systems, we pretend it worked
|
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
};
|
};
|
||||||
|
@ -30,8 +30,6 @@
|
|||||||
#ifndef THREAD_UTIL_HXX
|
#ifndef THREAD_UTIL_HXX
|
||||||
#define THREAD_UTIL_HXX
|
#define THREAD_UTIL_HXX
|
||||||
|
|
||||||
class Error;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lower the current thread's priority to "idle" (very low).
|
* Lower the current thread's priority to "idle" (very low).
|
||||||
*/
|
*/
|
||||||
@ -40,10 +38,10 @@ SetThreadIdlePriority();
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Raise the current thread's priority to "real-time" (very high).
|
* Raise the current thread's priority to "real-time" (very high).
|
||||||
* @param[out] error Receives error information on failure
|
*
|
||||||
* @return true on success (always true on non-linux systems)
|
* Throws std::system_error on error.
|
||||||
*/
|
*/
|
||||||
bool
|
void
|
||||||
SetThreadRealtime(Error &error);
|
SetThreadRealtime();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user