Commit 7685e367 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

first sketch of macros

parents
#ifndef __MOCHI_ERROR_UTILS_H
#define __MOCHI_ERROR_UTILS_H
typedef uint64_t mochi_return_t;
/**
* Indicates that the error is produced by a server.
* This construct should be the most outer one, e.g:
* MOCHI_SERVER_ERROR(MOCHI_MERCURY_ERROR(X)), not
* MOCHI_MERCURY_ERROR(MOCHI_SERVER_ERROR(X)).
*/
#define MOCHI_SERVER_ERROR(_error) (_error) | (1 << (sizeof(mochi_return_t)-1))
/**
* Returns a non-zero value if the provided error is
* a server-side error.
*/
#define MOCHI_IS_SERVER_ERROR(_error) (_error) & (1 << (sizeof(mochi_return_t)-1))
/**
* Converts a Mercury error into a Mochi error.
*/
#define MOCHI_MERCURY_ERROR(_hg_error) \
(((mochi_return_t)(_hg_error)) << 56)
/**
* Returns a non-zero value if the provided error
* includes a Mercury error code.
*/
#define MOCHI_HAS_MERCURY_ERROR(_error) \
((_error) & (31 << 56))
/**
* Converts a Mochi error into its underlying Mercury error.
*/
#define MOCHI_GET_MERCURY_ERROR(_error) \
((hg_return_t)(((_error) & (31 << 56)) >> 56))
/**
* Converts an Argobots error into a Mochi error.
*/
#define MOCHI_ARGOBOTS_ERROR(_abt_error) \
(((mochi_return_t)(_abt_error)) << 48)
/**
* Returns a non-zero value if the provided error
* includes an Argobots error code.
*/
#define MOCHI_HAS_ARGOBOTS_ERROR(_error) \
((_error) & (31 << 48))
/**
* Converts a Mochi error into its underlying Argobots error.
*/
#define MOCHI_GET_ARGOBOTS_ERROR(_error) \
((int)(((_error) & (31 << 48)) >> 48))
/**
* Creates a Mochi error from a service error.
*/
#define MOCHI_SERVICE_ERROR(_error) \
((mochi_return_t)(_error))
/**
* Converts a Mochi error into the most recent service error.
*/
#define MOCHI_GET_SERVICE_ERROR(_error) \
((_error) & 8)
/**
* Creates a Mochi error from an existing parent error and a
* new service error.
*/
#define MOCHI_NESTED_SERVICE_ERROR(_parent_error, _error) \
( \
((_parent_error) & (((1 << 32) - 1) << 32)) \
| (((_parent_error) << 8) & ((1 << 32) -1)) \
| (_error) \
)
/**
* Get the parent service error from provided error.
*/
#define MOCHI_GET_PARENT_SERVICE_ERROR(_error) \
( \
((_parent_error) & (((1 << 32) - 1) << 32)) \
| (((_parent_error) & ((1 << 32) -1)) >> 8) \
)
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment