Skip to content

Commit

Permalink
Thread/*: add noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed May 3, 2019
1 parent 4cfb651 commit 6412cdf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
10 changes: 5 additions & 5 deletions src/Thread/CriticalSection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
18 changes: 9 additions & 9 deletions src/Thread/Mutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Mutex {
#if defined(HAVE_POSIX) && defined(NDEBUG) && defined(__GLIBC__)
constexpr
#endif
Mutex()
Mutex() noexcept
#ifndef NDEBUG
:locked(false)
#endif
Expand All @@ -88,7 +88,7 @@ class Mutex {
/**
* Deletes the Mutex
*/
~Mutex() {
~Mutex() noexcept {
assert(!locked);
}
#endif
Expand All @@ -101,7 +101,7 @@ class Mutex {
* in optimised builds.
*/
gcc_pure
bool IsLockedByCurrent() const {
bool IsLockedByCurrent() const noexcept {
debug_mutex.lock();
bool result = locked && owner.IsInside();
debug_mutex.unlock();
Expand Down Expand Up @@ -137,7 +137,7 @@ class Mutex {
/**
* Tries to lock the Mutex
*/
bool try_lock() {
bool try_lock() noexcept {
if (!mutex.try_lock()) {
#ifndef NDEBUG
assert(!IsLockedByCurrent());
Expand Down Expand Up @@ -179,11 +179,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();
}

Expand All @@ -202,15 +202,15 @@ class TemporaryUnlock {
Mutex &mutex;

public:
TemporaryUnlock(Mutex &_mutex):mutex(_mutex) {
TemporaryUnlock(Mutex &_mutex) noexcept:mutex(_mutex) {
mutex.debug_mutex.lock();
assert(mutex.locked);
assert(mutex.owner.IsInside());
mutex.locked = false;
mutex.debug_mutex.unlock();
}

~TemporaryUnlock() {
~TemporaryUnlock() noexcept {
mutex.debug_mutex.lock();
assert(!mutex.locked);
mutex.owner = ThreadHandle::GetCurrent();
Expand All @@ -219,7 +219,7 @@ class TemporaryUnlock {
}
#else
public:
constexpr TemporaryUnlock(Mutex &_mutex) {}
constexpr TemporaryUnlock(Mutex &_mutex) noexcept {}
#endif

TemporaryUnlock(const TemporaryUnlock &other) = delete;
Expand Down
20 changes: 10 additions & 10 deletions src/Thread/PosixCond.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2015 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2009-2015 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -44,40 +44,40 @@ 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

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);
}

void wait(Mutex &mutex) {
void wait(Mutex &mutex) noexcept {
TemporaryUnlock unlock(mutex);
wait(mutex.mutex);
}

bool timed_wait(PosixMutex &mutex, unsigned timeout_ms) {
bool timed_wait(PosixMutex &mutex, unsigned timeout_ms) noexcept {
struct timeval now;
gettimeofday(&now, nullptr);

Expand All @@ -93,7 +93,7 @@ public:
return pthread_cond_timedwait(&cond, &mutex.mutex, &ts) == 0;
}

bool timed_wait(Mutex &mutex, unsigned timeout_ms) {
bool timed_wait(Mutex &mutex, unsigned timeout_ms) noexcept {
TemporaryUnlock unlock(mutex);
return timed_wait(mutex.mutex, timeout_ms);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Thread/PosixMutex.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,31 @@ public:
#ifdef __GLIBC__
/* optimized constexpr constructor for pthread implementations
that support it */
constexpr PosixMutex():mutex(PTHREAD_MUTEX_INITIALIZER) {}
constexpr PosixMutex() noexcept:mutex(PTHREAD_MUTEX_INITIALIZER) {}
#else
/* slow fallback for pthread implementations that are not
compatible with "constexpr" */
PosixMutex() {
PosixMutex() noexcept {
pthread_mutex_init(&mutex, nullptr);
}

~PosixMutex() {
~PosixMutex() noexcept {
pthread_mutex_destroy(&mutex);
}
#endif

PosixMutex(const PosixMutex &other) = delete;
PosixMutex &operator=(const PosixMutex &other) = delete;

void lock() {
void lock() noexcept {
pthread_mutex_lock(&mutex);
}

bool try_lock() {
bool try_lock() noexcept {
return pthread_mutex_trylock(&mutex) == 0;
}

void unlock() {
void unlock() noexcept {
pthread_mutex_unlock(&mutex);
}
};
Expand Down
16 changes: 8 additions & 8 deletions src/Thread/WindowsCond.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2013 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2009-2019 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -40,36 +40,36 @@ 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);
}

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);
}

bool timed_wait(Mutex &mutex, unsigned timeout_ms) {
bool timed_wait(Mutex &mutex, unsigned timeout_ms) noexcept {
TemporaryUnlock unlock(mutex);
return timed_wait(mutex.mutex, timeout_ms);
}

void wait(CriticalSection &mutex) {
void wait(CriticalSection &mutex) noexcept {
timed_wait(mutex, INFINITE);
}

void wait(Mutex &mutex) {
void wait(Mutex &mutex) noexcept {
TemporaryUnlock unlock(mutex);
wait(mutex.mutex);
}
Expand Down

0 comments on commit 6412cdf

Please sign in to comment.