The SLiRP mutex is now a Network mutex and is now also used by PCap.
This commit is contained in:
@@ -78,6 +78,10 @@ poll_thread(void *arg)
|
|||||||
|
|
||||||
/* As long as the channel is open.. */
|
/* As long as the channel is open.. */
|
||||||
while (pcap != NULL) {
|
while (pcap != NULL) {
|
||||||
|
startnet();
|
||||||
|
|
||||||
|
network_wait_for_poll();
|
||||||
|
|
||||||
/* Wait for the next packet to arrive. */
|
/* Wait for the next packet to arrive. */
|
||||||
data = f_pcap_next(pcap, &h);
|
data = f_pcap_next(pcap, &h);
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
@@ -101,11 +105,15 @@ poll_thread(void *arg)
|
|||||||
/* If we did not get anything, wait a while. */
|
/* If we did not get anything, wait a while. */
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
thread_wait_event(evt, 10);
|
thread_wait_event(evt, 10);
|
||||||
|
|
||||||
|
endnet();
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_destroy_event(evt);
|
thread_destroy_event(evt);
|
||||||
poll_tid = NULL;
|
poll_tid = NULL;
|
||||||
|
|
||||||
|
network_mutex_close();
|
||||||
|
|
||||||
pclog("PCAP: polling stopped.\n");
|
pclog("PCAP: polling stopped.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,6 +241,8 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
|||||||
poll_rx = func;
|
poll_rx = func;
|
||||||
poll_arg = arg;
|
poll_arg = arg;
|
||||||
|
|
||||||
|
network_thread_init();
|
||||||
|
|
||||||
pclog(" Starting thread..\n");
|
pclog(" Starting thread..\n");
|
||||||
poll_tid = thread_create(poll_thread, mac);
|
poll_tid = thread_create(poll_thread, mac);
|
||||||
|
|
||||||
@@ -263,6 +273,8 @@ network_pcap_close(void)
|
|||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
network_mutex_close();
|
||||||
|
|
||||||
/* OK, now shut down WinPcap itself. */
|
/* OK, now shut down WinPcap itself. */
|
||||||
f_pcap_close(pc);
|
f_pcap_close(pc);
|
||||||
pc = pcap = NULL;
|
pc = pcap = NULL;
|
||||||
@@ -390,6 +402,11 @@ network_pcap_test(void)
|
|||||||
void
|
void
|
||||||
network_pcap_in(uint8_t *bufp, int len)
|
network_pcap_in(uint8_t *bufp, int len)
|
||||||
{
|
{
|
||||||
if (pcap != NULL)
|
if (pcap != NULL) {
|
||||||
|
network_busy_set();
|
||||||
|
|
||||||
f_pcap_sendpacket(pcap, bufp, len);
|
f_pcap_sendpacket(pcap, bufp, len);
|
||||||
|
|
||||||
|
network_busy_clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,24 +32,9 @@ static queueADT slirpq; /* SLiRP library handle */
|
|||||||
static thread_t *poll_tid;
|
static thread_t *poll_tid;
|
||||||
static NETRXCB poll_rx; /* network RX function to call */
|
static NETRXCB poll_rx; /* network RX function to call */
|
||||||
static void *poll_arg; /* network RX function arg */
|
static void *poll_arg; /* network RX function arg */
|
||||||
static mutex_t *slirpMutex;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
startslirp(void)
|
|
||||||
{
|
|
||||||
thread_wait_mutex(slirpMutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
endslirp(void)
|
|
||||||
{
|
|
||||||
thread_release_mutex(slirpMutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Instead of calling this and crashing some times
|
/* Instead of calling this and crashing some times
|
||||||
or experencing jitter, this is called by the
|
or experencing jitter, this is called by the
|
||||||
60Hz clock which seems to do the job. */
|
60Hz clock which seems to do the job. */
|
||||||
@@ -82,25 +67,6 @@ slirp_tic(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct
|
|
||||||
{
|
|
||||||
int busy;
|
|
||||||
int queue_in_use;
|
|
||||||
|
|
||||||
event_t *wake_poll_thread;
|
|
||||||
event_t *poll_complete;
|
|
||||||
event_t *queue_not_in_use;
|
|
||||||
} poll_data;
|
|
||||||
|
|
||||||
|
|
||||||
void network_slirp_wait_for_poll()
|
|
||||||
{
|
|
||||||
while (poll_data.busy)
|
|
||||||
thread_wait_event(poll_data.poll_complete, -1);
|
|
||||||
thread_reset_event(poll_data.poll_complete);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Handle the receiving of frames. */
|
/* Handle the receiving of frames. */
|
||||||
static void
|
static void
|
||||||
poll_thread(void *arg)
|
poll_thread(void *arg)
|
||||||
@@ -114,9 +80,9 @@ poll_thread(void *arg)
|
|||||||
evt = thread_create_event();
|
evt = thread_create_event();
|
||||||
|
|
||||||
while (slirpq != NULL) {
|
while (slirpq != NULL) {
|
||||||
startslirp();
|
startnet();
|
||||||
|
|
||||||
network_slirp_wait_for_poll();
|
network_wait_for_poll();
|
||||||
|
|
||||||
/* See if there is any work. */
|
/* See if there is any work. */
|
||||||
slirp_tic();
|
slirp_tic();
|
||||||
@@ -141,13 +107,13 @@ poll_thread(void *arg)
|
|||||||
/* Done with this one. */
|
/* Done with this one. */
|
||||||
free(qp);
|
free(qp);
|
||||||
|
|
||||||
endslirp();
|
endnet();
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_destroy_event(evt);
|
thread_destroy_event(evt);
|
||||||
evt = poll_tid = NULL;
|
evt = poll_tid = NULL;
|
||||||
|
|
||||||
thread_close_mutex(slirpMutex);
|
network_mutex_close();
|
||||||
|
|
||||||
pclog("SLiRP: polling stopped.\n");
|
pclog("SLiRP: polling stopped.\n");
|
||||||
}
|
}
|
||||||
@@ -171,10 +137,7 @@ network_slirp_setup(uint8_t *mac, NETRXCB func, void *arg)
|
|||||||
poll_rx = func;
|
poll_rx = func;
|
||||||
poll_arg = arg;
|
poll_arg = arg;
|
||||||
|
|
||||||
slirpMutex = thread_create_mutex(L"86Box.SLiRPMutex");
|
network_thread_init();
|
||||||
|
|
||||||
poll_data.wake_poll_thread = thread_create_event();
|
|
||||||
poll_data.poll_complete = thread_create_event();
|
|
||||||
|
|
||||||
pclog("SLiRP: starting thread..\n");
|
pclog("SLiRP: starting thread..\n");
|
||||||
poll_tid = thread_create(poll_thread, mac);
|
poll_tid = thread_create(poll_thread, mac);
|
||||||
@@ -205,7 +168,7 @@ network_slirp_close(void)
|
|||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
thread_close_mutex(slirpMutex);
|
network_mutex_close();
|
||||||
|
|
||||||
/* OK, now shut down SLiRP itself. */
|
/* OK, now shut down SLiRP itself. */
|
||||||
QueueDestroy(sl);
|
QueueDestroy(sl);
|
||||||
@@ -238,12 +201,11 @@ void
|
|||||||
network_slirp_in(uint8_t *pkt, int pkt_len)
|
network_slirp_in(uint8_t *pkt, int pkt_len)
|
||||||
{
|
{
|
||||||
if (slirpq != NULL) {
|
if (slirpq != NULL) {
|
||||||
poll_data.busy = 1;
|
network_busy_set();
|
||||||
|
|
||||||
slirp_input((const uint8_t *)pkt, pkt_len);
|
slirp_input((const uint8_t *)pkt, pkt_len);
|
||||||
|
|
||||||
poll_data.busy = 0;
|
network_busy_clear();
|
||||||
thread_set_event(poll_data.poll_complete);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include "../ibm.h"
|
#include "../ibm.h"
|
||||||
#include "../device.h"
|
#include "../device.h"
|
||||||
|
#include "../plat.h"
|
||||||
#include "../ui.h"
|
#include "../ui.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "net_ne2000.h"
|
#include "net_ne2000.h"
|
||||||
@@ -53,6 +54,79 @@ int network_card;
|
|||||||
netdev_t network_devs[32];
|
netdev_t network_devs[32];
|
||||||
char network_pcap[512];
|
char network_pcap[512];
|
||||||
int nic_do_log;
|
int nic_do_log;
|
||||||
|
static mutex_t *netMutex;
|
||||||
|
|
||||||
|
|
||||||
|
static struct
|
||||||
|
{
|
||||||
|
int busy;
|
||||||
|
int queue_in_use;
|
||||||
|
|
||||||
|
event_t *wake_poll_thread;
|
||||||
|
event_t *poll_complete;
|
||||||
|
event_t *queue_not_in_use;
|
||||||
|
} poll_data;
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
startnet(void)
|
||||||
|
{
|
||||||
|
thread_wait_mutex(netMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
endnet(void)
|
||||||
|
{
|
||||||
|
thread_release_mutex(netMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
network_wait_for_poll()
|
||||||
|
{
|
||||||
|
while (poll_data.busy)
|
||||||
|
thread_wait_event(poll_data.poll_complete, -1);
|
||||||
|
thread_reset_event(poll_data.poll_complete);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
network_mutex_init()
|
||||||
|
{
|
||||||
|
netMutex = thread_create_mutex(L"86Box.NetMutex");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
network_mutex_close()
|
||||||
|
{
|
||||||
|
thread_close_mutex(netMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
network_thread_init()
|
||||||
|
{
|
||||||
|
network_mutex_init();
|
||||||
|
|
||||||
|
poll_data.wake_poll_thread = thread_create_event();
|
||||||
|
poll_data.poll_complete = thread_create_event();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
network_busy_set()
|
||||||
|
{
|
||||||
|
poll_data.busy = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
network_busy_clear()
|
||||||
|
{
|
||||||
|
poll_data.busy = 0;
|
||||||
|
thread_set_event(poll_data.poll_complete);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -56,6 +56,15 @@ extern char network_pcap[512];
|
|||||||
|
|
||||||
|
|
||||||
/* Function prototypes. */
|
/* Function prototypes. */
|
||||||
|
extern void startnet(void);
|
||||||
|
extern void endnet(void);
|
||||||
|
extern void network_wait_for_poll();
|
||||||
|
extern void network_mutex_init();
|
||||||
|
extern void network_mutex_close();
|
||||||
|
extern void network_thread_init();
|
||||||
|
extern void network_busy_set();
|
||||||
|
extern void network_busy_clear();
|
||||||
|
|
||||||
extern void network_init(void);
|
extern void network_init(void);
|
||||||
extern int network_attach(void *, uint8_t *, NETRXCB);
|
extern int network_attach(void *, uint8_t *, NETRXCB);
|
||||||
extern void network_close(void);
|
extern void network_close(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user