linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Per Persson" <per.persson@gnosjo.pp.se>
To: <marcelo@conectiva.com.br>, <alan@redhat.com>
Cc: <linux-fsdevel@vger.kernel.org>
Subject: triple_down et al.
Date: Fri, 24 Jan 2003 21:40:42 +0100	[thread overview]
Message-ID: <002e01c2c3e8$e32a89c0$0e02a8c0@solveig> (raw)

Here's a patch I tried to get into the 2.4 series in autumn 2001. I was
however told that it was too close to the start of the 2.5 series.

The patch cleans up the "messy" triple_down code in fs.h.

  /Per


--- include/linux/fs.h.orig 2003-01-11 00:34:56.000000000 +0100
+++ include/linux/fs.h 2003-01-24 10:12:46.000000000 +0100
@@ -1564,14 +1564,25 @@
 /*
  * Whee.. Deadlock country. Happily there are only two VFS
  * operations that does this..
+ *
+ * {double,triple}_down modified by Per Persson
  */
+
+#define __exch(x,y)   \
+do {     \
+ typeof(x) __tmp__ = (x); \
+ (x) = (y);   \
+ (y) = __tmp__;   \
+} while(0)
+
+#define __sort(x,y)   \
+if((x) < (y))    \
+ __exch((x), (y))
+
 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 (s1 != s2)
+  __sort((ulong)s1, (ulong)s2); // s1 > s2
   down(s1);
  }
  down(s2);
@@ -1581,9 +1592,10 @@
  * 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).
+ *
+ * Cleaner and more efficient code than the original.
+ *     /Per
  */

 static inline void triple_down(struct semaphore *s1,
@@ -1591,34 +1603,18 @@
           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;
-   }
-  }
+  __sort((ulong)s1, (ulong)s2); // s1 > s2
+  __sort((ulong)s1, (ulong)s3); // s1 > s3
   down(s1);
- } else if ((unsigned long) s2 < (unsigned long) s3) {
-  struct semaphore *tmp = s3;
-  s3 = s2; s2 = tmp;
  }
+ __sort((ulong)s2, (ulong)s3);  // s2 > s3
  down(s2);
  down(s3);
 }

+#undef __sort
+#undef __exch
+
 static inline void double_up(struct semaphore *s1, struct semaphore *s2)
 {
  up(s1);



             reply	other threads:[~2003-01-24 20:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-24 20:40 Per Persson [this message]
2003-01-27 14:49 ` triple_down et al Alan Cox
2003-02-02  0:03   ` Matthew Wilcox

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='002e01c2c3e8$e32a89c0$0e02a8c0@solveig' \
    --to=per.persson@gnosjo.pp.se \
    --cc=alan@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=marcelo@conectiva.com.br \
    /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;
as well as URLs for NNTP newsgroup(s).