diff --git a/src/network/net_pcap.c b/src/network/net_pcap.c index ba56cebfb..7008d1442 100644 --- a/src/network/net_pcap.c +++ b/src/network/net_pcap.c @@ -172,6 +172,7 @@ poll_thread(void *arg) thread_set_event(poll_state); /* Create a waitable event. */ + pcap_log("PCAP: Creating event...\n"); evt = thread_create_event(); /* As long as the channel is open.. */ @@ -185,8 +186,6 @@ poll_thread(void *arg) if (pcap == NULL) break; - /* Wait for the next packet to arrive. */ - tx = network_tx_queue_check(); if (network_get_wait() || (poll_card->set_link_state && poll_card->set_link_state(poll_card->priv)) || (poll_card->wait && poll_card->wait(poll_card->priv))) data = NULL; else @@ -208,11 +207,14 @@ poll_thread(void *arg) } } + /* Wait for the next packet to arrive. */ + tx = network_tx_queue_check(); + if (tx) network_do_tx(); /* If we did not get anything, wait a while. */ - if ((data == NULL) && !tx) + if (!tx) thread_wait_event(evt, 10); /* Release ownership of the device. */ @@ -224,7 +226,8 @@ poll_thread(void *arg) thread_destroy_event(evt); pcap_log("PCAP: polling stopped.\n"); - thread_set_event(poll_state); + if (poll_state != NULL) + thread_set_event(poll_state); } diff --git a/src/network/network.c b/src/network/network.c index b545b08ca..0e7f16bac 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -49,6 +49,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include +#include #include #include #include @@ -107,7 +108,7 @@ int nic_do_log = ENABLE_NIC_LOG; /* Local variables. */ -static volatile int net_wait = 0; +static volatile atomic_int net_wait = 0; static mutex_t *network_mutex; static uint8_t *network_mac; static uint8_t network_timer_active = 0; @@ -388,8 +389,8 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx, NETWAITCB wait, NETSETLINKST network_set_wait(0); /* Create the network events. */ - poll_data.wake_poll_thread = thread_create_event(); poll_data.poll_complete = thread_create_event(); + poll_data.wake_poll_thread = thread_create_event(); /* Activate the platform module. */ switch(network_type) { @@ -671,9 +672,7 @@ network_card_get_from_internal_name(char *s) void network_set_wait(int wait) { - network_wait(1); net_wait = wait; - network_wait(0); } @@ -682,8 +681,6 @@ network_get_wait(void) { int ret; - network_wait(1); ret = net_wait; - network_wait(0); return ret; }