Fix prof_{enter,leave}() calls to pass tdata_self.

This commit is contained in:
Jason Evans 2014-10-30 16:50:33 -07:00
parent af1f592763
commit c93ed81cd0

View File

@ -245,10 +245,11 @@ bt_init(prof_bt_t *bt, void **vec)
} }
JEMALLOC_INLINE_C void JEMALLOC_INLINE_C void
prof_enter(prof_tdata_t *tdata) prof_enter(tsd_t *tsd, prof_tdata_t *tdata)
{ {
cassert(config_prof); cassert(config_prof);
assert(tdata == prof_tdata_get(tsd, false));
assert(!tdata->enq); assert(!tdata->enq);
tdata->enq = true; tdata->enq = true;
@ -257,11 +258,12 @@ prof_enter(prof_tdata_t *tdata)
} }
JEMALLOC_INLINE_C void JEMALLOC_INLINE_C void
prof_leave(prof_tdata_t *tdata) prof_leave(tsd_t *tsd, prof_tdata_t *tdata)
{ {
bool idump, gdump; bool idump, gdump;
cassert(config_prof); cassert(config_prof);
assert(tdata == prof_tdata_get(tsd, false));
malloc_mutex_unlock(&bt2gctx_mtx); malloc_mutex_unlock(&bt2gctx_mtx);
@ -542,7 +544,8 @@ prof_gctx_create(tsd_t *tsd, prof_bt_t *bt)
} }
static void static void
prof_gctx_try_destroy(tsd_t *tsd, prof_gctx_t *gctx, prof_tdata_t *tdata) prof_gctx_try_destroy(tsd_t *tsd, prof_tdata_t *tdata_self, prof_gctx_t *gctx,
prof_tdata_t *tdata)
{ {
cassert(config_prof); cassert(config_prof);
@ -554,14 +557,14 @@ prof_gctx_try_destroy(tsd_t *tsd, prof_gctx_t *gctx, prof_tdata_t *tdata)
* avoid a race between the main body of prof_tctx_destroy() and entry * avoid a race between the main body of prof_tctx_destroy() and entry
* into this function. * into this function.
*/ */
prof_enter(tdata); prof_enter(tsd, tdata_self);
malloc_mutex_lock(gctx->lock); malloc_mutex_lock(gctx->lock);
assert(gctx->nlimbo != 0); assert(gctx->nlimbo != 0);
if (tctx_tree_empty(&gctx->tctxs) && gctx->nlimbo == 1) { if (tctx_tree_empty(&gctx->tctxs) && gctx->nlimbo == 1) {
/* Remove gctx from bt2gctx. */ /* Remove gctx from bt2gctx. */
if (ckh_remove(tsd, &bt2gctx, &gctx->bt, NULL, NULL)) if (ckh_remove(tsd, &bt2gctx, &gctx->bt, NULL, NULL))
not_reached(); not_reached();
prof_leave(tdata); prof_leave(tsd, tdata_self);
/* Destroy gctx. */ /* Destroy gctx. */
malloc_mutex_unlock(gctx->lock); malloc_mutex_unlock(gctx->lock);
idalloc(tsd, gctx); idalloc(tsd, gctx);
@ -572,7 +575,7 @@ prof_gctx_try_destroy(tsd_t *tsd, prof_gctx_t *gctx, prof_tdata_t *tdata)
*/ */
gctx->nlimbo--; gctx->nlimbo--;
malloc_mutex_unlock(gctx->lock); malloc_mutex_unlock(gctx->lock);
prof_leave(tdata); prof_leave(tsd, tdata_self);
} }
} }
@ -655,8 +658,10 @@ prof_tctx_destroy(tsd_t *tsd, prof_tctx_t *tctx)
destroy_gctx = false; destroy_gctx = false;
} }
malloc_mutex_unlock(gctx->lock); malloc_mutex_unlock(gctx->lock);
if (destroy_gctx) if (destroy_gctx) {
prof_gctx_try_destroy(tsd, gctx, tdata); prof_gctx_try_destroy(tsd, prof_tdata_get(tsd, false), gctx,
tdata);
}
if (destroy_tdata) if (destroy_tdata)
prof_tdata_destroy(tsd, tdata, false); prof_tdata_destroy(tsd, tdata, false);
@ -679,18 +684,18 @@ prof_lookup_global(tsd_t *tsd, prof_bt_t *bt, prof_tdata_t *tdata,
} btkey; } btkey;
bool new_gctx; bool new_gctx;
prof_enter(tdata); prof_enter(tsd, tdata);
if (ckh_search(&bt2gctx, bt, &btkey.v, &gctx.v)) { if (ckh_search(&bt2gctx, bt, &btkey.v, &gctx.v)) {
/* bt has never been seen before. Insert it. */ /* bt has never been seen before. Insert it. */
gctx.p = prof_gctx_create(tsd, bt); gctx.p = prof_gctx_create(tsd, bt);
if (gctx.v == NULL) { if (gctx.v == NULL) {
prof_leave(tdata); prof_leave(tsd, tdata);
return (true); return (true);
} }
btkey.p = &gctx.p->bt; btkey.p = &gctx.p->bt;
if (ckh_insert(tsd, &bt2gctx, btkey.v, gctx.v)) { if (ckh_insert(tsd, &bt2gctx, btkey.v, gctx.v)) {
/* OOM. */ /* OOM. */
prof_leave(tdata); prof_leave(tsd, tdata);
idalloc(tsd, gctx.v); idalloc(tsd, gctx.v);
return (true); return (true);
} }
@ -705,7 +710,7 @@ prof_lookup_global(tsd_t *tsd, prof_bt_t *bt, prof_tdata_t *tdata,
malloc_mutex_unlock(gctx.p->lock); malloc_mutex_unlock(gctx.p->lock);
new_gctx = false; new_gctx = false;
} }
prof_leave(tdata); prof_leave(tsd, tdata);
*p_btkey = btkey.v; *p_btkey = btkey.v;
*p_gctx = gctx.p; *p_gctx = gctx.p;
@ -751,7 +756,7 @@ prof_lookup(tsd_t *tsd, prof_bt_t *bt)
ret.v = imalloc(tsd, sizeof(prof_tctx_t)); ret.v = imalloc(tsd, sizeof(prof_tctx_t));
if (ret.p == NULL) { if (ret.p == NULL) {
if (new_gctx) if (new_gctx)
prof_gctx_try_destroy(tsd, gctx, tdata); prof_gctx_try_destroy(tsd, tdata, gctx, tdata);
return (NULL); return (NULL);
} }
ret.p->tdata = tdata; ret.p->tdata = tdata;
@ -765,7 +770,7 @@ prof_lookup(tsd_t *tsd, prof_bt_t *bt)
malloc_mutex_unlock(tdata->lock); malloc_mutex_unlock(tdata->lock);
if (error) { if (error) {
if (new_gctx) if (new_gctx)
prof_gctx_try_destroy(tsd, gctx, tdata); prof_gctx_try_destroy(tsd, tdata, gctx, tdata);
idalloc(tsd, ret.v); idalloc(tsd, ret.v);
return (NULL); return (NULL);
} }
@ -872,9 +877,9 @@ prof_bt_count(void)
if (tdata == NULL) if (tdata == NULL)
return (0); return (0);
prof_enter(tdata); malloc_mutex_lock(&bt2gctx_mtx);
bt_count = ckh_count(&bt2gctx); bt_count = ckh_count(&bt2gctx);
prof_leave(tdata); malloc_mutex_unlock(&bt2gctx_mtx);
return (bt_count); return (bt_count);
} }
@ -1155,7 +1160,7 @@ prof_gctx_finish(tsd_t *tsd, prof_gctx_tree_t *gctxs)
if (prof_gctx_should_destroy(gctx)) { if (prof_gctx_should_destroy(gctx)) {
gctx->nlimbo++; gctx->nlimbo++;
malloc_mutex_unlock(gctx->lock); malloc_mutex_unlock(gctx->lock);
prof_gctx_try_destroy(tsd, gctx, tdata); prof_gctx_try_destroy(tsd, tdata, gctx, tdata);
} else } else
malloc_mutex_unlock(gctx->lock); malloc_mutex_unlock(gctx->lock);
} }
@ -1398,7 +1403,7 @@ prof_dump(tsd_t *tsd, bool propagate_err, const char *filename, bool leakcheck)
return (true); return (true);
malloc_mutex_lock(&prof_dump_mtx); malloc_mutex_lock(&prof_dump_mtx);
prof_enter(tdata); prof_enter(tsd, tdata);
/* /*
* Put gctx's in limbo and clear their counters in preparation for * Put gctx's in limbo and clear their counters in preparation for
@ -1421,7 +1426,7 @@ prof_dump(tsd_t *tsd, bool propagate_err, const char *filename, bool leakcheck)
leak_ngctx = 0; leak_ngctx = 0;
gctx_tree_iter(&gctxs, NULL, prof_gctx_merge_iter, (void *)&leak_ngctx); gctx_tree_iter(&gctxs, NULL, prof_gctx_merge_iter, (void *)&leak_ngctx);
prof_leave(tdata); prof_leave(tsd, tdata);
/* Create dump file. */ /* Create dump file. */
if ((prof_dump_fd = prof_dump_open(propagate_err, filename)) == -1) if ((prof_dump_fd = prof_dump_open(propagate_err, filename)) == -1)