Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adding tracing for the slot APIs
  • Loading branch information
tonycoz committed Sep 17, 2012
1 parent 88adfaa commit 61495d6
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion FT2/freetyp2.c
Expand Up @@ -65,7 +65,7 @@ static i_img_dim i_max(i_img_dim a, i_img_dim b);
void
i_ft2_start(void) {
if (slot == -1)
slot = im_context_slot_new(ft2_final);
slot = im_context_slot_new(ft2_final, "FT2");
}

/*
Expand Down
19 changes: 17 additions & 2 deletions context.c
Expand Up @@ -189,15 +189,15 @@ im_context_clone(im_context_t ctx, const char *where) {
}

/*
=item im_context_slot_new(destructor)
=item im_context_slot_new(destructor, where)
Allocate a new context-local-storage slot.
=cut
*/

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)
Expand All @@ -213,6 +213,11 @@ im_context_slot_new(im_slot_destroy_t destructor) {

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;
Expand Down Expand Up @@ -257,6 +262,11 @@ im_context_slot_set(im_context_t ctx, im_slot_t slot, void *value) {

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;
}

Expand All @@ -280,5 +290,10 @@ im_context_slot_get(im_context_t ctx, im_slot_t slot) {
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];
}
3 changes: 1 addition & 2 deletions fontft1.c
Expand Up @@ -150,9 +150,8 @@ static int LTT_hinted = 1; /* FIXME: this too */

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");
}


Expand Down
2 changes: 1 addition & 1 deletion imager.h
Expand Up @@ -386,7 +386,7 @@ extern im_context_t im_context_new(void);
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 *);

Expand Down
2 changes: 1 addition & 1 deletion imext.h
Expand Up @@ -232,7 +232,7 @@ extern im_ext_funcs *imager_function_ext_table;
#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)))

Expand Down
2 changes: 1 addition & 1 deletion imexttypes.h
Expand Up @@ -232,7 +232,7 @@ typedef struct {
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;
Expand Down
7 changes: 4 additions & 3 deletions lib/Imager/API.pod
Expand Up @@ -447,10 +447,11 @@ Imager provides simple APIs for storing per-context information.

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.
Expand Down
2 changes: 1 addition & 1 deletion lib/Imager/APIRef.pod
Expand Up @@ -2302,7 +2302,7 @@ object.
=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.

Expand Down
2 changes: 1 addition & 1 deletion t/t82inline.t
Expand Up @@ -422,7 +422,7 @@ test_mutex() {
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");
Expand Down

0 comments on commit 61495d6

Please sign in to comment.