Use queue instaed of vector

This preserves correctly the order of packets
This commit is contained in:
Baptiste Wicht 2016-10-02 16:43:18 +02:00
parent 60622f8a3b
commit ebc2bfbb9c
No known key found for this signature in database
GPG Key ID: C5566B6C7F884532
4 changed files with 11 additions and 17 deletions

View File

@ -10,10 +10,9 @@
#include <types.hpp>
#include <string.hpp>
#include <circular_buffer.hpp>
#include <lock_guard.hpp>
#include <shared_ptr.hpp>
#include <vector.hpp>
#include <queue.hpp>
#include "conc/mutex.hpp"
#include "conc/semaphore.hpp"
@ -51,13 +50,8 @@ struct interface_descriptor {
mutable semaphore tx_sem; ///< Semaphore for transmission
mutable deferred_unique_semaphore rx_sem; ///< Semaphore for reception
//TODO We need a queue to handle the packets in order
// (need a deque to be efficient)
std::vector<network::packet_p> rx_queue;
std::vector<network::packet_p> tx_queue;
//circular_buffer<packet, 32> rx_queue; ///< The reception queue
//circular_buffer<packet, 32> tx_queue; ///< The transmission queue
std::queue<network::packet_p> rx_queue;
std::queue<network::packet_p> tx_queue;
void (*hw_send)(interface_descriptor&, packet_p& p); ///< Driver hardware send function
@ -66,7 +60,7 @@ struct interface_descriptor {
*/
void send(packet_p& p){
std::lock_guard<mutex> l(tx_lock);
tx_queue.push_back(p);
tx_queue.push(p);
tx_sem.unlock();
}

View File

@ -28,7 +28,7 @@ void send_packet(network::interface_descriptor& interface, network::packet_p& pa
{
direct_int_lock lock;
interface.rx_queue.push_back(packet);
interface.rx_queue.push(packet);
interface.rx_sem.notify();
}

View File

@ -131,7 +131,7 @@ void packet_handler(interrupt::syscall_regs*, void* data){
std::copy_n(packet_payload, packet_only_length, packet_buffer);
interface.rx_queue.emplace_back(std::make_shared<network::packet>(packet_buffer, packet_only_length));
interface.rx_queue.emplace(std::make_shared<network::packet>(packet_buffer, packet_only_length));
interface.rx_sem.notify();
}
@ -194,7 +194,7 @@ void send_packet(network::interface_descriptor& interface, network::packet_p& pa
{
direct_int_lock lock;
interface.rx_queue.push_back(packet);
interface.rx_queue.push(packet);
interface.rx_sem.notify();
}

View File

@ -74,8 +74,8 @@ void rx_thread(void* data){
//TODO This is highly unsafe since back() and pop_back() can suffer interleaving
auto packet = interface.rx_queue.back();
interface.rx_queue.pop_back();
auto packet = interface.rx_queue.top();
interface.rx_queue.pop();
ethernet_layer->decode(interface, packet);
@ -94,8 +94,8 @@ void tx_thread(void* data){
while(true){
interface.tx_sem.lock();
auto packet = interface.tx_queue.back();
interface.tx_queue.pop_back();
auto packet = interface.tx_queue.top();
interface.tx_queue.pop();
interface.hw_send(interface, packet);
thor_assert(!packet->user);