1
1

Refinement of Rainer's r13227 and r13228 (worked with Rainer, Ralph,

and George on these refinements):

 * Rename the static OBJ initializer macro to be
   OPAL_OBJ_STATIC_INIT(class)
 * Ensure that all static OBJ initializations get a refcount of 1
   (doesn't ''really'' matter, since they're static, it should never
   get to the point where the OBJ is DESTRUCTed, but more correct
   nonetheless)
 * Add a "magic number" to the OBJ when compiling with debug support.
   The magic number does some rudimentary support to ensure that
   you're operating on a valid OBJ (and fails an assertion if you're
   not).  Check to ensure that the memory contains the magic number
   when performing actions of OBJ's.  Also remove the magic number
   when DESTRUCTing OBJs, so that if, for example, an OBJ is
   DESTRUCTed more than once, we'll fail the magic number assert.

This commit was SVN r13338.

The following SVN revision numbers were found above:
  r13227 --> open-mpi/ompi@96030de97b
  r13228 --> open-mpi/ompi@c2e9075d29
Этот коммит содержится в:
Jeff Squyres 2007-01-27 13:44:03 +00:00
родитель 33dcb4f810
Коммит 3c5c8c3c4c
6 изменённых файлов: 67 добавлений и 38 удалений

Просмотреть файл

