* [PATCH] triple_down in fs.h
@ 2001-10-02 19:42 Per Persson
0 siblings, 0 replies; 3+ messages in thread
From: Per Persson @ 2001-10-02 19:42 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 88 bytes --]
Cleaned up some code.
[PATCH of 2.4.10 attached]
Per Persson
per.persson@gnosjo.pp.se
[-- Attachment #2: fs.h.patch --]
[-- Type: application/octet-stream, Size: 2451 bytes --]
--- 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);
}
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH] triple_down in fs.h
@ 2001-10-18 13:10 Per Persson
0 siblings, 0 replies; 3+ messages in thread
From: Per Persson @ 2001-10-18 13:10 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 704 bytes --]
First, I'd like to send a thank to the Linux community from my father who
passed away this morning. He was very impressed by Linux and other free or
semi-free software like Samba, MySQL, GIMP and StarOffice.
Now to the patch:
I've made a couple of minor (but important?) changes in my patch of
{double,triple}_down in include/linux/fs.h.
Changes:
1) Added #undef's of my macros.
Thanks to Mitchell Blank Jr who proposed this change.
Also thanks to Yaroslav Popovitch who told me he had got an error caused
by the lack of #undef's.
2) Changed the names of the macros to further minimize the risk for name
collision; exch -> exch_vars, sort -> sort_vars.
Per Persson
per.persson@gnosjo.pp.se
[-- Attachment #2: fs.h.patch --]
[-- Type: application/octet-stream, Size: 2667 bytes --]
--- include/linux/fs.h.orig Sat Sep 29 22:10:21 2001
+++ include/linux/fs.h Mon Oct 8 13:03:24 2001
@@ -1476,14 +1476,27 @@
/*
* 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_vars(x,y) \
+do { \
+ typeof(x) __tmp__ = (x); \
+ (x) = (y); \
+ (y) = __tmp__; \
+ \
+ (void)(&(x) == &(y)) /* typecheck */ \
+} while(0)
+
+#define sort_vars(x,y) \
+if((x) > (y)) \
+ exch_vars((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_vars((ulong) s2, (ulong) s1); // s2 < s1
down(s1);
}
down(s2);
@@ -1493,9 +1506,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,33 +1518,17 @@
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_vars((ulong) s2, (ulong) s1); // s2 < s1
+ sort_vars((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_vars((ulong) s3, (ulong) s2); // s2 > s3
down(s2);
down(s3);
}
+
+#undef exch_vars
+#undef sort_vars
static inline void double_up(struct semaphore *s1, struct semaphore *s2)
{
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH] triple_down in fs.h
@ 2001-09-24 14:50 Per Persson
0 siblings, 0 replies; 3+ messages in thread
From: Per Persson @ 2001-09-24 14:50 UTC (permalink / raw)
To: linux-kernel
[-- 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);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-10-18 13:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-02 19:42 [PATCH] triple_down in fs.h Per Persson
-- strict thread matches above, loose matches on Subject: below --
2001-10-18 13:10 Per Persson
2001-09-24 14:50 Per Persson
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®