--- include/linux/fs.h.orig Sat Sep 29 22:10:21 2001 +++ include/linux/fs.h Sat Sep 29 22:32:28 2001 @@ -1476,14 +1476,25 @@ /* * 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) + +#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; - } + sort((ulong) s2, (ulong) s1); // s2 < s1 down(s1); } down(s2); @@ -1493,9 +1504,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, @@ -1503,30 +1516,11 @@ 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) s2, (ulong) s1); // s2 < s1 + sort((ulong) s3, (ulong) s1); // s3 < s1 down(s1); - } else if ((unsigned long) s2 < (unsigned long) s3) { - struct semaphore *tmp = s3; - s3 = s2; s2 = tmp; } + sort((ulong) s3, (ulong) s2); // s2 > s3 down(s2); down(s3); }