DHCP proc semaphor replaced with mutex

This commit is contained in:
Wiesner András 2023-02-24 12:19:58 +01:00
parent 025f6d09b9
commit a6ee1d3fe5

View File

@ -16,7 +16,7 @@ static struct {
cbd desc;
uint32_t tranId;
EthInterface *intf;
ETHLIB_OS_SEM_TYPE procSem;
ETHLIB_OS_MTX_TYPE procMtx;
} s;
static const uint8_t DHCP_MAGIC_COOKIE[] = {99, 130, 83, 99};
@ -249,7 +249,7 @@ void dhcp_request(ip4_addr reqAddr, ip4_addr dhcpServerAddr) {
}
static void dhcp_process(DhcpProps *props, DhcpOption *opts) {
ETHLIB_OS_SEM_WAIT(&s.procSem); // LOCK!
ETHLIB_OS_MTX_LOCK(&s.procMtx); // LOCK!
switch (s.state) {
case DHCP_INIT:
@ -313,7 +313,7 @@ static void dhcp_process(DhcpProps *props, DhcpOption *opts) {
break;
}
ETHLIB_OS_SEM_POST(&s.procSem); // RELEASE!
ETHLIB_OS_MTX_UNLOCK(&s.procMtx); // RELEASE!
}
static int dhcp_resp_cb(const Pckt *pckt, PcktSieveLayerTag tag) {
@ -334,8 +334,7 @@ void dhcp_start() {
}
void dhcp_initiate(EthInterface *intf) {
ETHLIB_OS_SEM_CREATE(&s.procSem);
ETHLIB_OS_SEM_POST(&s.procSem);
ETHLIB_OS_MTX_CREATE(&s.procMtx);
s.state = DHCP_INIT;
s.buf = dynmem_alloc(DHCP_MIN_PACKET_SIZE);
s.desc = udp_new_connblock(intf, IPv4_ANY_ADDR, DHCP_CLIENT_PORT, dhcp_resp_cb);