fifo: use minmax.h instead of rolling its own min/max
authorJens Axboe <axboe@fb.com>
Tue, 23 Sep 2014 16:35:49 +0000 (10:35 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 23 Sep 2014 16:35:49 +0000 (10:35 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
fifo.h
minmax.h

diff --git a/fifo.h b/fifo.h
index 749136530a2c5410867f10caf672c155949daa2f..4b775b0bfc1942eb3f7199968e28678a93835796 100644 (file)
--- a/fifo.h
+++ b/fifo.h
@@ -1,3 +1,5 @@
+#ifndef FIO_FIFO_H
+#define FIO_FIFO_H
 /*
  * A simple FIFO implementation.
  *
 /*
  * A simple FIFO implementation.
  *
@@ -18,6 +20,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  */
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  */
+#include "minmax.h"
+
 struct fifo {
        unsigned char *buffer;  /* the buffer holding the data */
        unsigned int size;      /* the size of the allocated buffer */
 struct fifo {
        unsigned char *buffer;  /* the buffer holding the data */
        unsigned int size;      /* the size of the allocated buffer */
@@ -40,19 +44,4 @@ static inline unsigned int fifo_room(struct fifo *fifo)
        return fifo->size - fifo->in + fifo->out;
 }
 
        return fifo->size - fifo->in + fifo->out;
 }
 
-#ifndef min
-#define min(x,y) ({ \
-       typeof(x) _x = (x);     \
-       typeof(y) _y = (y);     \
-       (void) (&_x == &_y);            \
-       _x < _y ? _x : _y; })
-#endif
-
-#ifndef max
-#define max(x,y) ({ \
-       typeof(x) _x = (x);     \
-       typeof(y) _y = (y);     \
-       (void) (&_x == &_y);            \
-       _x > _y ? _x : _y; })
-
 #endif
 #endif
index e5c2f584714fe877d7b119d16683f0a3cdd7146f..97957c8874e2e68b6e84a318d70c7c62670501bf 100644 (file)
--- a/minmax.h
+++ b/minmax.h
@@ -2,10 +2,19 @@
 #define FIO_MIN_MAX_H
 
 #ifndef min
 #define FIO_MIN_MAX_H
 
 #ifndef min
-#define min(a, b)      ((a) < (b) ? (a) : (b))
+#define min(x,y) ({ \
+       typeof(x) _x = (x);     \
+       typeof(y) _y = (y);     \
+       (void) (&_x == &_y);            \
+       _x < _y ? _x : _y; })
 #endif
 #endif
+
 #ifndef max
 #ifndef max
-#define max(a, b)      ((a) > (b) ? (a) : (b))
+#define max(x,y) ({ \
+       typeof(x) _x = (x);     \
+       typeof(y) _y = (y);     \
+       (void) (&_x == &_y);            \
+       _x > _y ? _x : _y; })
 #endif
 
 #endif
 #endif
 
 #endif