From 39be6a0ac9ffaa5ddf93f092b63b34c8ee6934b9 Mon Sep 17 00:00:00 2001 From: Ricky Zhang Date: Thu, 18 Sep 2014 16:10:41 -0400 Subject: [PATCH] Use atomic operation --- .../src/Unix/Linux/NetDriver/sheep_net.c | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/BasiliskII/src/Unix/Linux/NetDriver/sheep_net.c b/BasiliskII/src/Unix/Linux/NetDriver/sheep_net.c index 5b36170f..2e3ead5e 100644 --- a/BasiliskII/src/Unix/Linux/NetDriver/sheep_net.c +++ b/BasiliskII/src/Unix/Linux/NetDriver/sheep_net.c @@ -158,7 +158,7 @@ struct SheepVars { char eth_addr[6]; /* Hardware address of the Ethernet card */ char fake_addr[6]; /* Local faked hardware address (what SheepShaver sees) */ #ifdef LINUX_3_15 - int got_packet; + atomic_t got_packet; #endif }; @@ -396,14 +396,10 @@ static ssize_t sheep_net_read(struct file *f, char *buf, size_t count, loff_t *o if (skb != NULL || (f->f_flags & O_NONBLOCK)) break; - /*packet is not available*/ - #ifdef LINUX_3_15 - v->got_packet = 0; - #endif - /* No packet in queue and in blocking mode, so block */ #ifdef LINUX_3_15 - wait_event_interruptible(v->wait, v->got_packet == 1); + atomic_set(&v->got_packet, 0); + wait_event_interruptible(v->wait, atomic_read(&v->got_packet)); #else interruptible_sleep_on(&v->wait); #endif @@ -746,12 +742,18 @@ static int sheep_net_receiver(struct sk_buff *skb, struct net_device *dev, struc /* Enqueue packet */ skb_queue_tail(&v->queue, skb); + /* Unblock blocked read */ #ifdef LINUX_3_15 - v->got_packet = 1; - #endif - /* Unblock blocked read */ - wake_up(&v->wait); + atomic_set(&v->got_packet, 1); + + wake_up_interruptible(&v->wait); + + #else + + wake_up(&v->wait); + + #endif return 0; drop: