void
i_ft2_start(void) {
if (slot == -1)
- slot = im_context_slot_new(ft2_final);
+ slot = im_context_slot_new(ft2_final, "FT2");
}
/*
}
/*
-=item im_context_slot_new(destructor)
+=item im_context_slot_new(destructor, where)
Allocate a new context-local-storage slot.
*/
im_slot_t
-im_context_slot_new(im_slot_destroy_t destructor) {
+im_context_slot_new(im_slot_destroy_t destructor, const char *where) {
im_slot_t new_slot;
im_slot_destroy_t *new_destructors;
if (!slot_mutex)
slot_destructors[new_slot] = destructor;
+#ifdef IMAGER_TRACE_CONTEXT
+ fprintf(stderr, "im_context: slot %d allocated for %s\n",
+ (int)new_slot, where);
+#endif
+
i_mutex_unlock(slot_mutex);
return new_slot;
ctx->slots[slot] = value;
+#ifdef IMAGER_TRACE_CONTEXT
+ fprintf(stderr, "im_context: ctx %p slot %d set to %p\n",
+ ctx, (int)slot, value);
+#endif
+
return 1;
}
if (slot >= ctx->slot_alloc)
return NULL;
+#ifdef IMAGER_TRACE_CONTEXT
+ fprintf(stderr, "im_context: ctx %p slot %d retrieved as %p\n",
+ ctx, (int)slot, ctx->slots[slot]);
+#endif
+
return ctx->slots[slot];
}
void
i_tt_start(void) {
- im_context_t ctx = im_get_context();
if (slot == -1)
- slot = im_context_slot_new(i_tt_uninit);
+ slot = im_context_slot_new(i_tt_uninit, "TT");
}
extern void im_context_refinc(im_context_t ctx, const char *where);
extern void im_context_refdec(im_context_t ctx, const char *where);
extern im_context_t im_context_clone(im_context_t ctx, const char *where);
-extern im_slot_t im_context_slot_new(im_slot_destroy_t);
+extern im_slot_t im_context_slot_new(im_slot_destroy_t, const char *);
extern void *im_context_slot_get(im_context_t ctx, im_slot_t slot);
extern int im_context_slot_set(im_context_t ctx, im_slot_t slot, void *);
#define i_mutex_lock(m) ((im_extt->f_i_mutex_lock)(m))
#define i_mutex_unlock(m) ((im_extt->f_i_mutex_unlock)(m))
-#define im_context_slot_new(destructor) ((im_extt->f_im_context_slot_new)(destructor))
+#define im_context_slot_new(destructor, where) ((im_extt->f_im_context_slot_new)((destructor), (where)))
#define im_context_slot_get(ctx, slot) ((im_extt->f_im_context_slot_get)((ctx), (slot)))
#define im_context_slot_set(ctx, slot, value) ((im_extt->f_im_context_slot_set)((ctx), (slot), (value)))
void (*f_i_mutex_destroy)(i_mutex_t m);
void (*f_i_mutex_lock)(i_mutex_t m);
void (*f_i_mutex_unlock)(i_mutex_t m);
- im_slot_t (*f_im_context_slot_new)(im_slot_destroy_t);
+ im_slot_t (*f_im_context_slot_new)(im_slot_destroy_t, const char *);
int (*f_im_context_slot_set)(im_context_t, im_slot_t, void *);
void *(*f_im_context_slot_get)(im_context_t, im_slot_t);
} im_ext_funcs;
To allocate a slot:
- im_slot_t slot = im_context_slot_new(callback)
+ im_slot_t slot = im_context_slot_new(callback, where)
-where callback is a (possibly NULL) function pointer called when the
-context object is destroyed.
+where I<callback> is a (possibly NULL) function pointer called when
+the context object is destroyed, and I<where> is a brief description
+of what the slot is used for.
By default, the stored value for a slot is NULL, whether for a new
context or for a cloned context.
=for comment
From: File context.c
-=item im_context_slot_new(destructor)
+=item im_context_slot_new(destructor, where)
Allocate a new context-local-storage slot.
int
test_slots() {
- im_slot_t slot = im_context_slot_new(NULL);
+ im_slot_t slot = im_context_slot_new(NULL, "t82inline");
if (im_context_slot_get(aIMCTX, slot)) {
fprintf(stderr, "slots should default to NULL\n");