diff mbox

[v3] Add ODP_ABORT

Message ID 1412015986-4499-1-git-send-email-mike.holmes@linaro.org
State Accepted
Commit 32e78e10572fb411e9369dfeef0e6daab8bff90a
Headers show

Commit Message

Mike Holmes Sept. 29, 2014, 6:39 p.m. UTC
Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
v3:
Fix missing brace

 platform/linux-generic/include/api/odp_debug.h | 16 ++++++++++++++--
 platform/linux-generic/odp_buffer_pool.c       | 26 ++++++++++----------------
 platform/linux-generic/odp_time.c              |  3 +--
 3 files changed, 25 insertions(+), 20 deletions(-)

Comments

Maxim Uvarov Sept. 30, 2014, 1:55 p.m. UTC | #1
Merged, thanks!

Maxim.

On 09/29/2014 10:39 PM, Mike Holmes wrote:
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> ---
> v3:
> Fix missing brace
>
>   platform/linux-generic/include/api/odp_debug.h | 16 ++++++++++++++--
>   platform/linux-generic/odp_buffer_pool.c       | 26 ++++++++++----------------
>   platform/linux-generic/odp_time.c              |  3 +--
>   3 files changed, 25 insertions(+), 20 deletions(-)
>
> diff --git a/platform/linux-generic/include/api/odp_debug.h b/platform/linux-generic/include/api/odp_debug.h
> index e8f6003..344b0a9 100644
> --- a/platform/linux-generic/include/api/odp_debug.h
> +++ b/platform/linux-generic/include/api/odp_debug.h
> @@ -13,6 +13,7 @@
>   #define ODP_DEBUG_H_
>   
>   #include <stdio.h>
> +#include <stdlib.h>
>   
>   #ifdef __cplusplus
>   extern "C" {
> @@ -76,8 +77,19 @@ extern "C" {
>    * Print output to stderr (file, line and function).
>    */
>   #define ODP_ERR(fmt, ...) \
> -	fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
> -		__LINE__, __func__, ##__VA_ARGS__)
> +do { fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
> +	__LINE__, __func__, ##__VA_ARGS__); \
> +} while (0)
> +
> +/**
> + * Print output to stderr (file, line and function),
> + * then abort.
> + */
> +#define ODP_ABORT(fmt, ...) \
> +do { fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
> +	__LINE__, __func__, ##__VA_ARGS__); \
> +	abort(); \
> +} while (0)
>   
>   #ifdef __cplusplus
>   }
> diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
> index 4d9ff45..a48d7d6 100644
> --- a/platform/linux-generic/odp_buffer_pool.c
> +++ b/platform/linux-generic/odp_buffer_pool.c
> @@ -98,10 +98,8 @@ static inline void set_handle(odp_buffer_hdr_t *hdr,
>   	odp_buffer_pool_t pool_hdl = pool->s.pool_hdl;
>   	uint32_t          pool_id  = pool_handle_to_index(pool_hdl);
>   
> -	if (pool_id >= ODP_CONFIG_BUFFER_POOLS) {
> -		ODP_ERR("set_handle: Bad pool handle %u\n", pool_hdl);
> -		exit(0);
> -	}
> +	if (pool_id >= ODP_CONFIG_BUFFER_POOLS)
> +		ODP_ABORT("set_handle: Bad pool handle %u\n", pool_hdl);
>   
>   	if (index > ODP_BUFFER_MAX_INDEX)
>   		ODP_ERR("set_handle: Bad buffer index\n");
> @@ -221,15 +219,13 @@ static void add_chunk(pool_entry_t *pool, odp_buffer_chunk_hdr_t *chunk_hdr)
>   static void check_align(pool_entry_t *pool, odp_buffer_hdr_t *hdr)
>   {
>   	if (!ODP_ALIGNED_CHECK_POWER_2(hdr->addr, pool->s.user_align)) {
> -		ODP_ERR("check_align: user data align error %p, align %zu\n",
> -			hdr->addr, pool->s.user_align);
> -		exit(0);
> +		ODP_ABORT("check_align: user data align error %p, align %zu\n",
> +			  hdr->addr, pool->s.user_align);
>   	}
>   
>   	if (!ODP_ALIGNED_CHECK_POWER_2(hdr, ODP_CACHE_LINE_SIZE)) {
> -		ODP_ERR("check_align: hdr align error %p, align %i\n",
> -			hdr, ODP_CACHE_LINE_SIZE);
> -		exit(0);
> +		ODP_ABORT("check_align: hdr align error %p, align %i\n",
> +			  hdr, ODP_CACHE_LINE_SIZE);
>   	}
>   }
>   
> @@ -267,8 +263,7 @@ static void fill_hdr(void *ptr, pool_entry_t *pool, uint32_t index,
>   		buf_data = any_hdr->buf_data;
>   		break;
>   	default:
> -		ODP_ERR("Bad buffer type\n");
> -		exit(0);
> +		ODP_ABORT("Bad buffer type\n");
>   	}
>   
>   	memset(hdr, 0, size);
> @@ -314,10 +309,9 @@ static void link_bufs(pool_entry_t *pool)
>   		hdr_size = sizeof(odp_timeout_hdr_t);
>   	} else if (buf_type == ODP_BUFFER_TYPE_ANY) {
>   		hdr_size = sizeof(odp_any_buffer_hdr_t);
> -	} else {
> -		ODP_ERR("odp_buffer_pool_create: Bad type %i\n", buf_type);
> -		exit(0);
> -	}
> +	} else
> +		ODP_ABORT("odp_buffer_pool_create: Bad type %i\n", buf_type);
> +
>   
>   	/* Chunk must fit into buffer data area.*/
>   	min_size = sizeof(odp_buffer_chunk_hdr_t) - hdr_size;
> diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c
> index 181294a..faece0e 100644
> --- a/platform/linux-generic/odp_time.c
> +++ b/platform/linux-generic/odp_time.c
> @@ -59,8 +59,7 @@ uint64_t odp_time_get_cycles(void)
>   	ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time);
>   
>   	if (ret != 0) {
> -		ODP_ERR("clock_gettime failed\n");
> -		exit(EXIT_FAILURE);
> +		ODP_ABORT("clock_gettime failed\n");
>   	}
>   
>   	hz  = odp_sys_cpu_hz();
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_debug.h b/platform/linux-generic/include/api/odp_debug.h
index e8f6003..344b0a9 100644
--- a/platform/linux-generic/include/api/odp_debug.h
+++ b/platform/linux-generic/include/api/odp_debug.h
@@ -13,6 +13,7 @@ 
 #define ODP_DEBUG_H_
 
 #include <stdio.h>
