@@ -137,6 +137,7 @@ typedef struct parsec_object_t parsec_object_t;
137137typedef struct parsec_class_t parsec_class_t ;
138138typedef void (* parsec_construct_t ) (parsec_object_t * );
139139typedef void (* parsec_destruct_t ) (parsec_object_t * );
140+ typedef void (* parsec_release_t ) (parsec_object_t * );
140141
141142
142143/* types **************************************************************/
@@ -185,6 +186,7 @@ struct parsec_object_t {
185186#endif /* defined(PARSEC_DEBUG_PARANOID) */
186187 parsec_class_t * obj_class ; /**< class descriptor */
187188 volatile int32_t obj_reference_count ; /**< reference count */
189+ parsec_release_t obj_release ; /**< destruct and release */
188190#if defined(PARSEC_DEBUG_PARANOID )
189191 const char * cls_init_file_name ; /**< In debug mode store the file where the object get contructed */
190192 int cls_init_lineno ; /**< In debug mode store the line number where the object get contructed */
@@ -295,6 +297,9 @@ static inline parsec_object_t *parsec_obj_new_debug(parsec_class_t* type, const
295297#define PARSEC_OBJ_SET_MAGIC_ID ( OBJECT , VALUE )
296298#endif /* defined(PARSEC_DEBUG_PARANOID) */
297299
300+ void parsec_obj_destruct (parsec_object_t * object );
301+ void parsec_obj_destruct_and_free (parsec_object_t * object );
302+
298303/**
299304 * Release an object (by decrementing its reference count). If the
300305 * reference count reaches zero, destruct (finalize) the object and
@@ -311,25 +316,21 @@ static inline parsec_object_t *parsec_obj_new_debug(parsec_class_t* type, const
311316 assert(NULL != ((parsec_object_t *) (object))->obj_class); \
312317 assert(PARSEC_OBJ_MAGIC_ID == ((parsec_object_t *) (object))->obj_magic_id); \
313318 if (0 == parsec_obj_update((parsec_object_t *) (object), -1)) { \
314- parsec_obj_run_destructors((parsec_object_t *) (object)); \
315- PARSEC_OBJ_SET_MAGIC_ID((object), 0); \
316319 PARSEC_OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \
317- free( object); \
320+ ((parsec_object_t*) object)->obj_release((parsec_object_t*)object); \
318321 object = NULL; \
319322 } \
320323 } while (0)
321324#else
322325#define PARSEC_OBJ_RELEASE (object ) \
323326 do { \
324327 if (0 == parsec_obj_update((parsec_object_t *) (object), -1)) { \
325- parsec_obj_run_destructors((parsec_object_t *) (object)); \
326- free(object); \
328+ ((parsec_object_t*)object)->obj_release((parsec_object_t*)object); \
327329 object = NULL; \
328330 } \
329331 } while (0)
330332#endif
331333
332-
333334/**
334335 * Construct (initialize) objects that are not dynamically allocated.
335336 *
@@ -339,17 +340,26 @@ static inline parsec_object_t *parsec_obj_new_debug(parsec_class_t* type, const
339340
340341#define PARSEC_OBJ_CONSTRUCT (object , type ) \
341342do { \
342- PARSEC_OBJ_CONSTRUCT_INTERNAL((object), PARSEC_OBJ_CLASS(type)); \
343+ PARSEC_OBJ_CONSTRUCT_WRELEASE_INTERNAL((object), PARSEC_OBJ_CLASS(type), &parsec_obj_destruct); \
344+ } while (0)
345+
346+ #define PARSEC_OBJ_CONSTRUCT_WRELEASE (object , type , release ) \
347+ do { \
348+ PARSEC_OBJ_CONSTRUCT_WRELEASE_INTERNAL((object), PARSEC_OBJ_CLASS(type), release); \
343349} while (0)
344350
345- #define PARSEC_OBJ_CONSTRUCT_INTERNAL (object , type ) \
351+ /* backwards compatible macro for mempool */
352+ #define PARSEC_OBJ_CONSTRUCT_INTERNAL (object , type ) PARSEC_OBJ_CONSTRUCT_WRELEASE_INTERNAL(object, type, &parsec_obj_destruct)
353+
354+ #define PARSEC_OBJ_CONSTRUCT_WRELEASE_INTERNAL (object , type , release ) \
346355do { \
347356 PARSEC_OBJ_SET_MAGIC_ID((object), PARSEC_OBJ_MAGIC_ID); \
348357 if (0 == (type)->cls_initialized) { \
349358 parsec_class_initialize((type)); \
350359 } \
351360 ((parsec_object_t *) (object))->obj_class = (type); \
352361 ((parsec_object_t *) (object))->obj_reference_count = 1; \
362+ ((parsec_object_t *) (object))->obj_release = (parsec_release_t)release; \
353363 parsec_obj_run_constructors((parsec_object_t *) (object)); \
354364 PARSEC_OBJ_REMEMBER_FILE_AND_LINENO( object, __FILE__, __LINE__ ); \
355365} while (0)
@@ -470,6 +480,7 @@ static inline parsec_object_t *parsec_obj_new(parsec_class_t * cls)
470480 if (NULL != object ) {
471481 object -> obj_class = cls ;
472482 object -> obj_reference_count = 1 ;
483+ object -> obj_release = & parsec_obj_destruct_and_free ;
473484 parsec_obj_run_constructors (object );
474485 }
475486 return object ;
0 commit comments