/* This API is defined only if the library has been suitably compiled */
/* (i.e. with ENABLE_DISCLAIM defined). */
- /* Prepare the object kind used for GC_finalized_malloc. */
++/* Prepare the object kind used by GC_finalized_malloc. Call it from */
++/* your initialization code or, at least, at some point before using */
++/* finalized allocations. The function is thread-safe. */
+GC_API void GC_CALL GC_init_finalized_malloc(void);
+
/* Type of a disclaim call-back, always stored along with closure data */
/* passed as the second argument. */
typedef int (GC_CALLBACK * GC_disclaim_proc)(void * /*obj*/, void * /*cd*/);
#include <stdio.h>
#include <string.h>
-#include <time.h> // FIXME: It would be good not to use timing API by
- // default (is it is not quite portable).
-
#include "atomic_ops.h"
-#include "private/gc_priv.h"
#include "gc_disclaim.h"
- #ifndef AO_HAVE_fetch_and_add1
++#include "private/gc_priv.h"
+
- int main(void)
- {
- printf("Skipping disclaim_bench test\n");
- return 0;
- }
-
- #else
+ static int free_count = 0;
- #include <time.h>
-
- static AO_t free_count = 0;
-
--typedef struct testobj_s *testobj_t;
struct testobj_s {
-- testobj_t keep_link;
++ struct testobj_s *keep_link;
int i;
};
++typedef struct testobj_s *testobj_t;
++
void GC_CALLBACK testobj_finalize(void *obj, void *carg)
{
- AO_fetch_and_add1((AO_t *)carg);
+ ++*(int *)carg;
assert(((testobj_t)obj)->i++ == 109);
}