summaryrefslogtreecommitdiffstats
path: root/runtime/runtime.h
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2010-02-15 21:27:37 -0800
committerJosh Stone <jistone@redhat.com>2010-02-16 15:55:01 -0800
commitd9f58253e30ea80e57d8f54e41e9cd114cc13973 (patch)
tree557c38cd069499be0defe734595af161a166bd98 /runtime/runtime.h
parent4fa8e6497405fd4f121a3eee0c6d772aaeeef6d8 (diff)
downloadsystemtap-steved-d9f58253e30ea80e57d8f54e41e9cd114cc13973.tar.gz
systemtap-steved-d9f58253e30ea80e57d8f54e41e9cd114cc13973.tar.xz
systemtap-steved-d9f58253e30ea80e57d8f54e41e9cd114cc13973.zip
Use clamping to more easily normalize input values
The kernel has min/max/clamp macros to make range comparisons easier. Clamp is a newer invention, but we can define it for older kernels in terms of min and max.
Diffstat (limited to 'runtime/runtime.h')
-rw-r--r--runtime/runtime.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 91c48d57..c51520d0 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -50,6 +50,14 @@
#define stp_for_each_cpu(cpu) for_each_cpu_mask((cpu), cpu_possible_map)
#endif
+#ifndef clamp
+#define clamp(val, low, high) min(max(low, val), high)
+#endif
+
+#ifndef clamp_t
+#define clamp_t(type, val, low, high) min_t(type, max_t(type, low, val), high)
+#endif
+
static void _stp_dbug (const char *func, int line, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
static void _stp_error (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
static void _stp_warn (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));