Remove synchronized_pool_resource class and its implementation

This commit is contained in:
mutouyun 2024-01-13 19:05:43 +08:00
parent f3ecf7c61c
commit f615f200df
2 changed files with 0 additions and 79 deletions

View File

@ -1,40 +0,0 @@
/**
* \file libpmr/synchronized_pool_resource.h
* \author mutouyun (orz@orzz.org)
* \brief A thread-safe std::pmr::memory_resource for managing allocations in pools of different block sizes.
* \date 2023-12-23
*/
#pragma once
#include <cstddef> // std::size_t, std::max_align_t
#include "libimp/export.h"
#include "libpmr/def.h"
LIBPMR_NAMESPACE_BEG_
/**
* \class LIBIMP_EXPORT synchronized_pool_resource
* \brief `synchronized_pool_resource` may be accessed from multiple threads without external synchronization,
* and have thread-specific pools to reduce synchronization costs.
* \note Unlike the standard library implementation, `synchronized_pool_resource` automatically manages
* the block size and reclaims all deallocated memory to the central heap when the thread is destroyed,
* rather than being destructed on its own.
* \see https://en.cppreference.com/w/cpp/memory/synchronized_pool_resource
*/
class LIBIMP_EXPORT synchronized_pool_resource {
public:
/// \brief Returns a pointer to a `synchronized_pool_resource`.
static synchronized_pool_resource *get() noexcept;
/// \brief Allocates storage with a size of at least bytes bytes, aligned to the specified alignment.
/// \remark Returns nullptr if storage of the requested size and alignment cannot be obtained.
/// \see https://en.cppreference.com/w/cpp/memory/memory_resource/do_allocate
void *allocate(std::size_t bytes, std::size_t alignment = alignof(std::max_align_t)) noexcept;
/// \brief Deallocates the storage pointed to by p.
/// \see https://en.cppreference.com/w/cpp/memory/memory_resource/deallocate
void deallocate(void *p, std::size_t bytes, std::size_t alignment = alignof(std::max_align_t)) noexcept;
};
LIBPMR_NAMESPACE_END_

View File

@ -1,39 +0,0 @@
#include "libimp/log.h"
#include "libpmr/synchronized_pool_resource.h"
#include "libpmr/block_pool.h"
#include "verify_args.h"
LIBPMR_NAMESPACE_BEG_
namespace {
} // namespace
synchronized_pool_resource *synchronized_pool_resource::get() noexcept {
static synchronized_pool_resource mem_res;
return &mem_res;
}
void *synchronized_pool_resource::allocate(std::size_t bytes, std::size_t alignment) noexcept {
LIBIMP_LOG_();
if (!verify_args(bytes, alignment) || (alignment > alignof(std::max_align_t))) {
log.error("invalid bytes = ", bytes, ", alignment = ", alignment);
return nullptr;
}
return nullptr;
}
void synchronized_pool_resource::deallocate(void *p, std::size_t bytes, std::size_t alignment) noexcept {
LIBIMP_LOG_();
if (p == nullptr) {
return;
}
if (!verify_args(bytes, alignment) || (alignment > alignof(std::max_align_t))) {
log.error("invalid bytes = ", bytes, ", alignment = ", alignment);
return;
}
}
LIBPMR_NAMESPACE_END_