Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[concurrent-blocking-queue-fix] ConcurrentBlockingQueue::Pop's return… #2

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/common/concurrent_blocking_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template<typename T> class ConcurrentBlockingQueue {
queue_.pop_front();
if (queue_.empty())
has_elmt_ = false;
return false;
return true;
}
}
{
Expand All @@ -44,9 +44,9 @@ template<typename T> class ConcurrentBlockingQueue {
queue_.pop_front();
if (queue_.empty())
has_elmt_ = false;
return false;
return true;
} else {
return true;
return false;
}
}
}
Expand Down
45 changes: 0 additions & 45 deletions src/common/spin_lock.h

This file was deleted.

44 changes: 44 additions & 0 deletions src/common/spinlock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef MXNET_COMMON_SPINLOCK_H_
#define MXNET_COMMON_SPINLOCK_H_

#include <atomic>

namespace mxnet {
namespace common {

/*!
* \brief Simple userspace spinlock implementation.
*/
class Spinlock {
public:
Spinlock() = default;
/*!
* \brief Disable copy and move.
*/
Spinlock(Spinlock const&) = delete;
Spinlock(Spinlock&&) = delete;
Spinlock& operator=(Spinlock const&) = delete;
Spinlock& operator=(Spinlock&&) = delete;
~Spinlock() = default;
/*!
* \brief Acquire lock.
*/
void lock() noexcept {
while (lock_.test_and_set(std::memory_order_acquire));
}
/*!
* \brief Release lock.
*/
void unlock() noexcept {
lock_.clear(std::memory_order_release);
}

private:
std::atomic_flag lock_ = ATOMIC_FLAG_INIT;
};

} // namespace common
} // namespace mxnet

#endif // MXNET_COMMON_SPINLOCK_H_

2 changes: 1 addition & 1 deletion src/dag_engine/threaded_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ThreadedEngine : public DAGEngine {
}
void WorkerRoutine(int thrid) {
OpDescr* opd = nullptr;
while(! worker_queues_[thrid]->Pop(opd)) {
while(worker_queues_[thrid]->Pop(opd)) {
LOG(INFO) << "worker thread #" << thrid << " got operator " << opd;
opd->op(GetRunContext(opd->exec_ctx), [this, opd] () { this->OnOpFinished(opd); });
opd = nullptr;
Expand Down