patch-1.3.77 linux/net/core/sock.c

Next file: linux/net/ipv4/af_inet.c
Previous file: linux/net/core/skbuff.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.76/linux/net/core/sock.c linux/net/core/sock.c
@@ -324,50 +324,32 @@
   	return(0);
 }
 
-
 struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force, int priority)
 {
-	if (sk) 
-	{
-		if (sk->wmem_alloc + size < sk->sndbuf || force) 
-		{
-			struct sk_buff * c = alloc_skb(size, priority);
-			if (c) 
-			{
-				unsigned long flags;
-				save_flags(flags);
-				cli();
-				sk->wmem_alloc+= c->truesize;
-				restore_flags(flags); /* was sti(); */
-			}
-			return c;
+	if (sk) {
+		if (force || sk->wmem_alloc + size < sk->sndbuf) {
+			struct sk_buff * skb = alloc_skb(size, priority);
+			if (skb)
+				atomic_add(skb->truesize, &sk->wmem_alloc);
+			return skb;
 		}
-		return(NULL);
+		return NULL;
 	}
-	return(alloc_skb(size, priority));
+	return alloc_skb(size, priority);
 }
 
-
 struct sk_buff *sock_rmalloc(struct sock *sk, unsigned long size, int force, int priority)
 {
-	if (sk) 
-	{
-		if (sk->rmem_alloc + size < sk->rcvbuf || force) 
-		{
-			struct sk_buff *c = alloc_skb(size, priority);
-			if (c) 
-			{
-				unsigned long flags;
-				save_flags(flags);
-				cli();
-				sk->rmem_alloc += c->truesize;
-				restore_flags(flags); /* was sti(); */
-			}
-			return(c);
+	if (sk) {
+		if (force || sk->rmem_alloc + size < sk->rcvbuf) {
+			struct sk_buff *skb = alloc_skb(size, priority);
+			if (skb)
+				atomic_add(skb->truesize, &sk->rmem_alloc);
+			return skb;
 		}
-		return(NULL);
+		return NULL;
 	}
-	return(alloc_skb(size, priority));
+	return alloc_skb(size, priority);
 }
 
 
@@ -396,7 +378,7 @@
 			return(0);
 		if (sk->wmem_alloc >= sk->sndbuf)
 			return(0);
-		return(sk->sndbuf-sk->wmem_alloc );
+		return sk->sndbuf - sk->wmem_alloc;
 	}
 	return(0);
 }
@@ -411,14 +393,9 @@
 	kfree_skbmem(skb);
 	if (sk) 
 	{
-		unsigned long flags;
-		save_flags(flags);
-		cli();
-		sk->wmem_alloc -= s;
-		restore_flags(flags);
+		atomic_sub(s, &sk->wmem_alloc);
 		/* In case it might be waiting for more memory. */
 		sk->write_space(sk);
-		return;
 	}
 }
 
@@ -432,11 +409,7 @@
 	kfree_skbmem(skb);
 	if (sk) 
 	{
-		unsigned long flags;
-		save_flags(flags);
-		cli();
-		sk->rmem_alloc -= s;
-		restore_flags(flags);
+		atomic_sub(s, &sk->rmem_alloc);
 	}
 }
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this