}
EventView GetReceivedEvent() {
+ std::lock_guard<std::mutex> lock(list_protector_);
EventView packetview = incoming_events_.front();
incoming_events_.pop_front();
return packetview;
}
AclView GetReceivedAcl() {
+ std::lock_guard<std::mutex> lock(list_protector_);
AclView packetview = incoming_acl_packets_.front();
incoming_acl_packets_.pop_front();
return packetview;
std::list<AclView> incoming_acl_packets_;
std::unique_ptr<std::promise<void>> event_promise_;
std::unique_ptr<std::promise<void>> acl_promise_;
+ /* This mutex is protecting lists above from being pushed/popped from different threads at same time */
+ std::mutex list_protector_;
void handle_acl() {
+ std::lock_guard<std::mutex> lock(list_protector_);
auto acl_ptr = hci_->GetAclQueueEnd()->TryDequeue();
incoming_acl_packets_.push_back(*acl_ptr);
if (acl_promise_ != nullptr) {
template <typename T>
void handle_event(T event) {
+ std::lock_guard<std::mutex> lock(list_protector_);
incoming_events_.push_back(event);
if (event_promise_ != nullptr) {
auto promise = std::move(event_promise_);
Address bd_addr;
ASSERT_TRUE(Address::FromString("A1:A2:A3:A4:A5:A6", bd_addr));
uint16_t handle = 0x0001;
- uint16_t num_packets = 100;
+ const uint16_t num_packets = 100;
PacketBoundaryFlag packet_boundary_flag = PacketBoundaryFlag::FIRST_AUTOMATICALLY_FLUSHABLE;
BroadcastFlag broadcast_flag = BroadcastFlag::POINT_TO_POINT;
for (uint16_t i = 0; i < num_packets; i++) {
auto incoming_acl_future = upper->GetReceivedAclFuture();
uint16_t received_packets = 0;
while (received_packets < num_packets - 1) {
- size_t num_packets = upper->GetNumReceivedAclPackets();
- if (num_packets == 0) {
+ size_t num_rcv_packets = upper->GetNumReceivedAclPackets();
+ if (num_rcv_packets == 0) {
auto incoming_acl_status = incoming_acl_future.wait_for(kAclTimeout);
// Get the next future.
ASSERT_EQ(incoming_acl_status, std::future_status::ready);
incoming_acl_future = upper->GetReceivedAclFuture();
- num_packets = upper->GetNumReceivedAclPackets();
+ num_rcv_packets = upper->GetNumReceivedAclPackets();
}
- for (size_t i = 0; i < num_packets; i++) {
+ for (size_t i = 0; i < num_rcv_packets; i++) {
auto acl_view = upper->GetReceivedAcl();
ASSERT_TRUE(acl_view.IsValid());
ASSERT_EQ(bd_addr.length() + sizeof(handle) + sizeof(received_packets), acl_view.GetPayload().size());