mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 00:26:44 -04:00
Use queue instaed of vector
This preserves correctly the order of packets
This commit is contained in:
parent
60622f8a3b
commit
ebc2bfbb9c
@ -10,10 +10,9 @@
|
|||||||
|
|
||||||
#include <types.hpp>
|
#include <types.hpp>
|
||||||
#include <string.hpp>
|
#include <string.hpp>
|
||||||
#include <circular_buffer.hpp>
|
|
||||||
#include <lock_guard.hpp>
|
#include <lock_guard.hpp>
|
||||||
#include <shared_ptr.hpp>
|
#include <shared_ptr.hpp>
|
||||||
#include <vector.hpp>
|
#include <queue.hpp>
|
||||||
|
|
||||||
#include "conc/mutex.hpp"
|
#include "conc/mutex.hpp"
|
||||||
#include "conc/semaphore.hpp"
|
#include "conc/semaphore.hpp"
|
||||||
@ -51,13 +50,8 @@ struct interface_descriptor {
|
|||||||
mutable semaphore tx_sem; ///< Semaphore for transmission
|
mutable semaphore tx_sem; ///< Semaphore for transmission
|
||||||
mutable deferred_unique_semaphore rx_sem; ///< Semaphore for reception
|
mutable deferred_unique_semaphore rx_sem; ///< Semaphore for reception
|
||||||
|
|
||||||
//TODO We need a queue to handle the packets in order
|
std::queue<network::packet_p> rx_queue;
|
||||||
// (need a deque to be efficient)
|
std::queue<network::packet_p> tx_queue;
|
||||||
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
|
|
||||||
|
|
||||||
void (*hw_send)(interface_descriptor&, packet_p& p); ///< Driver hardware send function
|
void (*hw_send)(interface_descriptor&, packet_p& p); ///< Driver hardware send function
|
||||||
|
|
||||||
@ -66,7 +60,7 @@ struct interface_descriptor {
|
|||||||
*/
|
*/
|
||||||
void send(packet_p& p){
|
void send(packet_p& p){
|
||||||
std::lock_guard<mutex> l(tx_lock);
|
std::lock_guard<mutex> l(tx_lock);
|
||||||
tx_queue.push_back(p);
|
tx_queue.push(p);
|
||||||
tx_sem.unlock();
|
tx_sem.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ void send_packet(network::interface_descriptor& interface, network::packet_p& pa
|
|||||||
{
|
{
|
||||||
direct_int_lock lock;
|
direct_int_lock lock;
|
||||||
|
|
||||||
interface.rx_queue.push_back(packet);
|
interface.rx_queue.push(packet);
|
||||||
interface.rx_sem.notify();
|
interface.rx_sem.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ void packet_handler(interrupt::syscall_regs*, void* data){
|
|||||||
|
|
||||||
std::copy_n(packet_payload, packet_only_length, packet_buffer);
|
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();
|
interface.rx_sem.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ void send_packet(network::interface_descriptor& interface, network::packet_p& pa
|
|||||||
{
|
{
|
||||||
direct_int_lock lock;
|
direct_int_lock lock;
|
||||||
|
|
||||||
interface.rx_queue.push_back(packet);
|
interface.rx_queue.push(packet);
|
||||||
interface.rx_sem.notify();
|
interface.rx_sem.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +74,8 @@ void rx_thread(void* data){
|
|||||||
|
|
||||||
//TODO This is highly unsafe since back() and pop_back() can suffer interleaving
|
//TODO This is highly unsafe since back() and pop_back() can suffer interleaving
|
||||||
|
|
||||||
auto packet = interface.rx_queue.back();
|
auto packet = interface.rx_queue.top();
|
||||||
interface.rx_queue.pop_back();
|
interface.rx_queue.pop();
|
||||||
|
|
||||||
ethernet_layer->decode(interface, packet);
|
ethernet_layer->decode(interface, packet);
|
||||||
|
|
||||||
@ -94,8 +94,8 @@ void tx_thread(void* data){
|
|||||||
while(true){
|
while(true){
|
||||||
interface.tx_sem.lock();
|
interface.tx_sem.lock();
|
||||||
|
|
||||||
auto packet = interface.tx_queue.back();
|
auto packet = interface.tx_queue.top();
|
||||||
interface.tx_queue.pop_back();
|
interface.tx_queue.pop();
|
||||||
interface.hw_send(interface, packet);
|
interface.hw_send(interface, packet);
|
||||||
|
|
||||||
thor_assert(!packet->user);
|
thor_assert(!packet->user);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user