From 10014e35f8bd2ddaf5c74cf6bec0a42ec2acee86 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Thu, 4 Apr 2013 10:06:38 +0000
Subject: [PATCH] Merged some common definitions in two files, error.h and
 inline.h to avoid duplicates.

Former-commit-id: 6c12d97f251222dda4fc10fea1ef50aca667a52c
---
 src/atomic.h | 10 +---------
 src/cell.c   | 14 ++------------
 src/engine.c |  4 +---
 src/error.h  | 27 +++++++++++++++++++++++++++
 src/inline.h | 30 ++++++++++++++++++++++++++++++
 src/io.c     | 15 +++------------
 src/lock.h   |  9 +--------
 src/queue.c  | 12 ++----------
 src/runner.c |  4 +---
 src/runner.h | 10 +---------
 src/space.c  |  4 +---
 src/task.c   |  5 +----
 src/timers.h |  9 +--------
 13 files changed, 72 insertions(+), 81 deletions(-)
 create mode 100644 src/error.h
 create mode 100644 src/inline.h

diff --git a/src/atomic.h b/src/atomic.h
index 82b86eb4bc..882f4288df 100644
--- a/src/atomic.h
+++ b/src/atomic.h
@@ -18,15 +18,7 @@
  ******************************************************************************/
 
 
-
-/* Get the inlining right. */
-#ifndef INLINE
-# if __GNUC__ && !__GNUC_STDC_INLINE__
-#  define INLINE extern inline
-# else
-#  define INLINE inline
-# endif
-#endif
+#include "inline.h"
     
 #define atomic_add(v,i) __sync_fetch_and_add( v , i )
 #define atomic_inc(v) atomic_add( v , 1 )
diff --git a/src/cell.c b/src/cell.c
index cf99651293..b3612d6909 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -35,11 +35,8 @@
 #include "task.h"
 #include "part.h"
 #include "cell.h"
-
-
-/* Error macro. */
-#define error(s) { fprintf( stderr , "%s:%s:%i: %s\n" , __FILE__ , __FUNCTION__ , __LINE__ , s ); abort(); }
-
+#include "error.h"
+#include "inline.h"
 
 /* The timers. */
 ticks cell_timer[ cell_timer_count ];
@@ -56,13 +53,6 @@ ticks cell_timer[ cell_timer_count ];
     #define TIMER_TOC(t) timer_toc( t , tic )
     #define TIMER_TIC2 ticks tic2 = getticks();
     #define TIMER_TOC2(t) timer_toc( t , tic2 )
-    #ifndef INLINE
-    # if __GNUC__ && !__GNUC_STDC_INLINE__
-    #  define INLINE extern inline
-    # else
-    #  define INLINE inline
-    # endif
-    #endif
     INLINE static ticks timer_toc ( int t , ticks tic ) {
         ticks d = (getticks() - tic);
         __sync_add_and_fetch( &cell_timer[t] , d );
diff --git a/src/engine.c b/src/engine.c
index 528e6d2fd0..c649d00c7a 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -46,9 +46,7 @@
 #include "engine.h"
 #include "runner.h"
 #include "runner_iact.h"
-
-/* Error macro. */
-#define error(s) { fprintf( stderr , "%s:%s:%i: %s\n" , __FILE__ , __FUNCTION__ , __LINE__ , s ); abort(); }
+#include "error.h"
 
 /* Convert cell location to ID. */
 #define cell_getid( cdim , i , j , k ) ( (int)(k) + (cdim)[2]*( (int)(j) + (cdim)[1]*(int)(i) ) )
diff --git a/src/error.h b/src/error.h
new file mode 100644
index 0000000000..4d4aa5c76c
--- /dev/null
+++ b/src/error.h
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * This file is part of SWIFT.
+ * Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk),
+ *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk).
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ ******************************************************************************/
+
+#include <stdio.h>
+
+/**
+ * @brief Error macro. Prints the message given in argument and aborts.
+ *
+ */
+#define error(s) { fprintf( stderr , "%s:%s():%i: %s\n" , __FILE__ , __FUNCTION__ , __LINE__ , s ); abort(); }
diff --git a/src/inline.h b/src/inline.h
new file mode 100644
index 0000000000..a9b3059fe7
--- /dev/null
+++ b/src/inline.h
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * This file is part of SWIFT.
+ * Coypright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk),
+ *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk).
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ ******************************************************************************/
+
+/**
+ * @brief Defines inline 
+ */
+#ifndef INLINE
+# if __GNUC__ && !__GNUC_STDC_INLINE__
+#  define INLINE extern inline
+# else
+#  define INLINE inline
+# endif
+#endif
diff --git a/src/io.c b/src/io.c
index e8c57a256c..4a27d59490 100644
--- a/src/io.c
+++ b/src/io.c
@@ -37,12 +37,7 @@
 #include "part.h"
 #include "space.h"
 #include "engine.h"
