Skip to content

Commit

Permalink
Renamed actor_t id field to avoid confusion with identity
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsAsplund committed Jan 14, 2023
1 parent 2f72ad0 commit 9ddbc36
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 72 deletions.
122 changes: 61 additions & 61 deletions vunit/vhdl/com/src/com_messenger.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ package body com_messenger_pkg is
else
id := get_id(name);
end if;
actors(actors'length - 1) := ((id => actor_id), id,
actors(actors'length - 1) := ((p_id_number => actor_id), id,
deferred_creation, create(inbox_size), create(outbox_size), null, (null, null, null));

return actors(actors'length - 1).actor;
Expand All @@ -320,8 +320,8 @@ package body com_messenger_pkg is

impure function name (actor : actor_t) return string is
begin
if actors(actor.id).id /= null_id then
return full_name(actors(actor.id).id);
if actors(actor.p_id_number).id /= null_id then
return full_name(actors(actor.p_id_number).id);
else
return "";
end if;
Expand All @@ -338,10 +338,10 @@ package body com_messenger_pkg is
begin
if (actor = null_actor) or (name = "") then
actor := create_actor(name, false, inbox_size, outbox_size);
elsif actors(actor.id).deferred_creation then
actors(actor.id).deferred_creation := false;
actors(actor.id).inbox.size := inbox_size;
actors(actor.id).outbox.size := outbox_size;
elsif actors(actor.p_id_number).deferred_creation then
actors(actor.p_id_number).deferred_creation := false;
actors(actor.p_id_number).inbox.size := inbox_size;
actors(actor.p_id_number).outbox.size := outbox_size;
else
check_failed(duplicate_actor_name_error);
end if;
Expand All @@ -353,7 +353,7 @@ package body com_messenger_pkg is
subscriber : actor_t;
publisher : actor_t;
traffic_type : subscription_traffic_type_t) return boolean is
variable item : subscriber_item_ptr_t := actors(publisher.id).subscribers(traffic_type);
variable item : subscriber_item_ptr_t := actors(publisher.p_id_number).subscribers(traffic_type);
begin
while item /= null loop
if item.actor = subscriber then
Expand All @@ -368,12 +368,12 @@ package body com_messenger_pkg is
procedure remove_subscriber (subscriber : actor_t; publisher : actor_t; traffic_type : subscription_traffic_type_t) is
variable item, previous_item : subscriber_item_ptr_t;
begin
item := actors(publisher.id).subscribers(traffic_type);
item := actors(publisher.p_id_number).subscribers(traffic_type);
previous_item := null;
while item /= null loop
if item.actor = subscriber then
if previous_item = null then
actors(publisher.id).subscribers(traffic_type) := item.next_item;
actors(publisher.p_id_number).subscribers(traffic_type) := item.next_item;
else
previous_item.next_item := item.next_item;
end if;
Expand All @@ -393,17 +393,17 @@ package body com_messenger_pkg is
begin
check(not unknown_actor(actor), unknown_actor_error);

while actors(actor.id).inbox.first_envelope /= null loop
envelope := actors(actor.id).inbox.first_envelope;
actors(actor.id).inbox.first_envelope := envelope.next_envelope;
while actors(actor.p_id_number).inbox.first_envelope /= null loop
envelope := actors(actor.p_id_number).inbox.first_envelope;
actors(actor.p_id_number).inbox.first_envelope := envelope.next_envelope;
deallocate(envelope.message.payload);
deallocate_envelope(envelope);
end loop;

for t in subscription_traffic_type_t'left to subscription_traffic_type_t'right loop
while actors(actor.id).subscribers(t) /= null loop
item := actors(actor.id).subscribers(t);
actors(actor.id).subscribers(t) := item.next_item;
while actors(actor.p_id_number).subscribers(t) /= null loop
item := actors(actor.p_id_number).subscribers(t);
actors(actor.p_id_number).subscribers(t) := item.next_item;
deallocate(item);
end loop;
end loop;
Expand All @@ -416,9 +416,9 @@ package body com_messenger_pkg is
end loop;
end loop;

deallocate(actors(actor.id).inbox);
deallocate(actors(actor.id).outbox);
actors(actor.id) := null_actor_item;
deallocate(actors(actor.p_id_number).inbox);
deallocate(actors(actor.p_id_number).outbox);
actors(actor.p_id_number) := null_actor_item;
actor := null_actor;
end;

Expand Down Expand Up @@ -464,7 +464,7 @@ package body com_messenger_pkg is

impure function is_deferred(actor : actor_t) return boolean is
begin
return actors(actor.id).deferred_creation;
return actors(actor.p_id_number).deferred_creation;
end;

impure function num_of_deferred_creations return natural is
Expand All @@ -481,9 +481,9 @@ package body com_messenger_pkg is

impure function unknown_actor (actor : actor_t) return boolean is
begin
if (actor.id = 0) or (actor.id > actors'length - 1) then
if (actor.p_id_number = 0) or (actor.p_id_number > actors'length - 1) then
return true;
elsif actors(actor.id).actor = null_actor then
elsif actors(actor.p_id_number).actor = null_actor then
return true;
end if;

Expand All @@ -492,35 +492,35 @@ package body com_messenger_pkg is

impure function deferred (actor : actor_t) return boolean is
begin
return actors(actor.id).deferred_creation;
return actors(actor.p_id_number).deferred_creation;
end function deferred;

impure function is_full (actor : actor_t; mailbox_id : mailbox_id_t) return boolean is
begin
if mailbox_id = inbox then
return actors(actor.id).inbox.num_of_messages >= actors(actor.id).inbox.size;
return actors(actor.p_id_number).inbox.num_of_messages >= actors(actor.p_id_number).inbox.size;
else
return actors(actor.id).outbox.num_of_messages >= actors(actor.id).outbox.size;
return actors(actor.p_id_number).outbox.num_of_messages >= actors(actor.p_id_number).outbox.size;
end if;
end function;

impure function num_of_messages (actor : actor_t; mailbox_id : mailbox_id_t) return natural is
begin
if mailbox_id = inbox then
return actors(actor.id).inbox.num_of_messages;
return actors(actor.p_id_number).inbox.num_of_messages;
else
return actors(actor.id).outbox.num_of_messages;
return actors(actor.p_id_number).outbox.num_of_messages;
end if;
end function;

procedure resize_mailbox (actor : actor_t; new_size : natural; mailbox_id : mailbox_id_t) is
begin
if mailbox_id = inbox then
check(num_of_messages(actor, inbox) <= new_size, insufficient_size_error);
actors(actor.id).inbox.size := new_size;
actors(actor.p_id_number).inbox.size := new_size;
else
check(num_of_messages(actor, outbox) <= new_size, insufficient_size_error);
actors(actor.id).outbox.size := new_size;
actors(actor.p_id_number).outbox.size := new_size;
end if;
end;

Expand All @@ -537,14 +537,14 @@ package body com_messenger_pkg is
while item /= null loop
result := is_full(item.actor, inbox);
exit when result;
has_full_inboxes(actors(item.actor.id).subscribers(inbound), result);
has_full_inboxes(actors(item.actor.p_id_number).subscribers(inbound), result);
exit when result;
item := item.next_item;
end loop;
end;
begin
for t in subscription_traffic_types'range loop
has_full_inboxes(actors(publisher.id).subscribers(subscription_traffic_types(t)), result(t));
has_full_inboxes(actors(publisher.p_id_number).subscribers(subscription_traffic_types(t)), result(t));
end loop;

return or result;
Expand All @@ -554,15 +554,15 @@ package body com_messenger_pkg is
actor : actor_t;
subscription_traffic_type : subscription_traffic_type_t := published) return boolean is
begin
return actors(actor.id).subscribers(subscription_traffic_type) /= null;
return actors(actor.p_id_number).subscribers(subscription_traffic_type) /= null;
end;

impure function mailbox_size (actor : actor_t; mailbox_id : mailbox_id_t) return natural is
begin
if mailbox_id = inbox then
return actors(actor.id).inbox.size;
return actors(actor.p_id_number).inbox.size;
else
return actors(actor.id).outbox.size;
return actors(actor.p_id_number).outbox.size;
end if;
end function;

Expand Down Expand Up @@ -591,7 +591,7 @@ package body com_messenger_pkg is
write(envelope.message.payload, payload);
next_message_id := next_message_id + 1;

mailbox := actors(receiver.id).inbox when mailbox_id = inbox else actors(receiver.id).outbox;
mailbox := actors(receiver.p_id_number).inbox when mailbox_id = inbox else actors(receiver.p_id_number).outbox;
mailbox.num_of_messages := mailbox.num_of_messages + 1;
if mailbox.last_envelope /= null then
mailbox.last_envelope.next_envelope := envelope;
Expand All @@ -607,7 +607,7 @@ package body com_messenger_pkg is
begin
check(not unknown_actor(sender), unknown_publisher_error);

subscriber_item := actors(sender.id).subscribers(published);
subscriber_item := actors(sender.p_id_number).subscribers(published);
while subscriber_item /= null loop
send(sender, subscriber_item.actor, inbox, no_message_id, payload, receipt);
subscriber_item := subscriber_item.next_item;
Expand Down Expand Up @@ -677,7 +677,7 @@ package body com_messenger_pkg is
envelope.message.request_id := msg.request_id;
write(envelope.message.payload, encode(data));

mailbox := actors(receiver.id).inbox when mailbox_id = inbox else actors(receiver.id).outbox;
mailbox := actors(receiver.p_id_number).inbox when mailbox_id = inbox else actors(receiver.p_id_number).outbox;
mailbox.num_of_messages := mailbox.num_of_messages + 1;
if mailbox.last_envelope /= null then
mailbox.last_envelope.next_envelope := envelope;
Expand Down Expand Up @@ -717,7 +717,7 @@ package body com_messenger_pkg is
msg.sender := sender;

for t in subscriber_traffic_types'range loop
put_subscriber_messages(actors(sender.id).subscribers(subscriber_traffic_types(t)),
put_subscriber_messages(actors(sender.p_id_number).subscribers(subscriber_traffic_types(t)),
msg, set_msg_receiver => true);
end loop;

Expand All @@ -730,7 +730,7 @@ package body com_messenger_pkg is
constant subscriber_traffic_types : in subscription_traffic_types_t) is
begin
for t in subscriber_traffic_types'range loop
put_subscriber_messages(actors(sender.id).subscribers(subscriber_traffic_types(t)),
put_subscriber_messages(actors(sender.p_id_number).subscribers(subscriber_traffic_types(t)),
msg, set_msg_receiver => false);
end loop;
end;
Expand Down Expand Up @@ -759,7 +759,7 @@ package body com_messenger_pkg is
-----------------------------------------------------------------------------
impure function has_messages (actor : actor_t) return boolean is
begin
return actors(actor.id).inbox.first_envelope /= null;
return actors(actor.p_id_number).inbox.first_envelope /= null;
end function has_messages;

impure function has_messages (actor_vec : actor_vec_t) return boolean is
Expand All @@ -780,7 +780,7 @@ package body com_messenger_pkg is
variable envelope : inout envelope_ptr_t;
variable previous_envelope : inout envelope_ptr_t) is
begin
mailbox := actors(actor.id).inbox when mailbox_id = inbox else actors(actor.id).outbox;
mailbox := actors(actor.p_id_number).inbox when mailbox_id = inbox else actors(actor.p_id_number).outbox;
envelope := mailbox.first_envelope;
previous_envelope := null;

Expand Down Expand Up @@ -933,16 +933,16 @@ package body com_messenger_pkg is
return boolean is
begin
if request_id = no_message_id then
return actors(actor.id).reply_stash /= null;
elsif actors(actor.id).reply_stash /= null then
return actors(actor.id).reply_stash.message.request_id = request_id;
return actors(actor.p_id_number).reply_stash /= null;
elsif actors(actor.p_id_number).reply_stash /= null then
return actors(actor.p_id_number).reply_stash.message.request_id = request_id;
else
return false;
end if;
end function has_reply_stash_message;

impure function get_reply_stash_message_payload (actor : actor_t) return string is
variable envelope : envelope_ptr_t := actors(actor.id).reply_stash;
variable envelope : envelope_ptr_t := actors(actor.p_id_number).reply_stash;
begin
if envelope /= null then
return envelope.message.payload.all;
Expand All @@ -952,7 +952,7 @@ package body com_messenger_pkg is
end;

impure function get_reply_stash_message_sender (actor : actor_t) return actor_t is
variable envelope : envelope_ptr_t := actors(actor.id).reply_stash;
variable envelope : envelope_ptr_t := actors(actor.p_id_number).reply_stash;
begin
if envelope /= null then
return envelope.message.sender;
Expand All @@ -962,7 +962,7 @@ package body com_messenger_pkg is
end;

impure function get_reply_stash_message_receiver (actor : actor_t) return actor_t is
variable envelope : envelope_ptr_t := actors(actor.id).reply_stash;
variable envelope : envelope_ptr_t := actors(actor.p_id_number).reply_stash;
begin
if envelope /= null then
return envelope.message.receiver;
Expand All @@ -972,7 +972,7 @@ package body com_messenger_pkg is
end;

impure function get_reply_stash_message_id (actor : actor_t) return message_id_t is
variable envelope : envelope_ptr_t := actors(actor.id).reply_stash;
variable envelope : envelope_ptr_t := actors(actor.p_id_number).reply_stash;
begin
if envelope /= null then
return envelope.message.id;
Expand All @@ -982,7 +982,7 @@ package body com_messenger_pkg is
end;

impure function get_reply_stash_message_request_id (actor : actor_t) return message_id_t is
variable envelope : envelope_ptr_t := actors(actor.id).reply_stash;
variable envelope : envelope_ptr_t := actors(actor.p_id_number).reply_stash;
begin
if envelope /= null then
return envelope.message.request_id;
Expand All @@ -1000,7 +1000,7 @@ package body com_messenger_pkg is
variable previous_envelope : out envelope_ptr_t;
variable position : out natural) is
begin
mailbox := actors(actor.id).inbox when mailbox_id = inbox else actors(actor.id).outbox;
mailbox := actors(actor.p_id_number).inbox when mailbox_id = inbox else actors(actor.p_id_number).outbox;
envelope := mailbox.first_envelope;
previous_envelope := null;
position := 0;
Expand Down Expand Up @@ -1047,7 +1047,7 @@ package body com_messenger_pkg is
find_reply_message(actor, request_id, mailbox_id, mailbox, envelope, previous_envelope, position);

if envelope /= null then
actors(actor.id).reply_stash := envelope;
actors(actor.p_id_number).reply_stash := envelope;

if previous_envelope /= null then
previous_envelope.next_envelope := envelope.next_envelope;
Expand All @@ -1069,8 +1069,8 @@ package body com_messenger_pkg is

procedure clear_reply_stash (actor : actor_t) is
begin
deallocate(actors(actor.id).reply_stash.message.payload);
deallocate(actors(actor.id).reply_stash);
deallocate(actors(actor.p_id_number).reply_stash.message.payload);
deallocate(actors(actor.p_id_number).reply_stash);
end procedure clear_reply_stash;

procedure subscribe (
Expand All @@ -1089,14 +1089,14 @@ package body com_messenger_pkg is
end if;

if traffic_type = published then
new_subscriber := new subscriber_item_t'(subscriber, actors(publisher.id).subscribers(published));
actors(publisher.id).subscribers(published) := new_subscriber;
new_subscriber := new subscriber_item_t'(subscriber, actors(publisher.p_id_number).subscribers(published));
actors(publisher.p_id_number).subscribers(published) := new_subscriber;
elsif traffic_type = outbound then
new_subscriber := new subscriber_item_t'(subscriber, actors(publisher.id).subscribers(outbound));
actors(publisher.id).subscribers(outbound) := new_subscriber;
new_subscriber := new subscriber_item_t'(subscriber, actors(publisher.p_id_number).subscribers(outbound));
actors(publisher.p_id_number).subscribers(outbound) := new_subscriber;
else
new_subscriber := new subscriber_item_t'(subscriber, actors(publisher.id).subscribers(inbound));
actors(publisher.id).subscribers(inbound) := new_subscriber;
new_subscriber := new subscriber_item_t'(subscriber, actors(publisher.p_id_number).subscribers(inbound));
actors(publisher.p_id_number).subscribers(inbound) := new_subscriber;
end if;
end procedure subscribe;

Expand Down Expand Up @@ -1164,7 +1164,7 @@ package body com_messenger_pkg is
variable item : subscriber_item_ptr_t;
begin
for t in subscription_traffic_type_t'left to subscription_traffic_type_t'right loop
item := actors(publisher.id).subscribers(t);
item := actors(publisher.p_id_number).subscribers(t);
while item /= null loop
n_subscriptions := n_subscriptions + 1;
item := item.next_item;
Expand All @@ -1179,7 +1179,7 @@ package body com_messenger_pkg is
variable idx : natural := 0;
begin
for t in subscription_traffic_type_t'left to subscription_traffic_type_t'right loop
item := actors(publisher.id).subscribers(t);
item := actors(publisher.p_id_number).subscribers(t);
while item /= null loop
subscriptions(idx).subscriber := item.actor;
subscriptions(idx).publisher := publisher;
Expand Down
Loading

0 comments on commit 9ddbc36

Please sign in to comment.