Skip to content

Commit

Permalink
Protect against priority inversion for linux (OpenEtherCATsociety#194)
Browse files Browse the repository at this point in the history
Set priority inheritance for mutex
  • Loading branch information
Wanga authored and nakarlsson committed Aug 7, 2018
1 parent 5b2c51b commit 2e165be
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions oshw/linux/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
struct ifreq ifr;
struct sockaddr_ll sll;
int *psock;
pthread_mutexattr_t mutexattr;

rval = 0;
if (secondary)
Expand Down Expand Up @@ -123,9 +124,11 @@ int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
}
else
{
pthread_mutex_init(&(port->getindex_mutex), NULL);
pthread_mutex_init(&(port->tx_mutex) , NULL);
pthread_mutex_init(&(port->rx_mutex) , NULL);
pthread_mutexattr_init(&mutexattr);
pthread_mutexattr_setprotocol(&mutexattr , PTHREAD_PRIO_INHERIT);
pthread_mutex_init(&(port->getindex_mutex), &mutexattr);
pthread_mutex_init(&(port->tx_mutex) , &mutexattr);
pthread_mutex_init(&(port->rx_mutex) , &mutexattr);
port->sockhandle = -1;
port->lastidx = 0;
port->redstate = ECT_RED_NONE;
Expand Down

0 comments on commit 2e165be

Please sign in to comment.