Fix race condition in rxbufstat (#200)

This commit is contained in:
wanga 2018-08-23 13:36:56 +08:00 committed by nakarlsson
parent 2e165bee41
commit 0a67e6bf94
6 changed files with 50 additions and 16 deletions

View File

@ -363,15 +363,16 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
} }
log_RT_event('S',(WORD)3); log_RT_event('S',(WORD)3);
(*stack->rxbufstat)[idx] = EC_BUF_TX;
status = hpeStartTransmitter(port->handle); status = hpeStartTransmitter(port->handle);
if (status != E_OK) if (status != E_OK)
{ {
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
result = -3; result = -3;
goto end; goto end;
} }
log_RT_event('S',(WORD)4); log_RT_event('S',(WORD)4);
(*stack->rxbufstat)[idx] = EC_BUF_TX;
result = lp; result = lp;
end: end:
@ -408,9 +409,13 @@ int ecx_outframe_red(ecx_portt *port, int idx)
//send(sockhandle2, &ec_txbuf2, ec_txbuflength2 , 0); //send(sockhandle2, &ec_txbuf2, ec_txbuflength2 , 0);
// OBS! redundant not ACTIVE for BFIN, just added to compile // OBS! redundant not ACTIVE for BFIN, just added to compile
//ASSERT (0); //ASSERT (0);
hpeAttachTransmitBufferSet(port->redport->handle, port->tx_buffers[idx]); hpeAttachTransmitBufferSet(port->redport->handle, port->tx_buffers[idx]);
status = hpeStartTransmitter(port->redport->handle);
port->redport->rxbufstat[idx] = EC_BUF_TX; port->redport->rxbufstat[idx] = EC_BUF_TX;
status = hpeStartTransmitter(port->redport->handle);
if (status != E_OK)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
} }
return rval; return rval;

View File

@ -281,8 +281,12 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
stack = &(port->redport->stack); stack = &(port->redport->stack);
} }
lp = (*stack->txbuflength)[idx]; lp = (*stack->txbuflength)[idx];
rval = send(*stack->sock, (*stack->txbuf)[idx], lp, 0);
(*stack->rxbufstat)[idx] = EC_BUF_TX; (*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = send(*stack->sock, (*stack->txbuf)[idx], lp, 0);
if (rval == -1)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
return rval; return rval;
} }
@ -314,9 +318,12 @@ int ecx_outframe_red(ecx_portt *port, int idx)
/* rewrite MAC source address 1 to secondary */ /* rewrite MAC source address 1 to secondary */
ehp->sa1 = htons(secMAC[1]); ehp->sa1 = htons(secMAC[1]);
/* transmit over secondary socket */ /* transmit over secondary socket */
send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0);
pthread_mutex_unlock( &(port->tx_mutex) );
port->redport->rxbufstat[idx] = EC_BUF_TX; port->redport->rxbufstat[idx] = EC_BUF_TX;
if (send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0) == -1)
{
port->redport->rxbufstat[idx] = EC_BUF_EMPTY;
}
pthread_mutex_unlock( &(port->tx_mutex) );
} }
return rval; return rval;

View File

@ -327,8 +327,12 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
} }
lp = (*stack->txbuflength)[idx]; lp = (*stack->txbuflength)[idx];
//rval = send(*stack->sock, (*stack->txbuf)[idx], lp, 0); //rval = send(*stack->sock, (*stack->txbuf)[idx], lp, 0);
rval = write (*stack->sock,(*stack->txbuf)[idx], lp);
(*stack->rxbufstat)[idx] = EC_BUF_TX; (*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = write (*stack->sock,(*stack->txbuf)[idx], lp);
if (rval == -1)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
return rval; return rval;
} }
@ -361,9 +365,12 @@ int ecx_outframe_red(ecx_portt *port, int idx)
ehp->sa1 = htons(secMAC[1]); ehp->sa1 = htons(secMAC[1]);
/* transmit over secondary socket */ /* transmit over secondary socket */
//send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0); //send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0);
write(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2);
pthread_mutex_unlock( &(port->tx_mutex) );
port->redport->rxbufstat[idx] = EC_BUF_TX; port->redport->rxbufstat[idx] = EC_BUF_TX;
if (write(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2) == -1)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
pthread_mutex_unlock( &(port->tx_mutex) );
} }
return rval; return rval;