-
-/**
- * @brief Error macro
- *
- */
-#define error(s) { fprintf( stderr , "%s:%s():%i: %s\n" , __FILE__ , __FUNCTION__ , __LINE__ , s ); abort(); }
+#include "error.h"
 
 /**
  * @brief The different types of data used in the GADGET IC files.
@@ -533,16 +528,12 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name, enu
  * @brief Writes an HDF5 output file (GADGET-3 type) with its XMF descriptor
  *
  * @param fileName The file to write.
- * @param dim The dimension of the volume written to the file.
- * @param parts The array of #part to write in the file.
- * @param N The number of particles to write.
- * @param periodic 1 if the volume is periodic, 0 if not.
+ * @param e The engine containing all the system.
  *
  * Creates the HDF5 file fileName and writess the particles contained
- * in the parts array. If such a file already exists, it is erased and replaced
+ * in the engine. If such a file already exists, it is erased and replaced
  * by the new one.
  *
- *
  * Calls #error() if an error occurs.
  *
  */
diff --git a/src/lock.h b/src/lock.h
index efdd0aa94c..39f80bcdc5 100644
--- a/src/lock.h
+++ b/src/lock.h
@@ -19,14 +19,7 @@
 
 
 
-/* Get the inlining right. */
-#ifndef INLINE
-# if __GNUC__ && !__GNUC_STDC_INLINE__
-#  define INLINE extern inline
-# else
-#  define INLINE inline
-# endif
-#endif
+#include "inline.h"
     
 #ifdef PTHREAD_LOCK
     #define lock_type pthread_spinlock_t
diff --git a/src/queue.c b/src/queue.c
index 757710ca52..d2c47b4d17 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -37,9 +37,8 @@
 #include "task.h"
 #include "cell.h"
 #include "queue.h"
-
-/* Error macro. */
-#define error(s) { fprintf( stderr , "%s:%s:%i: %s\n" , __FILE__ , __FUNCTION__ , __LINE__ , s ); abort(); }
+#include "error.h"
+#include "inline.h"
 
 /* Define the timer macros. */
 #ifdef TIMER_VERBOSE
@@ -52,13 +51,6 @@
     #define TIMER_TOC(t) timer_toc( t , tic )
     #define TIMER_TIC2 ticks tic2 = getticks();
     #define TIMER_TOC2(t) timer_toc( t , tic2 )
