Skip to content

Commit

Permalink
Update dispatch examples
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipjohnston committed Nov 2, 2018
1 parent 6049ade commit b38155a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions examples/cpp/dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ dispatch_queue::dispatch_queue(std::string name, size_t thread_cnt) :

for(size_t i = 0; i < threads_.size(); i++)
{
threads_[i] = std::thread(
std::bind(&dispatch_queue::dispatch_thread_handler, this));
threads_[i] = std::thread(&dispatch_queue::dispatch_thread_handler, this);
}
}

Expand All @@ -55,7 +54,9 @@ dispatch_queue::~dispatch_queue()
printf("Destructor: Destroying dispatch threads...\n");

// Signal to dispatch threads that it's time to wrap up
std::unique_lock<std::mutex> lock(lock_);
quit_ = true;
lock.unlock();
cv_.notify_all();

// Wait for threads to finish before we exit
Expand Down Expand Up @@ -102,7 +103,7 @@ void dispatch_queue::dispatch_thread_handler(void)
});

//after wait, we own the lock
if(q_.size() && !quit_)
if(!quit_ && q_.size())
{
auto op = std::move(q_.front());
q_.pop();
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/dispatch_freertos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void dispatch_queue::dispatch_thread_handler(void)

do {
//after wait, we own the lock
if(q_.size() && !quit_)
if(!quit_ && q_.size())
{
auto op = std::move(q_.front());
q_.pop();
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/dispatch_threadx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void dispatch_queue::dispatch_thread_handler(void)

do {
//after wait, we own the lock
if(q_.size() && !quit_)
if(!quit_ && q_.size())
{
auto op = std::move(q_.front());
q_.pop();
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/dispatch_threadx_stdmutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void dispatch_queue::dispatch_thread_handler(void)

do {
//after wait, we own the lock
if(q_.size() && !quit_)
if(!quit_ && q_.size())
{
auto op = std::move(q_.front());
q_.pop();
Expand Down

0 comments on commit b38155a

Please sign in to comment.