Skip to content

Commit f462fe0

Browse files
committed
opal,ompi: move container_of definition to its own header
Centralize container_of macro definition so that we don't have to define it everywhere. Signed-off-by: Wenduo Wang <[email protected]>
1 parent b4390af commit f462fe0

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

ompi/mca/mtl/ofi/mtl_ofi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "ompi/mca/mtl/mtl.h"
2525
#include "ompi/mca/mtl/base/base.h"
2626
#include "opal/datatype/opal_convertor.h"
27+
#include "opal/util/misc.h"
2728
#include "opal/util/show_help.h"
2829
#include "opal/util/printf.h"
2930

opal/mca/btl/usnic/btl_usnic.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "opal/class/opal_hash_table.h"
3636
#include "opal/util/alfg.h"
3737
#include "opal/util/event.h"
38+
#include "opal/util/misc.h"
3839
#include "opal_stdint.h"
3940

4041
#include "opal/mca/btl/base/base.h"
@@ -65,10 +66,6 @@ static inline uint64_t get_ticks(void)
6566
/* RNG buffer declaration */
6667
extern opal_rng_buff_t opal_btl_usnic_rand_buff;
6768

68-
#ifndef container_of
69-
# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member)))
70-
#endif
71-
7269
#ifndef max
7370
# define max(a, b) (((a) > (b)) ? (a) : (b))
7471
#endif

opal/util/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ headers = \
6363
if.h \
6464
keyval_parse.h \
6565
malloc.h \
66+
misc.h
6667
net.h \
6768
numtostr.h \
6869
opal_environ.h \

opal/util/bipartite_graph.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818
#include "opal/class/opal_pointer_array.h"
1919
#include "opal/constants.h"
2020
#include "opal/util/error.h"
21+
#include "opal/util/misc.h"
2122
#include "opal/util/output.h"
2223
#include "opal_stdint.h"
2324

2425
#include "opal/util/bipartite_graph.h"
2526
#include "opal/util/bipartite_graph_internal.h"
2627

27-
#ifndef container_of
28-
# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member)))
29-
#endif
30-
3128
#define GRAPH_DEBUG 0
3229
#if GRAPH_DEBUG
3330
# define GRAPH_DEBUG_OUT(args) printf(args)

opal/util/misc.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates.
3+
* All Rights reserved.
4+
* $COPYRIGHT$
5+
*
6+
* Additional copyrights may follow
7+
*
8+
* $HEADER$
9+
*/
10+
11+
/** @file:
12+
* Miscellaneous utilities
13+
*/
14+
15+
#ifndef OPAL_UTIL_MISC_H
16+
#define OPAL_UTIL_MISC_H
17+
18+
#include "opal/include/opal_config.h"
19+
20+
BEGIN_C_DECLS
21+
22+
#ifndef container_of
23+
# define container_of(ptr, type, member) ((type *) (((char *) (ptr)) - offsetof(type, member)))
24+
#endif
25+
26+
END_C_DECLS
27+
#endif

0 commit comments

Comments
 (0)