diff --git a/src/thread/CriticalSection.hxx b/src/thread/CriticalSection.hxx index eb3f5c5fe..1a55d3aca 100644 --- a/src/thread/CriticalSection.hxx +++ b/src/thread/CriticalSection.hxx @@ -41,26 +41,26 @@ class CriticalSection { CRITICAL_SECTION critical_section; public: - CriticalSection() { + CriticalSection() noexcept { ::InitializeCriticalSection(&critical_section); } - ~CriticalSection() { + ~CriticalSection() noexcept { ::DeleteCriticalSection(&critical_section); } CriticalSection(const CriticalSection &other) = delete; CriticalSection &operator=(const CriticalSection &other) = delete; - void lock() { + void lock() noexcept { ::EnterCriticalSection(&critical_section); }; - bool try_lock() { + bool try_lock() noexcept { return ::TryEnterCriticalSection(&critical_section) != 0; }; - void unlock() { + void unlock() noexcept { ::LeaveCriticalSection(&critical_section); } }; diff --git a/src/thread/Id.hxx b/src/thread/Id.hxx index 4b0b9109e..217a39e72 100644 --- a/src/thread/Id.hxx +++ b/src/thread/Id.hxx @@ -44,12 +44,12 @@ public: /** * No initialisation. */ - ThreadId() = default; + ThreadId() noexcept = default; #ifdef WIN32 - constexpr ThreadId(DWORD _id):id(_id) {} + constexpr ThreadId(DWORD _id) noexcept:id(_id) {} #else - constexpr ThreadId(pthread_t _id):id(_id) {} + constexpr ThreadId(pthread_t _id) noexcept:id(_id) {} #endif gcc_const diff --git a/src/thread/Mutex.hxx b/src/thread/Mutex.hxx index f3064387c..530ff9697 100644 --- a/src/thread/Mutex.hxx +++ b/src/thread/Mutex.hxx @@ -52,11 +52,11 @@ class ScopeUnlock { Mutex &mutex; public: - explicit ScopeUnlock(Mutex &_mutex):mutex(_mutex) { + explicit ScopeUnlock(Mutex &_mutex) noexcept:mutex(_mutex) { mutex.unlock(); }; - ~ScopeUnlock() { + ~ScopeUnlock() noexcept { mutex.lock(); } diff --git a/src/thread/Name.hxx b/src/thread/Name.hxx index 20560bfbb..70dbd59c2 100644 --- a/src/thread/Name.hxx +++ b/src/thread/Name.hxx @@ -35,7 +35,7 @@ #endif static inline void -SetThreadName(const char *name) +SetThreadName(const char *name) noexcept { #if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__NetBSD__) /* not using pthread_setname_np() on NetBSD because it @@ -56,7 +56,7 @@ SetThreadName(const char *name) template static inline void -FormatThreadName(const char *fmt, gcc_unused Args&&... args) +FormatThreadName(const char *fmt, gcc_unused Args&&... args) noexcept { #ifdef HAVE_THREAD_NAME char buffer[16]; diff --git a/src/thread/PosixCond.hxx b/src/thread/PosixCond.hxx index 7da71df38..e1c272071 100644 --- a/src/thread/PosixCond.hxx +++ b/src/thread/PosixCond.hxx @@ -46,15 +46,15 @@ public: #ifdef __GLIBC__ /* optimized constexpr constructor for pthread implementations that support it */ - constexpr PosixCond():cond(PTHREAD_COND_INITIALIZER) {} + constexpr PosixCond() noexcept:cond(PTHREAD_COND_INITIALIZER) {} #else /* slow fallback for pthread implementations that are not compatible with "constexpr" */ - PosixCond() { + PosixCond() noexcept { pthread_cond_init(&cond, nullptr); } - ~PosixCond() { + ~PosixCond() noexcept { pthread_cond_destroy(&cond); } #endif @@ -62,20 +62,20 @@ public: PosixCond(const PosixCond &other) = delete; PosixCond &operator=(const PosixCond &other) = delete; - void signal() { + void signal() noexcept { pthread_cond_signal(&cond); } - void broadcast() { + void broadcast() noexcept { pthread_cond_broadcast(&cond); } - void wait(PosixMutex &mutex) { + void wait(PosixMutex &mutex) noexcept { pthread_cond_wait(&cond, &mutex.mutex); } private: - bool timed_wait(PosixMutex &mutex, unsigned timeout_ms) { + bool timed_wait(PosixMutex &mutex, unsigned timeout_ms) noexcept { struct timeval now; gettimeofday(&now, nullptr); @@ -93,7 +93,7 @@ private: public: bool timed_wait(PosixMutex &mutex, - std::chrono::steady_clock::duration timeout) { + std::chrono::steady_clock::duration timeout) noexcept { auto timeout_ms = std::chrono::duration_cast(timeout).count(); if (timeout_ms < 0) timeout_ms = 0; diff --git a/src/thread/Slack.hxx b/src/thread/Slack.hxx index 1234e1fe9..d1bb49c1e 100644 --- a/src/thread/Slack.hxx +++ b/src/thread/Slack.hxx @@ -30,7 +30,7 @@ * merge multiple wakeups, which is a trick to save energy. */ static inline void -SetThreadTimerSlackNS(unsigned long slack_ns) +SetThreadTimerSlackNS(unsigned long slack_ns) noexcept { #if defined(HAVE_PRCTL) && defined(PR_SET_TIMERSLACK) prctl(PR_SET_TIMERSLACK, slack_ns, 0, 0, 0); @@ -40,13 +40,13 @@ SetThreadTimerSlackNS(unsigned long slack_ns) } static inline void -SetThreadTimerSlackUS(unsigned long slack_us) +SetThreadTimerSlackUS(unsigned long slack_us) noexcept { SetThreadTimerSlackNS(slack_us * 1000ul); } static inline void -SetThreadTimerSlackMS(unsigned long slack_ms) +SetThreadTimerSlackMS(unsigned long slack_ms) noexcept { SetThreadTimerSlackNS(slack_ms * 1000000ul); } diff --git a/src/thread/Thread.cxx b/src/thread/Thread.cxx index 69b7333bf..3b6da667d 100644 --- a/src/thread/Thread.cxx +++ b/src/thread/Thread.cxx @@ -56,7 +56,7 @@ Thread::Start() } void -Thread::Join() +Thread::Join() noexcept { assert(IsDefined()); assert(!IsInside()); @@ -72,7 +72,7 @@ Thread::Join() } inline void -Thread::Run() +Thread::Run() noexcept { #ifndef WIN32 #ifndef NDEBUG @@ -94,7 +94,7 @@ Thread::Run() #ifdef WIN32 DWORD WINAPI -Thread::ThreadProc(LPVOID ctx) +Thread::ThreadProc(LPVOID ctx) noexcept { Thread &thread = *(Thread *)ctx; @@ -105,7 +105,7 @@ Thread::ThreadProc(LPVOID ctx) #else void * -Thread::ThreadProc(void *ctx) +Thread::ThreadProc(void *ctx) noexcept { Thread &thread = *(Thread *)ctx; diff --git a/src/thread/Thread.hxx b/src/thread/Thread.hxx index 0251f46ec..cbf3310d0 100644 --- a/src/thread/Thread.hxx +++ b/src/thread/Thread.hxx @@ -54,19 +54,19 @@ class Thread { #endif public: - explicit Thread(Function _f):f(_f) {} + explicit Thread(Function _f) noexcept:f(_f) {} Thread(const Thread &) = delete; #ifndef NDEBUG - ~Thread() { + ~Thread() noexcept { /* all Thread objects must be destructed manually by calling Join(), to clean up */ assert(!IsDefined()); } #endif - bool IsDefined() const { + bool IsDefined() const noexcept { #ifdef WIN32 return handle != nullptr; #else @@ -91,15 +91,15 @@ public: } void Start(); - void Join(); + void Join() noexcept; private: - void Run(); + void Run() noexcept; #ifdef WIN32 - static DWORD WINAPI ThreadProc(LPVOID ctx); + static DWORD WINAPI ThreadProc(LPVOID ctx) noexcept; #else - static void *ThreadProc(void *ctx); + static void *ThreadProc(void *ctx) noexcept; #endif }; diff --git a/src/thread/Util.cxx b/src/thread/Util.cxx index 16fb1be7a..34c6b5380 100644 --- a/src/thread/Util.cxx +++ b/src/thread/Util.cxx @@ -41,13 +41,13 @@ #ifdef __linux__ static int -ioprio_set(int which, int who, int ioprio) +ioprio_set(int which, int who, int ioprio) noexcept { return syscall(__NR_ioprio_set, which, who, ioprio); } static void -ioprio_set_idle() +ioprio_set_idle() noexcept { static constexpr int _IOPRIO_WHO_PROCESS = 1; static constexpr int _IOPRIO_CLASS_IDLE = 3; @@ -61,7 +61,7 @@ ioprio_set_idle() #endif void -SetThreadIdlePriority() +SetThreadIdlePriority() noexcept { #ifdef __linux__ #ifdef SCHED_IDLE diff --git a/src/thread/Util.hxx b/src/thread/Util.hxx index ed5b91bde..ce1c0fbb4 100644 --- a/src/thread/Util.hxx +++ b/src/thread/Util.hxx @@ -34,7 +34,7 @@ * Lower the current thread's priority to "idle" (very low). */ void -SetThreadIdlePriority(); +SetThreadIdlePriority() noexcept; /** * Raise the current thread's priority to "real-time" (very high). diff --git a/src/thread/WindowsCond.hxx b/src/thread/WindowsCond.hxx index d01ee3a1d..108f38c81 100644 --- a/src/thread/WindowsCond.hxx +++ b/src/thread/WindowsCond.hxx @@ -41,35 +41,35 @@ class WindowsCond { CONDITION_VARIABLE cond; public: - WindowsCond() { + WindowsCond() noexcept { InitializeConditionVariable(&cond); } WindowsCond(const WindowsCond &other) = delete; WindowsCond &operator=(const WindowsCond &other) = delete; - void signal() { + void signal() noexcept { WakeConditionVariable(&cond); } - void broadcast() { + void broadcast() noexcept { WakeAllConditionVariable(&cond); } private: - bool timed_wait(CriticalSection &mutex, DWORD timeout_ms) { + bool timed_wait(CriticalSection &mutex, DWORD timeout_ms) noexcept { return SleepConditionVariableCS(&cond, &mutex.critical_section, timeout_ms); } public: bool timed_wait(CriticalSection &mutex, - std::chrono::steady_clock::duration timeout) { + std::chrono::steady_clock::duration timeout) noexcept { auto timeout_ms = std::chrono::duration_cast(timeout).count(); return timed_wait(mutex, timeout_ms); } - void wait(CriticalSection &mutex) { + void wait(CriticalSection &mutex) noexcept { timed_wait(mutex, INFINITE); } };