aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmdsserver/macros.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-18 08:57:51 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-18 08:57:51 +0200
commit9b72a7e795d74e4dceec516d592609de12b69e85 (patch)
tree899f5a0a6e455969ab367caf76205e25c87c39f9 /src/libmdsserver/macros.h
parentm (diff)
downloadmds-9b72a7e795d74e4dceec516d592609de12b69e85.tar.gz
mds-9b72a7e795d74e4dceec516d592609de12b69e85.tar.bz2
mds-9b72a7e795d74e4dceec516d592609de12b69e85.tar.xz
reduce code complexity
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/libmdsserver/macros.h')
-rw-r--r--src/libmdsserver/macros.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h
index 1623950..95f705f 100644
--- a/src/libmdsserver/macros.h
+++ b/src/libmdsserver/macros.h
@@ -77,6 +77,21 @@
instructions \
errno = pthread_mutex_unlock(&(mutex))
+/**
+ * Wrapper for `pthread_mutex_lock` and `pthread_mutex_unlock` with an embedded if-statement
+ *
+ * @param mutex:pthread_mutex_t The mutex
+ * @parma condition The condition to test
+ * @param instructions The instructions to run while the mutex is locked
+ */
+#define with_mutex_if(mutex, condition, instructions) \
+ errno = pthread_mutex_lock(&(mutex)); \
+ if (condition) \
+ { \
+ instructions \
+ } \
+ errno = pthread_mutex_unlock(&(mutex))
+
/**
* Return the maximum value of two values
@@ -296,6 +311,18 @@
/**
+ * `remalloc` wrapper that returns whether the allocation was not successful
+ *
+ * @param var The variable to which to assign the reallocation
+ * @param elements The number of elements to allocate
+ * @param type The data type of the elements for which to create an allocation
+ * @return :int Evaluates to true if an only if the allocation failed
+ */
+#define xrealloc(var, elements, type) \
+ ((var = realloc(var, (elements) * sizeof(type))) == NULL)
+
+
+/**
* Go to the label `pfail` if a condition is met
*
* @param CONDITION The condition