]> xenbits.xensource.com Git - people/dstodden/blktap.git/commitdiff
Add some useful gccisms.
authorDaniel Stodden <daniel.stodden@citrix.com>
Tue, 15 Feb 2011 09:37:44 +0000 (01:37 -0800)
committerDaniel Stodden <daniel.stodden@citrix.com>
Tue, 15 Feb 2011 09:37:44 +0000 (01:37 -0800)
This are all named after the linux/compiler.h ones, not to get
uneccessarily creative.

Signed-off-by: Daniel Stodden <daniel.stodden@citrix.com>
drivers/tapdisk-interface.c
drivers/tapdisk-interface.h
drivers/tapdisk-log.c
drivers/tapdisk-log.h
drivers/tapdisk-stats.c
drivers/tapdisk.h
include/compiler.h [new file with mode: 0644]

index af3c3150265a86743d5b50449c2b1633c5d076c2..49471c423d7a2bf73f34a60284b0015a31deb915 100644 (file)
@@ -261,7 +261,7 @@ td_debug(td_image_t *image)
        tapdisk_driver_debug(driver);
 }
 
-void
+__noreturn void
 td_panic(void)
 {
        tlog_precious();
index 4ee5424d2ceb8594392bd638dba83cce45a15bfc..d6966819f50163c28f5d7bab3039005e00c56acb 100644 (file)
@@ -50,6 +50,6 @@ void td_prep_read(struct tiocb *, int, char *, size_t,
                  long long, td_queue_callback_t, void *);
 void td_prep_write(struct tiocb *, int, char *, size_t,
                   long long, td_queue_callback_t, void *);
-void td_panic(void) __attribute__((noreturn));
+void td_panic(void) __noreturn;
 
 #endif
index bf7cdd6b2cf557b109040e5c64d847ccffcec3db..e531c3f87c45c068c2396c635423049aa4e940cf 100644 (file)
@@ -65,8 +65,7 @@ tlog_logfile_vprint(const char *fmt, va_list ap)
        tapdisk_logfile_vprintf(&tapdisk_log.logfile, fmt, ap);
 }
 
-static void
-__attribute__((format(printf, 1, 2)))
+static void __printf(1, 2)
 tlog_logfile_print(const char *fmt, ...)
 {
        va_list ap;
index 678d78b68a959066d7cf11716efcbc3323c9eb24..eeac30494f748312776784bb9fa5424f98e29219 100644 (file)
 #define TLOG_DIR "/var/log/blktap"
 
 #include <stdarg.h>
+#include "compiler.h"
 
 int  tlog_open(const char *, int, int);
 void tlog_close(void);
 void tlog_precious(void);
 void tlog_vsyslog(int, const char *, va_list);
-void tlog_syslog(int, const char *, ...);
+void tlog_syslog(int, const char *, ...) __printf(2, 3);
 
 #include <syslog.h>
 
@@ -49,11 +50,8 @@ void tlog_syslog(int, const char *, ...);
 #define DPRINTF(_f, _a...) syslog(LOG_INFO, _f, ##_a)
 #define PERROR(_f, _a...)  EPRINTF(_f ": %s", ##_a, strerror(errno))
 
-void __tlog_write(int, const char *, ...)
-       __attribute__((format(printf, 2, 3)));
-
-void __tlog_error(const char *fmt, ...)
-       __attribute__((format(printf, 1, 2)));
+void __tlog_write(int, const char *, ...) __printf(2, 3);
+void __tlog_error(const char *fmt, ...) __printf(1, 2);
 
 #define tlog_write(_level, _f, _a...)                  \
        __tlog_write(_level, "%s: " _f,  __func__, ##_a)
index c073fa2af27be94bc2dd609a616b4fe29937a464..42f420de34ee3f8dfd64ddca843682058ff8eb35 100644 (file)
@@ -43,7 +43,7 @@ __stats_vsprintf(td_stats_t *st,
        st->pos += vsnprintf(st->pos, size, fmt, ap);
 }
 
-static void __attribute__((format (printf, 2, 3)))
+static void __printf(2, 3)
 __stats_sprintf(td_stats_t *st,
                     const char *fmt, ...)
 {
index d552b288e3ff774976cf5ea404b13a9367fa1b9e..eb454b46d4c2c228ba8e868e64a380ad8e75733d 100644 (file)
@@ -60,6 +60,7 @@
 #include <stdint.h>
 
 #include "list.h"
+#include "compiler.h"
 #include "tapdisk-log.h"
 #include "tapdisk-utils.h"
 #include "tapdisk-stats.h"
diff --git a/include/compiler.h b/include/compiler.h
new file mode 100644 (file)
index 0000000..2c39fbb
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef _BLKTAP_COMPILER_H
+#define _BLKTAP_COMPILER_H
+
+#ifdef __GNUC__
+#define likely(_cond)           __builtin_expect(!!(_cond), 1)
+#define unlikely(_cond)         __builtin_expect(!!(_cond), 0)
+#endif
+
+#ifndef likely
+#define likely(_cond)           (_cond)
+#endif
+
+#ifndef unlikely
+#define unlikely(_cond)         (_cond)
+#endif
+
+#ifdef __GNUC__
+#define __printf(_f, _a)        __attribute__((format (printf, _f, _a)))
+#define __scanf(_f, _a)         __attribute__((format (scanf, _f, _a)))
+#define __noreturn              __attribute__((noreturn))
+#endif
+
+#ifndef __printf
+#define __printf(_f, _a)
+#endif
+
+#ifndef __scanf
+#define __scanf(_f, _a)
+#endif
+
+#ifndef __noreturn
+#define __noreturn
+#endif
+
+#endif /* _BLKTAP_COMPILER_H */