Skip to content

Commit

Permalink
[rpc] AsyncRPCOperation: std::move replaces assignment operator / old…
Browse files Browse the repository at this point in the history
… copy semantics
  • Loading branch information
ch4ot1c authored and Jon Layton committed Jul 15, 2018
1 parent c9e785d commit d1a02b0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
23 changes: 0 additions & 23 deletions src/asyncrpcoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,6 @@ AsyncRPCOperation::AsyncRPCOperation(std::shared_ptr<CWallet> const wallet) :
set_state(OperationStatus::READY);
}

AsyncRPCOperation::AsyncRPCOperation(const AsyncRPCOperation& o) :
m_pwallet(o.m_pwallet),
id_(o.id_), creation_time_(o.creation_time_), state_(o.state_.load()),
start_time_(o.start_time_), end_time_(o.end_time_),
error_code_(o.error_code_), error_message_(o.error_message_),
result_(o.result_)
{
}

AsyncRPCOperation& AsyncRPCOperation::operator=( const AsyncRPCOperation& other ) {
this->m_pwallet = other.m_pwallet;
this->id_ = other.id_;
this->creation_time_ = other.creation_time_;
this->state_.store(other.state_.load());
this->start_time_ = other.start_time_;
this->end_time_ = other.end_time_;
this->error_code_ = other.error_code_;
this->error_message_ = other.error_message_;
this->result_ = other.result_;
return *this;
}


AsyncRPCOperation::~AsyncRPCOperation() {
}

Expand Down
4 changes: 2 additions & 2 deletions src/asyncrpcoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class AsyncRPCOperation {
private:

// Derived classes should write their own copy constructor and assignment operators
AsyncRPCOperation(const AsyncRPCOperation& orig);
AsyncRPCOperation& operator=( const AsyncRPCOperation& other );
AsyncRPCOperation(const AsyncRPCOperation& orig) = delete;
AsyncRPCOperation& operator=(const AsyncRPCOperation& other) = delete;

// Initialized in the operation constructor, never to be modified again.
AsyncRPCOperationId id_;
Expand Down
10 changes: 5 additions & 5 deletions src/asyncrpcqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static std::atomic<size_t> workerCounter(0);
* Static method to return the shared/default queue.
*/
shared_ptr<AsyncRPCQueue> AsyncRPCQueue::sharedInstance() {
// Thread-safe in C+11 and gcc 4.3
// Thread-safe in C++11 and gcc 4.3
static shared_ptr<AsyncRPCQueue> q = std::make_shared<AsyncRPCQueue>();
return q;
}
Expand Down Expand Up @@ -56,7 +56,7 @@ void AsyncRPCQueue::run(size_t workerId) {
// Search operation map
AsyncRPCOperationMap::const_iterator iter = operation_map_.find(key);
if (iter != operation_map_.end()) {
operation = iter->second;
operation = std::move(iter->second);
}
}

Expand Down Expand Up @@ -104,7 +104,7 @@ std::shared_ptr<AsyncRPCOperation> AsyncRPCQueue::getOperationForId(AsyncRPCOper
std::lock_guard<std::mutex> guard(lock_);
AsyncRPCOperationMap::const_iterator iter = operation_map_.find(id);
if (iter != operation_map_.end()) {
ptr = iter->second;
ptr = std::move(iter->second);
}
return ptr;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ size_t AsyncRPCQueue::getOperationCount() const {
*/
void AsyncRPCQueue::addWorker() {
std::lock_guard<std::mutex> guard(lock_);
workers_.emplace_back( std::thread(&AsyncRPCQueue::run, this, ++workerCounter) );
workers_.emplace_back(std::thread(&AsyncRPCQueue::run, this, ++workerCounter));
}

/**
Expand All @@ -193,7 +193,7 @@ size_t AsyncRPCQueue::getNumberOfWorkers() const {
std::vector<AsyncRPCOperationId> AsyncRPCQueue::getAllOperationIds() const {
std::lock_guard<std::mutex> guard(lock_);
std::vector<AsyncRPCOperationId> v;
for(auto & entry: operation_map_) {
for (auto & entry : operation_map_) {
v.push_back(entry.first);
}
return v;
Expand Down
2 changes: 1 addition & 1 deletion src/asyncrpcqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <memory>


typedef std::unordered_map<AsyncRPCOperationId, std::shared_ptr<AsyncRPCOperation> > AsyncRPCOperationMap;
typedef std::unordered_map<AsyncRPCOperationId, std::shared_ptr<AsyncRPCOperation>> AsyncRPCOperationMap;


class AsyncRPCQueue {
Expand Down

0 comments on commit d1a02b0

Please sign in to comment.