Skip to content

Commit

Permalink
Review edits.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sever Topan committed Mar 29, 2018
1 parent b60772e commit 15d0afd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 11 additions & 7 deletions include/thread_pool/rouser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Rouser final
/**
* @brief State An Enum representing the Rouser thread state.
*/
enum State
enum class State
{
Initialized,
Running,
Expand Down Expand Up @@ -71,9 +71,9 @@ class Rouser final

/**
* @brief start Create the executing thread and start tasks execution.
* @param workers A pointer to the vector containing sibling workers for performing round robin work stealing.
* @param idle_workers A pointer to the slotted bag containing all idle workers.
* @param num_busy_waiters A pointer to the atomic busy waiter counter.
* @param workers A reference to the vector containing sibling workers for performing round robin work stealing.
* @param idle_workers A reference to the slotted bag containing all idle workers.
* @param num_busy_waiters A reference to the atomic busy waiter counter.
* @note The parameters passed into this function generally relate to the global thread pool state.
*/
template <typename Task, template<typename> class Queue>
Expand All @@ -82,16 +82,18 @@ class Rouser final
/**
* @brief stop Stop all worker's thread and stealing activity.
* Waits until the executing thread becomes finished.
* @note Stop may only be called once start() has been invoked.
* Repeated successful calls to stop() will be no-ops after the first.
*/
void stop();

private:

/**
* @brief threadFunc Executing thread function.
* @param workers A pointer to the vector containing sibling workers for performing round robin work stealing.
* @param idle_workers A pointer to the slotted bag containing all idle workers.
* @param num_busy_waiters A pointer to the atomic busy waiter counter.
* @param workers A reference to the vector containing sibling workers for performing round robin work stealing.
* @param idle_workers A reference to the slotted bag containing all idle workers.
* @param num_busy_waiters A reference to the atomic busy waiter counter.
*/
template <typename Task, template<typename> class Queue>
void threadFunc(std::vector<std::unique_ptr<Worker<Task, Queue>>>& workers, SlottedBag<Queue>& idle_workers, std::atomic<size_t>& num_busy_waiters);
Expand Down Expand Up @@ -144,6 +146,8 @@ inline void Rouser::stop()
auto expectedState = State::Running;
if (m_state.compare_exchange_strong(expectedState, State::Stopped, std::memory_order_acq_rel))
m_thread.join();
else if (expectedState == State::Initialized)
throw std::runtime_error("Cannot stop Rouser: stop may only be calld after the Rouser has been started.");
}

template <typename Task, template<typename> class Queue>
Expand Down
6 changes: 5 additions & 1 deletion include/thread_pool/worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Worker final
/**
* @brief State An Enum representing the Rouser thread state.
*/
enum State
enum class State
{
Initialized,
Running,
Expand Down Expand Up @@ -100,6 +100,8 @@ class Worker final
/**
* @brief stop Stop all worker's thread and stealing activity.
* Waits until the executing thread becomes finished.
* @note Stop may only be called once start() has been invoked.
* Repeated successful calls to stop() will be no-ops after the first.
*/
void stop();

Expand Down Expand Up @@ -245,6 +247,8 @@ inline void Worker<Task, Queue>::stop()
wake();
m_thread.join();
}
else if (expectedState == State::Initialized)
throw std::runtime_error("Cannot stop Worker: stop may only be calld after the Worker has been started.");
}

template <typename Task, template<typename> class Queue>
Expand Down

0 comments on commit 15d0afd

Please sign in to comment.