[sheepdog] [PATCH] introduce intcmp to simplify codes
Liu Yuan
namei.unix at gmail.com
Fri Aug 2 11:16:28 CEST 2013
On Fri, Aug 02, 2013 at 06:11:41PM +0900, MORITA Kazutaka wrote:
> From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
>
> Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
> ---
> include/sheep.h | 12 ++----------
> include/util.h | 8 ++++++++
> lib/event.c | 7 +------
> sheep/cluster/corosync.c | 4 ++--
> sheep/md.c | 6 +-----
> sheep/recovery.c | 6 +-----
> 6 files changed, 15 insertions(+), 28 deletions(-)
>
> diff --git a/include/sheep.h b/include/sheep.h
> index 646522c..e3f7755 100644
> --- a/include/sheep.h
> +++ b/include/sheep.h
> @@ -252,11 +252,7 @@ static inline int node_id_cmp(const struct node_id *node1,
> if (cmp != 0)
> return cmp;
>
> - if (node1->port < node2->port)
> - return -1;
> - if (node1->port > node2->port)
> - return 1;
> - return 0;
> + return intcmp(node1->port, node2->port);
> }
>
> static inline int node_cmp(const struct sd_node *node1,
> @@ -273,11 +269,7 @@ static inline bool node_eq(const struct sd_node *a, const struct sd_node *b)
> static inline int vnode_cmp(const struct sd_vnode *node1,
> const struct sd_vnode *node2)
> {
> - if (node1->id < node2->id)
> - return -1;
> - if (node1->id > node2->id)
> - return 1;
> - return 0;
> + return intcmp(node1->id, node2->id);
> }
>
> static inline int nodes_to_vnodes(struct sd_node *nodes, int nr,
> diff --git a/include/util.h b/include/util.h
> index aa5341e..82082c2 100644
> --- a/include/util.h
> +++ b/include/util.h
> @@ -71,6 +71,14 @@ static inline void *zalloc(size_t size)
> return calloc(1, size);
> }
>
> +#define intcmp(x, y) \
> +({ \
> + typeof(x) _x = (x); \
> + typeof(y) _y = (y); \
> + (void) (&_x == &_y); \
> + _x < _y ? -1 : _x > _y ? 1 : 0; \
> +})
> +
>
Please document what intcmp returns in the source
Thanks
Yuan
More information about the sheepdog
mailing list