summaryrefslogtreecommitdiff
path: root/src/common/util.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-03-06 20:25:44 +0000
committerNick Mathewson <nickm@torproject.org>2007-03-06 20:25:44 +0000
commit5d1bee87ffe3dcdaa9e7960b0fed836aa1d01b9b (patch)
tree5f9aea61df183fd3a5b88223789babc1fb859a67 /src/common/util.h
parentc9e2766e7598a669d3acf3ae0e45e8be8b5945b0 (diff)
downloadtor-5d1bee87ffe3dcdaa9e7960b0fed836aa1d01b9b.tar.gz
tor-5d1bee87ffe3dcdaa9e7960b0fed836aa1d01b9b.zip
r12468@Kushana: nickm | 2007-03-06 15:24:00 -0500
More unit tests: gcov is fun. svn:r9748
Diffstat (limited to 'src/common/util.h')
-rw-r--r--src/common/util.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/common/util.h b/src/common/util.h
index 5d9a16030d..9f37e6ad3f 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -41,7 +41,7 @@
#ifdef __GNUC__
/** Macro: evaluate the expression x, which we expect to be false.
* Used to hint the compiler that a branch won't be taken. */
-#define PREDICT_FALSE(x) PREDICT((x) == ((typeof(x)) 0), 0)
+#define PREDICT_FALSE(x) PREDICT_UNLIKELY((x) == ((typeof(x)) 0))
#else
#define PREDICT_FALSE(x) !(x)
#endif
@@ -85,14 +85,18 @@ void _tor_free(void *mem);
extern int dmalloc_free(const char *file, const int line, void *pnt,
const int func_id);
#define tor_free(p) do { \
- if (PREDICT((p)!=NULL, 1)) { \
+ if (PREDICT_LIKELY((p)!=NULL)) { \
dmalloc_free(_SHORT_FILE_, __LINE__, (p), 0); \
(p)=NULL; \
} \
} while (0)
#else
-#define tor_free(p) do { if (PREDICT((p)!=NULL,1)) { free(p); (p)=NULL;} } \
- while (0)
+#define tor_free(p) do { \
+ if (PREDICT_LIKELY((p)!=NULL)) { \
+ free(p); \
+ (p)=NULL; \
+ } \
+ } while (0)
#endif
#define tor_malloc(size) _tor_malloc(size DMALLOC_ARGS)
@@ -172,10 +176,10 @@ void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen);
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen);
/* Time helpers */
-long tv_udiff(struct timeval *start, struct timeval *end);
+long tv_udiff(const struct timeval *start, const struct timeval *end);
void tv_addms(struct timeval *a, long ms);
-void tv_add(struct timeval *a, struct timeval *b);
-int tv_cmp(struct timeval *a, struct timeval *b);
+void tv_add(struct timeval *a, const struct timeval *b);
+int tv_cmp(const struct timeval *a, const struct timeval *b);
time_t tor_timegm(struct tm *tm);
#define RFC1123_TIME_LEN 29
void format_rfc1123_time(char *buf, time_t t);