Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions opal/class/opal_object.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
Expand All @@ -9,6 +10,8 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -47,6 +50,8 @@ opal_class_t opal_object_t_class = {
sizeof(opal_object_t) /* size of the opal object */
};

int opal_class_init_epoch = 1;

/*
* Local variables
*/
Expand Down Expand Up @@ -81,7 +86,7 @@ void opal_class_initialize(opal_class_t *cls)
/* Check to see if any other thread got in here and initialized
this class before we got a chance to */

if (1 == cls->cls_initialized) {
if (opal_class_init_epoch == cls->cls_initialized) {
return;
}
opal_atomic_lock(&class_lock);
Expand All @@ -90,7 +95,7 @@ void opal_class_initialize(opal_class_t *cls)
roughly the same time, it may have gotten the lock and
initialized. So check again. */

if (1 == cls->cls_initialized) {
if (opal_class_init_epoch == cls->cls_initialized) {
opal_atomic_unlock(&class_lock);
return;
}
Expand Down Expand Up @@ -151,7 +156,7 @@ void opal_class_initialize(opal_class_t *cls)
}
*cls_destruct_array = NULL; /* end marker for the destructors */

cls->cls_initialized = 1;
cls->cls_initialized = opal_class_init_epoch;
save_class(cls);

/* All done */
Expand All @@ -167,6 +172,12 @@ int opal_class_finalize(void)
{
int i;

if (INT_MAX == opal_class_init_epoch) {
opal_class_init_epoch = 1;
} else {
opal_class_init_epoch++;
}

if (NULL != classes) {
for (i = 0; i < num_classes; ++i) {
if (NULL != classes[i]) {
Expand Down
11 changes: 8 additions & 3 deletions opal/class/opal_object.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
Expand All @@ -10,6 +11,8 @@
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -161,6 +164,8 @@ struct opal_class_t {
size_t cls_sizeof; /**< size of an object instance */
};

extern int opal_class_init_epoch;

/**
* For static initializations of OBJects.
*
Expand Down Expand Up @@ -344,8 +349,8 @@ do { \

#define OBJ_CONSTRUCT_INTERNAL(object, type) \
do { \
OBJ_SET_MAGIC_ID((object), OPAL_OBJ_MAGIC_ID); \
if (0 == (type)->cls_initialized) { \
OBJ_SET_MAGIC_ID((object), OPAL_OBJ_MAGIC_ID); \
if (opal_class_init_epoch != (type)->cls_initialized) { \
opal_class_initialize((type)); \
} \
((opal_object_t *) (object))->obj_class = (type); \
Expand Down Expand Up @@ -469,7 +474,7 @@ static inline opal_object_t *opal_obj_new(opal_class_t * cls)
#else
object = (opal_object_t *) malloc(cls->cls_sizeof);
#endif
if (0 == cls->cls_initialized) {
if (opal_class_init_epoch != cls->cls_initialized) {
opal_class_initialize(cls);
}
if (NULL != object) {
Expand Down