* triple_down et al.
@ 2003-01-24 20:40 Per Persson
2003-01-27 14:49 ` Alan Cox
0 siblings, 1 reply; 3+ messages in thread
From: Per Persson @ 2003-01-24 20:40 UTC (permalink / raw)
To: marcelo, alan; +Cc: linux-fsdevel
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);
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: triple_down et al.
2003-01-24 20:40 triple_down et al Per Persson
@ 2003-01-27 14:49 ` Alan Cox
2003-02-02 0:03 ` Matthew Wilcox
0 siblings, 1 reply; 3+ messages in thread
From: Alan Cox @ 2003-01-27 14:49 UTC (permalink / raw)
To: Per Persson; +Cc: marcelo, alan, linux-fsdevel
> 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.
Is this aimed at 2.4 or 2.5 ?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: triple_down et al.
2003-01-27 14:49 ` Alan Cox
@ 2003-02-02 0:03 ` Matthew Wilcox
0 siblings, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2003-02-02 0:03 UTC (permalink / raw)
To: Alan Cox; +Cc: Per Persson, marcelo, linux-fsdevel
On Mon, Jan 27, 2003 at 09:49:20AM -0500, Alan Cox wrote:
> > 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.
>
> 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.
--
"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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-02-02 0:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-24 20:40 triple_down et al Per Persson
2003-01-27 14:49 ` Alan Cox
2003-02-02 0:03 ` Matthew Wilcox
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).