mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Per Persson" <per.persson@gnosjo.pp.se>
To: <linux-kernel@vger.kernel.org>
Subject: [PATCH] triple_down in fs.h
Date: Mon, 24 Sep 2001 16:50:41 +0200	[thread overview]
Message-ID: <NDBBJMOHILCIIKFHCBHAEEKGCAAA.per.persson@gnosjo.pp.se> (raw)

[-- Attachment #1: Type: text/plain, Size: 108 bytes --]

Cleaned up some code.
Hope I didn't break anything.

[PATCH attached]

Per Persson
per.persson@gnosjo.pp.se

[-- Attachment #2: fs.h.patch --]
[-- Type: application/octet-stream, Size: 2469 bytes --]

--- include/linux/fs.h.orig	Mon Sep 24 12:43:10 2001
+++ include/linux/fs.h	Mon Sep 24 16:37:39 2001
@@ -1441,14 +1441,22 @@
 /*
  * Whee.. Deadlock country. Happily there are only two VFS
  * operations that does this..
+ *
+ * {double,triple}_down modified by Per Persson in September, 2001
  */
+
+#define exch(x,y)			\
+do {					\
+	typeof(x) __tmp__ = (x);	\
+	(x) = (y);			\
+	(y) = __tmp__;			\
+} while(0)
+
 static inline void double_down(struct semaphore *s1, struct semaphore *s2)
 {
 	if (s1 != s2) {
-		if ((unsigned long) s1 < (unsigned long) s2) {
-			struct semaphore *tmp = s2;
-			s2 = s1; s1 = tmp;
-		}
+		if ((ulong) s1 < (ulong) s2)
+			exch(s1, s2);		// s1 > s2
 		down(s1);
 	}
 	down(s2);
@@ -1458,9 +1466,11 @@
  * Ewwwwwwww... _triple_ lock. We are guaranteed that the 3rd argument is
  * not equal to 1st and not equal to 2nd - the first case (target is parent of
  * source) would be already caught, the second is plain impossible (target is
- * its own parent and that case would be caught even earlier). Very messy.
- * I _think_ that it works, but no warranties - please, look it through.
- * Pox on bloody lusers who mandated overwriting rename() for directories...
+ * its own parent and that case would be caught even earlier).
+ *
+ * Hopefully it does the same thing as the old code,
+ * but in a cleaner and more efficient way.
+ *     /Per
  */
 
 static inline void triple_down(struct semaphore *s1,
@@ -1468,30 +1478,14 @@
 			       struct semaphore *s3)
 {
 	if (s1 != s2) {
-		if ((unsigned long) s1 < (unsigned long) s2) {
-			if ((unsigned long) s1 < (unsigned long) s3) {
-				struct semaphore *tmp = s3;
-				s3 = s1; s1 = tmp;
-			}
-			if ((unsigned long) s1 < (unsigned long) s2) {
-				struct semaphore *tmp = s2;
-				s2 = s1; s1 = tmp;
-			}
-		} else {
-			if ((unsigned long) s1 < (unsigned long) s3) {
-				struct semaphore *tmp = s3;
-				s3 = s1; s1 = tmp;
-			}
-			if ((unsigned long) s2 < (unsigned long) s3) {
-				struct semaphore *tmp = s3;
-				s3 = s2; s2 = tmp;
-			}
-		}
+		if ((ulong) s1 < (ulong) s2)
+			exch(s1, s2);		// s1 > s2
+		if ((ulong) s1 < (ulong) s3)
+			exch(s1, s3);		// s1 > s2,  s1 > s3
 		down(s1);
-	} else if ((unsigned long) s2 < (unsigned long) s3) {
-		struct semaphore *tmp = s3;
-		s3 = s2; s2 = tmp;
 	}
+	if((ulong) s2 < (ulong) s3)
+		exch(s2, s3);			// s2 > s3
 	down(s2);
 	down(s3);
 }

             reply	other threads:[~2001-09-24 14:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-24 14:50 Per Persson [this message]
2001-10-02 19:42 Per Persson
2001-10-18 13:10 Per Persson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=NDBBJMOHILCIIKFHCBHAEEKGCAAA.per.persson@gnosjo.pp.se \
    --to=per.persson@gnosjo.pp.se \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®