reorganize the code into a thread-safe API
fix `reallocate_inplace` with small allocations