triple_down et al.
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
linux/fs.h 2003-01-24 10:12:46.000000000 +0100 renamed from linux/fs.h.orig 2003-01-11 00:34:56.000000000 +0100 +16 -5
@@ -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);
Quoted 4 lines
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_downcode infs.h.
Is this aimed at 2.4 or 2.5 ?
Quoted 6 lines · Alan Cox
Quoted 4 lines
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_downcode infs.h.Is this aimed at 2.4 or 2.5 ?
Must be 2.4; 2.5 no longer needs (nor has) triple_down or double_down.
Signature · 3 lines
"It's not Hollywood. War is real, war is primarily not about defeat or victory, it is about death. I've seen thousands and thousands of dead bodies. Do you think I want to have an academic debate on this subject?" -- Robert Fisk