029d44cf8b
Fix tsd cleanup regressions that were introduced in
5460aa6f66
(Convert all tsd variables to
reside in a single tsd structure.). These regressions were twofold:
1) tsd_tryget() should never (and need never) return NULL. Rename it to
tsd_fetch() and simplify all callers.
2) tsd_*_set() must only be called when tsd is in the nominal state,
because cleanup happens during the nominal-->purgatory transition,
and re-initialization must not happen while in the purgatory state.
Add tsd_nominal() and use it as needed. Note that tsd_*{p,}_get()
can still be used as long as no re-initialization that would require
cleanup occurs. This means that e.g. the thread_allocated counter
can be updated unconditionally.
61 lines
1.6 KiB
C
61 lines
1.6 KiB
C
/******************************************************************************/
|
|
#ifdef JEMALLOC_H_TYPES
|
|
|
|
typedef struct quarantine_obj_s quarantine_obj_t;
|
|
typedef struct quarantine_s quarantine_t;
|
|
|
|
/* Default per thread quarantine size if valgrind is enabled. */
|
|
#define JEMALLOC_VALGRIND_QUARANTINE_DEFAULT (ZU(1) << 24)
|
|
|
|
#endif /* JEMALLOC_H_TYPES */
|
|
/******************************************************************************/
|
|
#ifdef JEMALLOC_H_STRUCTS
|
|
|
|
struct quarantine_obj_s {
|
|
void *ptr;
|
|
size_t usize;
|
|
};
|
|
|
|
struct quarantine_s {
|
|
size_t curbytes;
|
|
size_t curobjs;
|
|
size_t first;
|
|
#define LG_MAXOBJS_INIT 10
|
|
size_t lg_maxobjs;
|
|
quarantine_obj_t objs[1]; /* Dynamically sized ring buffer. */
|
|
};
|
|
|
|
#endif /* JEMALLOC_H_STRUCTS */
|
|
/******************************************************************************/
|
|
#ifdef JEMALLOC_H_EXTERNS
|
|
|
|
quarantine_t *quarantine_init(tsd_t *tsd, size_t lg_maxobjs);
|
|
void quarantine(tsd_t *tsd, void *ptr);
|
|
void quarantine_cleanup(tsd_t *tsd);
|
|
|
|
#endif /* JEMALLOC_H_EXTERNS */
|
|
/******************************************************************************/
|
|
#ifdef JEMALLOC_H_INLINES
|
|
|
|
#ifndef JEMALLOC_ENABLE_INLINE
|
|
void quarantine_alloc_hook(void);
|
|
#endif
|
|
|
|
#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_QUARANTINE_C_))
|
|
JEMALLOC_ALWAYS_INLINE void
|
|
quarantine_alloc_hook(void)
|
|
{
|
|
tsd_t *tsd;
|
|
|
|
assert(config_fill && opt_quarantine);
|
|
|
|
tsd = tsd_fetch();
|
|
if (tsd_quarantine_get(tsd) == NULL && tsd_nominal(tsd))
|
|
tsd_quarantine_set(tsd, quarantine_init(tsd, LG_MAXOBJS_INIT));
|
|
}
|
|
#endif
|
|
|
|
#endif /* JEMALLOC_H_INLINES */
|
|
/******************************************************************************/
|
|
|