Skip to content

Commit

Permalink
Merge pull request #2383 from bitshares/network-inventory-advertise
Browse files Browse the repository at this point in the history
Use concurrent_unordered_set for _new_inventory
  • Loading branch information
abitmore authored Mar 17, 2021
2 parents c1fa635 + 46d9bb0 commit 9f94e65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libraries/net/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ namespace graphene { namespace net { namespace detail {
dlog("beginning an iteration of advertise inventory");
// swap inventory into local variable, clearing the node's copy
std::unordered_set<item_id> inventory_to_advertise;
inventory_to_advertise.swap(_new_inventory);
_new_inventory.swap( inventory_to_advertise );

// process all inventory to advertise and construct the inventory messages we'll send
// first, then send them all in a batch (to avoid any fiber interruption points while
Expand Down
13 changes: 10 additions & 3 deletions libraries/net/node_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public:
fc::scoped_lock<fc::mutex> lock(mux);
return std::unordered_set<Key, Hash, Pred>::erase( key );
}
// swap
void swap( typename std::unordered_set<Key, Hash, Pred>& other ) noexcept
{
fc::scoped_lock<fc::mutex> lock(mux);
std::unordered_set<Key, Hash, Pred>::swap( other );
}
// iteration
typename std::unordered_set<Key, Hash, Pred>::iterator begin() noexcept
{
Expand Down Expand Up @@ -335,11 +341,12 @@ class node_impl : public peer_connection_delegate
// @}

/// used by the task that advertises inventory during normal operation
// @{
/// @{
fc::promise<void>::ptr _retrigger_advertise_inventory_loop_promise;
fc::future<void> _advertise_inventory_loop_done;
std::unordered_set<item_id> _new_inventory; /// list of items we have received but not yet advertised to our peers
// @}
/// list of items we have received but not yet advertised to our peers
concurrent_unordered_set<item_id> _new_inventory;
/// @}

fc::future<void> _terminate_inactive_connections_loop_done;
uint8_t _recent_block_interval_in_seconds; // a cached copy of the block interval, to avoid a thread hop to the blockchain to get the current value
Expand Down

0 comments on commit 9f94e65

Please sign in to comment.