-    #ifndef INLINE
-    # if __GNUC__ && !__GNUC_STDC_INLINE__
-    #  define INLINE extern inline
-    # else
-    #  define INLINE inline
-    # endif
-    #endif
     INLINE static ticks timer_toc ( int t , ticks tic ) {
         ticks d = (getticks() - tic);
         __sync_add_and_fetch( &queue_timer[t] , d );
diff --git a/src/runner.c b/src/runner.c
index 8fa2d2fbed..adbf48ddd2 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -44,9 +44,7 @@
 #include "engine.h"
 #include "runner.h"
 #include "runner_iact.h"
-
-/* Error macro. */
-#define error(s) { fprintf( stderr , "%s:%s:%i: %s\n" , __FILE__ , __FUNCTION__ , __LINE__ , s ); abort(); }
+#include "error.h"
 
 /* Convert cell location to ID. */
 #define cell_getid( cdim , i , j , k ) ( (int)(k) + (cdim)[2]*( (int)(j) + (cdim)[1]*(int)(i) ) )
diff --git a/src/runner.h b/src/runner.h
index f9a8cfd6b0..58ecf128f5 100644
--- a/src/runner.h
+++ b/src/runner.h
@@ -17,6 +17,7 @@
  * 
  ******************************************************************************/
 
+#include "inline.h"
 
 /* SID stuff. */
 extern const char runner_flip[];
@@ -51,15 +52,6 @@ long long int runner_hist_bins[ runner_hist_N ];
 #define runner_hist_hit( x ) __sync_add_and_fetch( &runner_hist_bins[ (int)fmax( 0.0 , fmin( runner_hist_N-1 , ((x) - runner_hist_a) / (runner_hist_b - runner_hist_a) * runner_hist_N ) ) ] , 1 )
 
 
-/* Get the inlining right. */
-#ifndef INLINE
-# if __GNUC__ && !__GNUC_STDC_INLINE__
-#  define INLINE extern inline
-# else
-#  define INLINE inline
-# endif
-#endif
-
 
 /* A struct representing a runner's thread and its data. */
 struct runner {
diff --git a/src/space.c b/src/space.c
index 606ebe4387..08ac0b81e2 100644
--- a/src/space.c
+++ b/src/space.c
@@ -38,9 +38,7 @@
 #include "cell.h"
 #include "space.h"
 #include "runner.h"
-
-/* Error macro. */
-#define error(s) { fprintf( stderr , "%s:%s:%i: %s\n" , __FILE__ , __FUNCTION__ , __LINE__ , s ); abort(); }
+#include "error.h"
 
 /* Split size. */
 int space_splitsize = space_splitsize_default;
diff --git a/src/task.c b/src/task.c
index 8ac476043f..da5eb3190d 100644
--- a/src/task.c
+++ b/src/task.c
@@ -35,14 +35,11 @@
 #include "cycle.h"
 #include "lock.h"
 #include "task.h"
-
+#include "error.h"
 
 /* Task type names. */
 const char *taskID_names[task_type_count] = { "none" , "sort" , "self" , "pair" , "sub" , "ghost" };
 
-/* Error macro. */
-#define error(s) { fprintf( stderr , "%s:%s:%i: %s\n" , __FILE__ , __FUNCTION__ , __LINE__ , s ); abort(); }
-
 
 /**
  * @brief Remove all unlocks to tasks that are of the given type.
diff --git a/src/timers.h b/src/timers.h
index a2e50a0737..eb83b6f43a 100644
--- a/src/timers.h
+++ b/src/timers.h
@@ -17,7 +17,7 @@
  * 
  ******************************************************************************/
 
-
+#include "inline.h"
 
 /* The timers themselves. */
 enum {
@@ -62,13 +62,6 @@ extern ticks timers[ timer_count ];
     #define TIMER_TOC(t) timers_toc( t , tic )
     #define TIMER_TIC2 ticks tic2 = getticks();
     #define TIMER_TOC2(t) timers_toc( t , tic2 )
-    #ifndef INLINE
-    # if __GNUC__ && !__GNUC_STDC_INLINE__
-    #  define INLINE extern inline
-    # else
-    #  define INLINE inline
-    # endif
-    #endif
     INLINE static ticks timers_toc ( int t , ticks tic ) {
         ticks d = (getticks() - tic);
         __sync_add_and_fetch( &timers[t] , d );
-- 
GitLab