Skip to content

Commit

Permalink
clean up exception throwing behavior in TFdManagedThread
Browse files Browse the repository at this point in the history
  • Loading branch information
dspeterson committed Nov 5, 2015
1 parent ba984c5 commit 88f69ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/thread/fd_managed_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void TFdManagedThread::Start() {
assert(this);

if (OptThread.IsKnown()) {
THROW_ERROR(TThreadAlreadyStarted);
throw std::logic_error("Worker thread is already started");
}

assert(!ShutdownRequestedSem.GetFd().IsReadable());
Expand All @@ -71,7 +71,8 @@ void TFdManagedThread::RequestShutdown() {
assert(this);

if (OptThread.IsUnknown()) {
THROW_ERROR(TThreadAlreadyShutDown);
throw std::logic_error(
"Cannot request shutdown on nonexistent worker thread");
}

ShutdownRequestedSem.Push();
Expand All @@ -86,7 +87,7 @@ void TFdManagedThread::Join() {
assert(this);

if (OptThread.IsUnknown()) {
THROW_ERROR(TCannotJoinNonexistentThread);
throw std::logic_error("Cannot join nonexistent worker thread");
}

ShutdownFinishedSem.Pop();
Expand Down
9 changes: 0 additions & 9 deletions src/thread/fd_managed_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,9 @@ namespace Thread {
NO_COPY_SEMANTICS(TFdManagedThread);

public:
DEFINE_ERROR(TThreadAlreadyStarted, std::runtime_error,
"Worker thread is already started");

DEFINE_ERROR(TThreadAlreadyShutDown, std::runtime_error,
"Cannot request shutdown on nonexistent worker thread");

DEFINE_ERROR(TThreadThrewUnknownException, std::runtime_error,
"Worker thread threw unknown exception");

DEFINE_ERROR(TCannotJoinNonexistentThread, std::runtime_error,
"Cannot join nonexistent worker thread");

class TThreadThrewStdException final : public std::runtime_error {
public:
TThreadThrewStdException(const char *what_msg)
Expand Down
20 changes: 10 additions & 10 deletions src/thread/fd_managed_thread.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace {

try {
worker.Join();
} catch (const TFdManagedThread::TThreadThrewStdException &x) {
} catch (const TFdManagedThread::TThreadThrewStdException &) {
threw = true;
}

Expand All @@ -220,7 +220,7 @@ namespace {

try {
worker.Join();
} catch (const TFdManagedThread::TThreadThrewStdException &x) {
} catch (const TFdManagedThread::TThreadThrewStdException &) {
threw = true;
}

Expand All @@ -243,7 +243,7 @@ namespace {

try {
worker.Join();
} catch (const TFdManagedThread::TThreadThrewUnknownException &x) {
} catch (const TFdManagedThread::TThreadThrewUnknownException &) {
threw = true;
}

Expand All @@ -263,7 +263,7 @@ namespace {

try {
worker.Join();
} catch (const TFdManagedThread::TThreadThrewUnknownException &x) {
} catch (const TFdManagedThread::TThreadThrewUnknownException &) {
threw = true;
}

Expand All @@ -280,8 +280,8 @@ namespace {

try {
worker.Start();
} catch (const TFdManagedThread::TThreadAlreadyStarted &x) {
threw = true;
} catch (const std::logic_error &) {
threw = true; // worker already started
}

ASSERT_TRUE(threw);
Expand All @@ -296,17 +296,17 @@ namespace {

try {
worker.Join();
} catch (const TFdManagedThread::TCannotJoinNonexistentThread &x) {
threw = true;
} catch (const std::logic_error &) {
threw = true; // cannot join nonexistent thread
}

ASSERT_TRUE(threw);
threw = false;

try {
worker.RequestShutdown();
} catch (const TFdManagedThread::TThreadAlreadyShutDown &x) {
threw = true;
} catch (const std::logic_error &) {
threw = true; // worker already shut down
}

ASSERT_TRUE(threw);
Expand Down

0 comments on commit 88f69ff

Please sign in to comment.