mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
修正: 1. 无接收者时, send 可能返回 true; 2. Windows + MSVC 下分配器的内存异常
This commit is contained in:
parent
19f471b07c
commit
0aeaa0f1f1
@ -394,6 +394,14 @@ static bool send(F&& gen_push, ipc::handle_t h, void const * data, std::size_t s
|
||||
ipc::error("fail: send, queue_of(h) == nullptr\n");
|
||||
return false;
|
||||
}
|
||||
if (que->elems() == nullptr) {
|
||||
ipc::error("fail: send, queue_of(h)->elems() == nullptr\n");
|
||||
return false;
|
||||
}
|
||||
if (que->elems()->connections(std::memory_order_relaxed) == que->connected_id()) {
|
||||
// there is no receiver on this connection
|
||||
return false;
|
||||
}
|
||||
// calc a new message id
|
||||
auto acc = info_of(h)->acc();
|
||||
if (acc == nullptr) {
|
||||
|
||||
@ -20,7 +20,7 @@ struct rebind {
|
||||
using alloc_t = AllocP;
|
||||
};
|
||||
|
||||
template <template <typename U> class AllocT, typename T>
|
||||
template <typename T, template <typename> class AllocT>
|
||||
struct rebind<T, AllocT<T>> {
|
||||
template <typename U>
|
||||
using alloc_t = AllocT<U>;
|
||||
@ -65,7 +65,9 @@ public:
|
||||
public:
|
||||
// the other type of std_allocator
|
||||
template <typename U>
|
||||
struct rebind { typedef allocator_wrapper< U, typename detail::rebind<T, AllocP>::template alloc_t<U> > other; };
|
||||
struct rebind {
|
||||
using other = allocator_wrapper< U, typename detail::rebind<T, AllocP>::template alloc_t<U> >;
|
||||
};
|
||||
|
||||
constexpr size_type max_size(void) const noexcept {
|
||||
return (std::numeric_limits<size_type>::max)() / sizeof(value_type);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include <tuple>
|
||||
#include <thread>
|
||||
#include <set> // std::set
|
||||
#include <deque> // std::deque
|
||||
#include <functional> // std::function
|
||||
#include <utility> // std::forward
|
||||
#include <cstddef>
|
||||
@ -40,16 +40,7 @@ public:
|
||||
using alloc_policy = AllocP;
|
||||
|
||||
protected:
|
||||
template <typename T>
|
||||
struct fixed_alloc_t : public fixed_alloc<sizeof(T)> {};
|
||||
|
||||
template <typename T>
|
||||
using allocator = ipc::mem::allocator_wrapper<T, fixed_alloc_t<T>>;
|
||||
|
||||
std::multiset<alloc_policy, std::less<alloc_policy>,
|
||||
allocator<alloc_policy>
|
||||
> master_allocs_;
|
||||
|
||||
std::deque<alloc_policy> master_allocs_;
|
||||
ipc::spin_lock master_lock_;
|
||||
|
||||
template <typename F>
|
||||
@ -60,11 +51,6 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
void swap(limited_recycler & rhs) {
|
||||
IPC_UNUSED_ auto guard = ipc::detail::unique_lock(master_lock_);
|
||||
master_allocs_.swap(rhs.master_allocs_);
|
||||
}
|
||||
|
||||
void try_recover(alloc_policy & alc) {
|
||||
IPC_UNUSED_ auto guard = ipc::detail::unique_lock(master_lock_);
|
||||
if (master_allocs_.empty()) return;
|
||||
@ -76,7 +62,7 @@ public:
|
||||
if (master_allocs_.size() >= 32) {
|
||||
take_first_do([](alloc_policy &) {}); // erase first
|
||||
}
|
||||
master_allocs_.emplace(std::move(alc));
|
||||
master_allocs_.emplace_back(std::move(alc));
|
||||
}
|
||||
|
||||
IPC_CONSTEXPR_ auto try_replenish(alloc_policy&, std::size_t) noexcept {}
|
||||
@ -131,7 +117,6 @@ class empty_recycler {
|
||||
public:
|
||||
using alloc_policy = AllocP;
|
||||
|
||||
IPC_CONSTEXPR_ void swap(empty_recycler&) noexcept {}
|
||||
IPC_CONSTEXPR_ void try_recover(alloc_policy&) noexcept {}
|
||||
IPC_CONSTEXPR_ auto try_replenish(alloc_policy&, std::size_t) noexcept {}
|
||||
IPC_CONSTEXPR_ void collect(alloc_policy&&) noexcept {}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user