+#include <stdlib.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -76,8 +77,19 @@  extern "C" {
  * Print output to stderr (file, line and function).
  */
 #define ODP_ERR(fmt, ...) \
-	fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
-		__LINE__, __func__, ##__VA_ARGS__)
+do { fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
+	__LINE__, __func__, ##__VA_ARGS__); \
+} while (0)
+
+/**
+ * Print output to stderr (file, line and function),
+ * then abort.
+ */
+#define ODP_ABORT(fmt, ...) \
+do { fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
+	__LINE__, __func__, ##__VA_ARGS__); \
+	abort(); \
+} while (0)
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
index 4d9ff45..a48d7d6 100644
--- a/platform/linux-generic/odp_buffer_pool.c
+++ b/platform/linux-generic/odp_buffer_pool.c
@@ -98,10 +98,8 @@  static inline void set_handle(odp_buffer_hdr_t *hdr,
 	odp_buffer_pool_t pool_hdl = pool->s.pool_hdl;
 	uint32_t          pool_id  = pool_handle_to_index(pool_hdl);
 
-	if (pool_id >= ODP_CONFIG_BUFFER_POOLS) {
-		ODP_ERR("set_handle: Bad pool handle %u\n", pool_hdl);
-		exit(0);
-	}
+	if (pool_id >= ODP_CONFIG_BUFFER_POOLS)
+		ODP_ABORT("set_handle: Bad pool handle %u\n", pool_hdl);
 
 	if (index > ODP_BUFFER_MAX_INDEX)
 		ODP_ERR("set_handle: Bad buffer index\n");
@@ -221,15 +219,13 @@  static void add_chunk(pool_entry_t *pool, odp_buffer_chunk_hdr_t *chunk_hdr)
 static void check_align(pool_entry_t *pool, odp_buffer_hdr_t *hdr)
 {
 	if (!ODP_ALIGNED_CHECK_POWER_2(hdr->addr, pool->s.user_align)) {
-		ODP_ERR("check_align: user data align error %p, align %zu\n",
-			hdr->addr, pool->s.user_align);
-		exit(0);
+		ODP_ABORT("check_align: user data align error %p, align %zu\n",
+			  hdr->addr, pool->s.user_align);
 	}
 
 	if (!ODP_ALIGNED_CHECK_POWER_2(hdr, ODP_CACHE_LINE_SIZE)) {
-		ODP_ERR("check_align: hdr align error %p, align %i\n",
-			hdr, ODP_CACHE_LINE_SIZE);
-		exit(0);
+		ODP_ABORT("check_align: hdr align error %p, align %i\n",
+			  hdr, ODP_CACHE_LINE_SIZE);
 	}
 }
 
@@ -267,8 +263,7 @@  static void fill_hdr(void *ptr, pool_entry_t *pool, uint32_t index,
 		buf_data = any_hdr->buf_data;
 		break;
 	default:
-		ODP_ERR("Bad buffer type\n");
-		exit(0);
+		ODP_ABORT("Bad buffer type\n");
 	}
 
 	memset(hdr, 0, size);
@@ -314,10 +309,9 @@  static void link_bufs(pool_entry_t *pool)
 		hdr_size = sizeof(odp_timeout_hdr_t);
 	} else if (buf_type == ODP_BUFFER_TYPE_ANY) {
 		hdr_size = sizeof(odp_any_buffer_hdr_t);
-	} else {
-		ODP_ERR("odp_buffer_pool_create: Bad type %i\n", buf_type);
-		exit(0);
-	}
+	} else
+		ODP_ABORT("odp_buffer_pool_create: Bad type %i\n", buf_type);
+
 
 	/* Chunk must fit into buffer data area.*/
 	min_size = sizeof(odp_buffer_chunk_hdr_t) - hdr_size;
diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c
index 181294a..faece0e 100644
--- a/platform/linux-generic/odp_time.c
+++ b/platform/linux-generic/odp_time.c
@@ -59,8 +59,7 @@  uint64_t odp_time_get_cycles(void)
 	ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time);
 
 	if (ret != 0) {
-		ODP_ERR("clock_gettime failed\n");
-		exit(EXIT_FAILURE);
+		ODP_ABORT("clock_gettime failed\n");
 	}
 
 	hz  = odp_sys_cpu_hz();