View File

@ -262,8 +262,8 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
stack = &(port->redport->stack); stack = &(port->redport->stack);
} }
lp = (*stack->txbuflength)[idx]; lp = (*stack->txbuflength)[idx];
rval = bfin_EMAC_send((*stack->txbuf)[idx], lp);
(*stack->rxbufstat)[idx] = EC_BUF_TX; (*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = bfin_EMAC_send((*stack->txbuf)[idx], lp);
return rval; return rval;
} }
@ -298,9 +298,9 @@ int ecx_outframe_red(ecx_portt *port, int idx)
//send(sockhandle2, &ec_txbuf2, ec_txbuflength2 , 0); //send(sockhandle2, &ec_txbuf2, ec_txbuflength2 , 0);
// OBS! redundant not ACTIVE for BFIN, just added to compile // OBS! redundant not ACTIVE for BFIN, just added to compile
ASSERT (0); ASSERT (0);
port->redport->rxbufstat[idx] = EC_BUF_TX;
bfin_EMAC_send(&(port->txbuf2), port->txbuflength2); bfin_EMAC_send(&(port->txbuf2), port->txbuflength2);
mtx_unlock (port->tx_mutex); mtx_unlock (port->tx_mutex);
port->redport->rxbufstat[idx] = EC_BUF_TX;
} }
return rval; return rval;

View File

@ -474,13 +474,17 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
pPktDev = &(port->redport->pktDev); pPktDev = &(port->redport->pktDev);
} }
(*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = ec_outfram_send(pPktDev, (char*)(*stack->txbuf)[idx], rval = ec_outfram_send(pPktDev, (char*)(*stack->txbuf)[idx],
(*stack->txbuflength)[idx]); (*stack->txbuflength)[idx]);
if (rval > 0) if (rval > 0)
{ {
(*stack->rxbufstat)[idx] = EC_BUF_TX;
port->pktDev.tx_count++; port->pktDev.tx_count++;
} }
else
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
return rval; return rval;
} }
@ -511,8 +515,12 @@ int ecx_outframe_red(ecx_portt *port, int idx)
/* rewrite MAC source address 1 to secondary */ /* rewrite MAC source address 1 to secondary */
ehp->sa1 = htons(secMAC[1]); ehp->sa1 = htons(secMAC[1]);
/* transmit over secondary interface */ /* transmit over secondary interface */
rval = ec_outfram_send(&(port->redport->pktDev), &(port->txbuf2), port->txbuflength2);
port->redport->rxbufstat[idx] = EC_BUF_TX; port->redport->rxbufstat[idx] = EC_BUF_TX;
rval = ec_outfram_send(&(port->redport->pktDev), &(port->txbuf2), port->txbuflength2);
if (rval <= 0)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
} }
return rval; return rval;

View File

@ -268,8 +268,12 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
stack = &(port->redport->stack); stack = &(port->redport->stack);
} }
lp = (*stack->txbuflength)[idx]; lp = (*stack->txbuflength)[idx];
rval = pcap_sendpacket(*stack->sock, (*stack->txbuf)[idx], lp);
(*stack->rxbufstat)[idx] = EC_BUF_TX; (*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = pcap_sendpacket(*stack->sock, (*stack->txbuf)[idx], lp);
if (rval == PCAP_ERROR)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
return rval; return rval;
} }
@ -301,9 +305,12 @@ int ecx_outframe_red(ecx_portt *port, int idx)
/* rewrite MAC source address 1 to secondary */ /* rewrite MAC source address 1 to secondary */
ehp->sa1 = htons(secMAC[1]); ehp->sa1 = htons(secMAC[1]);
/* transmit over secondary socket */ /* transmit over secondary socket */
pcap_sendpacket(port->redport->sockhandle, (u_char const *)&(port->txbuf2), port->txbuflength2);
LeaveCriticalSection( &(port->tx_mutex) );
port->redport->rxbufstat[idx] = EC_BUF_TX; port->redport->rxbufstat[idx] = EC_BUF_TX;
if (pcap_sendpacket(port->redport->sockhandle, (u_char const *)&(port->txbuf2), port->txbuflength2) == PCAP_ERROR)
{
port->redport->rxbufstat[idx] = EC_BUF_EMPTY;
}
LeaveCriticalSection( &(port->tx_mutex) );
} }
return rval; return rval;