fine-tune

This commit is contained in:
mutouyun 2019-03-22 23:09:42 +08:00
parent 280cc81fa2
commit f2bfd0bc6c
2 changed files with 18 additions and 20 deletions

View File

@ -19,14 +19,13 @@
namespace { namespace {
using namespace ipc; using namespace ipc;
using msg_id_t = std::size_t; using msg_id_t = std::size_t;
template <std::size_t DataSize, template <std::size_t DataSize,
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
std::size_t AlignSize = (std::min)(DataSize, alignof(std::size_t))> std::size_t AlignSize = (std::min)(DataSize, alignof(std::max_align_t))>
#else /*__cplusplus < 201703L*/ #else /*__cplusplus < 201703L*/
std::size_t AlignSize = (alignof(std::size_t) < DataSize) ? alignof(std::size_t) : DataSize> std::size_t AlignSize = (alignof(std::max_align_t) < DataSize) ? alignof(std::max_align_t) : DataSize>
#endif/*__cplusplus < 201703L*/ #endif/*__cplusplus < 201703L*/
struct msg_t; struct msg_t;
@ -43,20 +42,7 @@ struct msg_t {
alignas(AlignSize) byte_t data_[DataSize]; alignas(AlignSize) byte_t data_[DataSize];
}; };
template <typename Policy> buff_t make_cache(void const * data, std::size_t size) {
struct detail_impl {
using queue_t = ipc::queue<msg_t<data_length>, Policy>;
constexpr static void* head_of(queue_t* que) {
return static_cast<void*>(que->elems());
}
constexpr static queue_t* queue_of(ipc::handle_t h) {
return static_cast<queue_t*>(h);
}
static buff_t make_cache(void const * data, std::size_t size) {
auto ptr = mem::alloc(size); auto ptr = mem::alloc(size);
std::memcpy(ptr, data, size); std::memcpy(ptr, data, size);
return { ptr, size, mem::free }; return { ptr, size, mem::free };
@ -76,7 +62,7 @@ struct cache_t {
} }
}; };
static auto& recv_cache() { auto& recv_cache() {
/* /*
<Remarks> thread_local may have some bugs. <Remarks> thread_local may have some bugs.
See: https://sourceforge.net/p/mingw-w64/bugs/727/ See: https://sourceforge.net/p/mingw-w64/bugs/727/
@ -90,6 +76,19 @@ static auto& recv_cache() {
return *rc.create(); return *rc.create();
} }
template <typename Policy>
struct detail_impl {
using queue_t = ipc::queue<msg_t<data_length>, Policy>;
constexpr static void* head_of(queue_t* que) {
return static_cast<void*>(que->elems());
}
constexpr static queue_t* queue_of(ipc::handle_t h) {
return static_cast<queue_t*>(h);
}
static auto& queues_cache() { static auto& queues_cache() {
static tls::pointer<mem::vector<queue_t*>> qc; static tls::pointer<mem::vector<queue_t*>> qc;
return *qc.create(); return *qc.create();
@ -102,7 +101,7 @@ static ipc::handle_t connect(char const * name) {
} }
static void disconnect(ipc::handle_t h) { static void disconnect(ipc::handle_t h) {
queue_t* que = queue_of(h); auto que = queue_of(h);
if (que == nullptr) { if (que == nullptr) {
return; return;
} }

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#include <thread>
#include <utility> #include <utility>
#include <cstring> #include <cstring>