Skip to content

Commit

Permalink
bus: track the number of monitors
Browse files Browse the repository at this point in the history
If no monitors are installed (the expected case), skip driver_monitor() which
is moderately expensive and otherwise would be performed on every message,
even if it ends up being a noop.

Signed-off-by: Tom Gundersen <[email protected]>
  • Loading branch information
teg committed Jan 29, 2018
1 parent 7692572 commit dee3380
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bus/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct Bus {
MatchRegistry sender_matches;
PeerRegistry peers;

uint64_t n_monitors;
uint64_t transaction_ids;
uint64_t listener_ids;

Expand Down
5 changes: 5 additions & 0 deletions src/bus/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ static int driver_monitor(Bus *bus, Peer *sender, Message *message) {
NameOwnership *ownership;
int r;

if (!bus->n_monitors)
return 0;

filter.type = message->metadata.header.type;
filter.sender = sender ? sender->id : ADDRESS_ID_INVALID;
filter.interface = message->metadata.fields.interface;
Expand Down Expand Up @@ -1789,6 +1792,8 @@ int driver_goodbye(Peer *peer, bool silent) {
return error_trace(r);
}
peer_unregister(peer);
} else if (peer_is_monitor(peer)) {
peer_stop_monitor(peer);
}

c_list_for_each_entry_safe(rule, rule_safe, &peer->name_owner_changed_matches.rule_list, registry_link)
Expand Down
10 changes: 10 additions & 0 deletions src/bus/peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,20 @@ int peer_become_monitor(Peer *peer, MatchOwner *owned_matches) {
return poison;

peer->monitor = true;
++peer->bus->n_monitors;

return 0;
}

void peer_stop_monitor(Peer *peer) {
assert(!peer->registered);
assert(peer->monitor);
assert(c_rbtree_is_empty(&peer->owned_matches.rule_tree));

peer->monitor = false;
--peer->bus->n_monitors;
}

void peer_flush_matches(Peer *peer) {
CRBNode *node;

Expand Down
1 change: 1 addition & 0 deletions src/bus/peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void peer_release_name_ownership(Peer *peer, NameOwnership *ownership, NameChang
int peer_add_match(Peer *peer, const char *rule_string);
int peer_remove_match(Peer *peer, const char *rule_string);
int peer_become_monitor(Peer *peer, MatchOwner *owner);
void peer_stop_monitor(Peer *peer);
void peer_flush_matches(Peer *peer);

int peer_queue_call(PolicySnapshot *sender_policy, NameSet *sender_names, MatchRegistry *sender_matches, ReplyOwner *sender_replies, User *sender_user, uint64_t sender_id, Peer *receiver, Message *message);
Expand Down

0 comments on commit dee3380

Please sign in to comment.