Refactor destroy code path for prof_tctx
This commit is contained in:
parent
055478cca8
commit
7d2bac5a38
@ -114,13 +114,13 @@ bool prof_log_rep_check(void);
|
||||
void prof_log_dummy_set(bool new_value);
|
||||
#endif
|
||||
|
||||
/* Functions in prof_data.c only accessed in prof.c */
|
||||
/* Functions in prof_data.c only used in profiling code. */
|
||||
bool prof_data_init(tsd_t *tsd);
|
||||
bool prof_dump(tsd_t *tsd, bool propagate_err, const char *filename,
|
||||
bool leakcheck);
|
||||
prof_tdata_t * prof_tdata_init_impl(tsd_t *tsd, uint64_t thr_uid,
|
||||
uint64_t thr_discrim, char *thread_name, bool active, bool reset_interval);
|
||||
void prof_tdata_detach(tsd_t *tsd, prof_tdata_t *tdata);
|
||||
void prof_tctx_destroy(tsd_t *tsd, prof_tctx_t *tctx);
|
||||
void prof_tctx_try_destroy(tsd_t *tsd, prof_tctx_t *tctx);
|
||||
|
||||
#endif /* JEMALLOC_INTERNAL_PROF_EXTERNS_H */
|
||||
|
28
src/prof.c
28
src/prof.c
@ -128,22 +128,6 @@ prof_strncpy(char *UNUSED dest, const char *UNUSED src, size_t UNUSED size) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool
|
||||
prof_tctx_should_destroy(tsdn_t *tsdn, prof_tctx_t *tctx) {
|
||||
malloc_mutex_assert_owner(tsdn, tctx->tdata->lock);
|
||||
|
||||
if (opt_prof_accum) {
|
||||
return false;
|
||||
}
|
||||
if (tctx->cnts.curobjs != 0) {
|
||||
return false;
|
||||
}
|
||||
if (tctx->prepared) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
prof_alloc_rollback(tsd_t *tsd, prof_tctx_t *tctx, bool updated) {
|
||||
cassert(config_prof);
|
||||
@ -171,11 +155,7 @@ prof_alloc_rollback(tsd_t *tsd, prof_tctx_t *tctx, bool updated) {
|
||||
if ((uintptr_t)tctx > (uintptr_t)1U) {
|
||||
malloc_mutex_lock(tsd_tsdn(tsd), tctx->tdata->lock);
|
||||
tctx->prepared = false;
|
||||
if (prof_tctx_should_destroy(tsd_tsdn(tsd), tctx)) {
|
||||
prof_tctx_destroy(tsd, tctx);
|
||||
} else {
|
||||
malloc_mutex_unlock(tsd_tsdn(tsd), tctx->tdata->lock);
|
||||
}
|
||||
prof_tctx_try_destroy(tsd, tctx);
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,11 +196,7 @@ prof_free_sampled_object(tsd_t *tsd, size_t usize, prof_info_t *prof_info) {
|
||||
|
||||
prof_try_log(tsd, usize, prof_info);
|
||||
|
||||
if (prof_tctx_should_destroy(tsd_tsdn(tsd), tctx)) {
|
||||
prof_tctx_destroy(tsd, tctx);
|
||||
} else {
|
||||
malloc_mutex_unlock(tsd_tsdn(tsd), tctx->tdata->lock);
|
||||
}
|
||||
prof_tctx_try_destroy(tsd, tctx);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1373,7 +1373,23 @@ prof_reset(tsd_t *tsd, size_t lg_sample) {
|
||||
malloc_mutex_unlock(tsd_tsdn(tsd), &prof_dump_mtx);
|
||||
}
|
||||
|
||||
void
|
||||
static bool
|
||||
prof_tctx_should_destroy(tsd_t *tsd, prof_tctx_t *tctx) {
|
||||
malloc_mutex_assert_owner(tsd_tsdn(tsd), tctx->tdata->lock);
|
||||
|
||||
if (opt_prof_accum) {
|
||||
return false;
|
||||
}
|
||||
if (tctx->cnts.curobjs != 0) {
|
||||
return false;
|
||||
}
|
||||
if (tctx->prepared) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
prof_tctx_destroy(tsd_t *tsd, prof_tctx_t *tctx) {
|
||||
prof_tdata_t *tdata = tctx->tdata;
|
||||
prof_gctx_t *gctx = tctx->gctx;
|
||||
@ -1449,4 +1465,15 @@ prof_tctx_destroy(tsd_t *tsd, prof_tctx_t *tctx) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_tctx_try_destroy(tsd_t *tsd, prof_tctx_t *tctx) {
|
||||
malloc_mutex_assert_owner(tsd_tsdn(tsd), tctx->tdata->lock);
|
||||
if (prof_tctx_should_destroy(tsd, tctx)) {
|
||||
/* tctx->tdata->lock will be released in prof_tctx_destroy(). */
|
||||
prof_tctx_destroy(tsd, tctx);
|
||||
} else {
|
||||
malloc_mutex_unlock(tsd_tsdn(tsd), tctx->tdata->lock);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user