@ -10,6 +10,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2006 The Regents of the University of California. * Copyright (c) 2004-2006 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -40,12 +41,7 @@ int ompi_ddt_dfd = -1;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0 } 0, 0, 0, 0, 0, 0, 0, 0, 0 }
#define EMPTY_DATA(NAME) NULL, 0, "MPI_" # NAME, {0, 0, NULL}, {0, 0, NULL}, NULL, NULL, ZERO_DDT_ARRAY #define EMPTY_DATA(NAME) NULL, 0, "MPI_" # NAME, {0, 0, NULL}, {0, 0, NULL}, NULL, NULL, ZERO_DDT_ARRAY
#define BASEOBJ_DATA OPAL_OBJ_STATIC_INIT(ompi_datatype_t)
#if OMPI_ENABLE_DEBUG
# define BASEOBJ_DATA { OBJ_CLASS(ompi_datatype_t), 1, __FILE__, __LINE__ }
#else
# define BASEOBJ_DATA { OBJ_CLASS(ompi_datatype_t), 1 }
#endif /* OMPI_ENABLE_DEBUG */
/* Using this macro implies that at this point not all informations needed /* Using this macro implies that at this point not all informations needed
* to fill up the datatype are known. We fill them with zeros and then later * to fill up the datatype are known. We fill them with zeros and then later

Просмотреть файл

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -318,7 +319,7 @@ OBJ_CLASS_INSTANCE(ompi_op_t, opal_object_t,
OMPI_OP_FLAGS_FLOAT_ASSOC | OMPI_OP_FLAGS_COMMUTE) OMPI_OP_FLAGS_FLOAT_ASSOC | OMPI_OP_FLAGS_COMMUTE)
ompi_op_t ompi_mpi_op_null = { ompi_op_t ompi_mpi_op_null = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_OP_NULL", "MPI_OP_NULL",
FLAGS, FLAGS,
@ -337,7 +338,7 @@ ompi_op_t ompi_mpi_op_null = {
* C integer, Fortran integer, Floating point * C integer, Fortran integer, Floating point
*/ */
ompi_op_t ompi_mpi_op_max = { ompi_op_t ompi_mpi_op_max = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_MAX", "MPI_MAX",
FLAGS, FLAGS,
@ -355,7 +356,7 @@ ompi_op_t ompi_mpi_op_max = {
* MPI_OP_MIN * MPI_OP_MIN
*/ */
ompi_op_t ompi_mpi_op_min = { ompi_op_t ompi_mpi_op_min = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_MIN", "MPI_MIN",
FLAGS, FLAGS,
@ -373,7 +374,7 @@ ompi_op_t ompi_mpi_op_min = {
* MPI_OP_SUM * MPI_OP_SUM
*/ */
ompi_op_t ompi_mpi_op_sum = { ompi_op_t ompi_mpi_op_sum = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_SUM", "MPI_SUM",
FLAGS_NO_FLOAT, FLAGS_NO_FLOAT,
@ -391,7 +392,7 @@ ompi_op_t ompi_mpi_op_sum = {
* MPI_OP_PROD * MPI_OP_PROD
*/ */
ompi_op_t ompi_mpi_op_prod = { ompi_op_t ompi_mpi_op_prod = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_PROD", "MPI_PROD",
FLAGS_NO_FLOAT, FLAGS_NO_FLOAT,
@ -409,7 +410,7 @@ ompi_op_t ompi_mpi_op_prod = {
* MPI_OP_LAND * MPI_OP_LAND
*/ */
ompi_op_t ompi_mpi_op_land = { ompi_op_t ompi_mpi_op_land = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_LAND", "MPI_LAND",
FLAGS, FLAGS,
@ -427,7 +428,7 @@ ompi_op_t ompi_mpi_op_land = {
* MPI_OP_BAND * MPI_OP_BAND
*/ */
ompi_op_t ompi_mpi_op_band = { ompi_op_t ompi_mpi_op_band = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_BAND", "MPI_BAND",
FLAGS, FLAGS,
@ -445,7 +446,7 @@ ompi_op_t ompi_mpi_op_band = {
* MPI_OP_LOR * MPI_OP_LOR
*/ */
ompi_op_t ompi_mpi_op_lor = { ompi_op_t ompi_mpi_op_lor = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_LOR", "MPI_LOR",
FLAGS, FLAGS,
@ -463,7 +464,7 @@ ompi_op_t ompi_mpi_op_lor = {
* MPI_OP_BOR * MPI_OP_BOR
*/ */
ompi_op_t ompi_mpi_op_bor = { ompi_op_t ompi_mpi_op_bor = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_BOR", "MPI_BOR",
FLAGS, FLAGS,
@ -481,7 +482,7 @@ ompi_op_t ompi_mpi_op_bor = {
* MPI_OP_LXOR * MPI_OP_LXOR
*/ */
ompi_op_t ompi_mpi_op_lxor = { ompi_op_t ompi_mpi_op_lxor = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_LXOR", "MPI_LXOR",
FLAGS, FLAGS,
@ -499,7 +500,7 @@ ompi_op_t ompi_mpi_op_lxor = {
* MPI_OP_BXOR * MPI_OP_BXOR
*/ */
ompi_op_t ompi_mpi_op_bxor = { ompi_op_t ompi_mpi_op_bxor = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_BXOR", "MPI_BXOR",
FLAGS, FLAGS,
@ -517,7 +518,7 @@ ompi_op_t ompi_mpi_op_bxor = {
* MPI_OP_MAXLOC * MPI_OP_MAXLOC
*/ */
ompi_op_t ompi_mpi_op_maxloc = { ompi_op_t ompi_mpi_op_maxloc = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_MAXLOC", "MPI_MAXLOC",
(OMPI_OP_FLAGS_INTRINSIC | OMPI_OP_FLAGS_ASSOC | OMPI_OP_FLAGS_COMMUTE), (OMPI_OP_FLAGS_INTRINSIC | OMPI_OP_FLAGS_ASSOC | OMPI_OP_FLAGS_COMMUTE),
@ -535,7 +536,7 @@ ompi_op_t ompi_mpi_op_maxloc = {
* MPI_OP_MINLOC * MPI_OP_MINLOC
*/ */
ompi_op_t ompi_mpi_op_minloc = { ompi_op_t ompi_mpi_op_minloc = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_MINLOC", "MPI_MINLOC",
FLAGS, FLAGS,
@ -556,7 +557,7 @@ ompi_op_t ompi_mpi_op_minloc = {
* than ACCUMULATE) * than ACCUMULATE)
*/ */
ompi_op_t ompi_mpi_op_replace = { ompi_op_t ompi_mpi_op_replace = {
{ NULL, 0 }, OPAL_OBJ_STATIC_INIT(opal_object_t),
"MPI_REPLACE", "MPI_REPLACE",
FLAGS, FLAGS,

Просмотреть файл

@ -9,7 +9,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2006 The Regents of the University of California. * Copyright (c) 2004-2006 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2006 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2006-2007 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -109,7 +109,7 @@ int ompi_proc_init(void)
orte_std_cntr_t i, npeers, num_tokens; orte_std_cntr_t i, npeers, num_tokens;
orte_jobid_t jobid; orte_jobid_t jobid;
char *segment, **tokens; char *segment, **tokens;
orte_data_value_t value = { {OBJ_CLASS(orte_data_value_t),0}, ORTE_NULL, NULL}; orte_data_value_t value = ORTE_DATA_VALUE_EMPTY;
uint32_t ui32; uint32_t ui32;
int rc; int rc;

Просмотреть файл

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -138,6 +139,11 @@
#define END_C_DECLS /* empty */ #define END_C_DECLS /* empty */
#endif #endif
#if OMPI_ENABLE_DEBUG
/* Not quite 0xdeadbeef, in case someone else is using that... */
#define OPAL_OBJ_MAGIC_ID ((0xdeafbeed << 8) + 0xdeadbeef)
#endif
/* typedefs ***********************************************************/ /* typedefs ***********************************************************/
typedef struct opal_object_t opal_object_t; typedef struct opal_object_t opal_object_t;
@ -168,12 +174,28 @@ struct opal_class_t {
size_t cls_sizeof; /**< size of an object instance */ size_t cls_sizeof; /**< size of an object instance */
}; };
/**
* For static initializations of OBJects.
*
* @param NAME Name of the class to initialize
*/
#if OMPI_ENABLE_DEBUG
#define OPAL_OBJ_STATIC_INIT(BASE_CLASS) { OPAL_OBJ_MAGIC_ID, OBJ_CLASS(BASE_CLASS), 1, __FILE__, __LINE__ }
#else
#define OPAL_OBJ_STATIC_INIT(BASE_CLASS) { OBJ_CLASS(BASE_CLASS), 1 }
#endif
/** /**
* Base object. * Base object.
* *
* This is special and does not follow the pattern for other classes. * This is special and does not follow the pattern for other classes.
*/ */
struct opal_object_t { struct opal_object_t {
#if OMPI_ENABLE_DEBUG
/** Magic ID -- want this to be the very first item in the
struct's memory */
uint64_t obj_magic_id;
#endif
opal_class_t *obj_class; /**< class descriptor */ opal_class_t *obj_class; /**< class descriptor */
volatile int32_t obj_reference_count; /**< reference count */ volatile int32_t obj_reference_count; /**< reference count */
#if OMPI_ENABLE_DEBUG #if OMPI_ENABLE_DEBUG
@ -226,18 +248,6 @@ struct opal_object_t {
extern opal_class_t NAME ## _class extern opal_class_t NAME ## _class
/**
* Referring to the OBJ_CLASS, when initializing
*
* @param NAME Name of class
*/
#if OMPI_ENABLE_DEBUG
# define OBJ_CLASS_EMPTY(NAME) {OBJ_CLASS(NAME), 0, __FILE__, __LINE__}
#else
# define OBJ_CLASS_EMPTY(NAME) {OBJ_CLASS(NAME), 0}
#endif /* OMPI_ENABLE_DEBUG */
/** /**
* Create an object: dynamically allocate storage and run the class * Create an object: dynamically allocate storage and run the class
* constructor. * constructor.
@ -250,6 +260,7 @@ static inline opal_object_t *opal_obj_new(opal_class_t * cls);
static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char* file, int line) static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char* file, int line)
{ {
opal_object_t* object = opal_obj_new(type); opal_object_t* object = opal_obj_new(type);
object->obj_magic_id = OPAL_OBJ_MAGIC_ID;
object->cls_init_file_name = file; object->cls_init_file_name = file;
object->cls_init_lineno = line; object->cls_init_lineno = line;
return object; return object;
@ -270,6 +281,7 @@ static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char*
#define OBJ_RETAIN(object) \ #define OBJ_RETAIN(object) \
do { \ do { \
assert(NULL != ((opal_object_t *) (object))->obj_class); \ assert(NULL != ((opal_object_t *) (object))->obj_class); \
assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \
opal_obj_update((opal_object_t *) (object), 1); \ opal_obj_update((opal_object_t *) (object), 1); \
assert(((opal_object_t *) (object))->obj_reference_count >= 0); \ assert(((opal_object_t *) (object))->obj_reference_count >= 0); \
} while (0) } while (0)
@ -287,8 +299,13 @@ static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char*
((opal_object_t*)(OBJECT))->cls_init_file_name = FILE; \ ((opal_object_t*)(OBJECT))->cls_init_file_name = FILE; \
((opal_object_t*)(OBJECT))->cls_init_lineno = LINENO; \ ((opal_object_t*)(OBJECT))->cls_init_lineno = LINENO; \
} while(0) } while(0)
#define OBJ_SET_MAGIC_ID( OBJECT, VALUE ) \
do { \
((opal_object_t*)(OBJECT))->obj_magic_id = (VALUE); \
} while(0)
#else #else
#define OBJ_REMEMBER_FILE_AND_LINENO( OBJECT, FILE, LINENO ) #define OBJ_REMEMBER_FILE_AND_LINENO( OBJECT, FILE, LINENO )
#define OBJ_SET_MAGIC_ID( OBJECT, VALUE )
#endif /* OMPI_ENABLE_DEBUG */ #endif /* OMPI_ENABLE_DEBUG */
/** /**
@ -305,7 +322,9 @@ static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char*
#define OBJ_RELEASE(object) \ #define OBJ_RELEASE(object) \
do { \ do { \
assert(NULL != ((opal_object_t *) (object))->obj_class); \ assert(NULL != ((opal_object_t *) (object))->obj_class); \
assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \
if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \ if (0 == opal_obj_update((opal_object_t *) (object), -1)) { \
OBJ_SET_MAGIC_ID((object), 0); \
opal_obj_run_destructors((opal_object_t *) (object)); \ opal_obj_run_destructors((opal_object_t *) (object)); \
OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \ OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \
free(object); \ free(object); \
@ -333,6 +352,7 @@ static inline opal_object_t *opal_obj_new_debug(opal_class_t* type, const char*
#define OBJ_CONSTRUCT(object, type) \ #define OBJ_CONSTRUCT(object, type) \
do { \ do { \
OBJ_SET_MAGIC_ID((object), OPAL_OBJ_MAGIC_ID); \
OBJ_CONSTRUCT_INTERNAL((object), OBJ_CLASS(type)); \ OBJ_CONSTRUCT_INTERNAL((object), OBJ_CLASS(type)); \
OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \ OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \
} while (0) } while (0)
@ -353,11 +373,21 @@ do { \
* *
* @param object Pointer to the object * @param object Pointer to the object
*/ */
#if OMPI_ENABLE_DEBUG
#define OBJ_DESTRUCT(object) \
do { \
assert(OPAL_OBJ_MAGIC_ID == ((opal_object_t *) (object))->obj_magic_id); \
OBJ_SET_MAGIC_ID((object), 0); \
opal_obj_run_destructors((opal_object_t *) (object)); \
OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \
} while (0)
#else
#define OBJ_DESTRUCT(object) \ #define OBJ_DESTRUCT(object) \
do { \ do { \
opal_obj_run_destructors((opal_object_t *) (object)); \ opal_obj_run_destructors((opal_object_t *) (object)); \
OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \ OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \
} while (0) } while (0)
#endif
BEGIN_C_DECLS BEGIN_C_DECLS

Просмотреть файл

@ -10,6 +10,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -51,7 +52,7 @@ typedef struct {
} orte_data_value_t; } orte_data_value_t;
ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_data_value_t); ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_data_value_t);
#define ORTE_DATA_VALUE_EMPTY {OBJ_CLASS_EMPTY(orte_data_value_t), ORTE_UNDEF, NULL} #define ORTE_DATA_VALUE_EMPTY { OPAL_OBJ_STATIC_INIT(orte_data_value_t), ORTE_UNDEF, NULL}
/* structured-unstructured data flags */ /* structured-unstructured data flags */
#define ORTE_DSS_STRUCTURED true #define ORTE_DSS_STRUCTURED true

Просмотреть файл

@ -10,6 +10,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -151,7 +152,7 @@ typedef struct {
} orte_gpr_value_t; } orte_gpr_value_t;
ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_gpr_value_t); ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_gpr_value_t);
#define ORTE_GPR_VALUE_EMPTY {OBJ_CLASS_EMPTY(orte_gpr_value_t), 0, NULL, 0, NULL, 0, NULL} #define ORTE_GPR_VALUE_EMPTY { OPAL_OBJ_STATIC_INIT(orte_gpr_value_t), 0, NULL, 0, NULL, 0, NULL}
/** Return structure for notification messages /** Return structure for notification messages
* A notification message contains data from each registered subscription structure. * A notification message contains data from each registered subscription structure.
@ -227,7 +228,7 @@ typedef struct {
} orte_gpr_subscription_t; } orte_gpr_subscription_t;
ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_gpr_subscription_t); ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_gpr_subscription_t);
#define ORTE_GPR_SUBSCRIPTION_EMPTY {OBJ_CLASS_EMPTY(orte_gpr_subscription_t), NULL, ORTE_GPR_SUBSCRIPTION_ID_MAX, 0, 0, NULL, 0, NULL} #define ORTE_GPR_SUBSCRIPTION_EMPTY { OPAL_OBJ_STATIC_INIT(orte_gpr_subscription_t), NULL, ORTE_GPR_SUBSCRIPTION_ID_MAX, 0, 0, NULL, 0, NULL}
/** Structure for registering triggers /** Structure for registering triggers
* A trigger causes the associated subscriptions to be executed at a specified event, * A trigger causes the associated subscriptions to be executed at a specified event,
@ -248,7 +249,7 @@ typedef struct {
} orte_gpr_trigger_t; } orte_gpr_trigger_t;
ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_gpr_trigger_t); ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_gpr_trigger_t);
#define ORTE_GPR_TRIGGER_EMPTY {OBJ_CLASS_EMPTY(orte_gpr_trigger_t), NULL, ORTE_GPR_TRIGGER_ID_MAX, 0, 0, NULL, 0, NULL} #define ORTE_GPR_TRIGGER_EMPTY { OPAL_OBJ_STATIC_INIT(orte_gpr_trigger_t), NULL, ORTE_GPR_TRIGGER_ID_MAX, 0, 0, NULL, 0, NULL}
#if defined(c_plusplus) || defined(__cplusplus) #if defined(c_plusplus) || defined(__cplusplus)
} }