mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 08:46:45 +08:00
调整目录结构,隔离include路径,修正tls在win下的问题
This commit is contained in:
parent
94c1043025
commit
523d38d247
2
LICENSE
Normal file → Executable file
2
LICENSE
Normal file → Executable file
@ -1,4 +1,4 @@
|
||||
cpp-ipc - A high-performance inter-process communication using shared memory on Linux/Windows.
|
||||
cpp-ipc(libipc) - A high-performance inter-process communication using shared memory on Linux/Windows.
|
||||
|
||||
Copyright (c) 2018 mutouyun (http://orzz.org)
|
||||
|
||||
|
||||
2
README.md
Normal file → Executable file
2
README.md
Normal file → Executable file
@ -1,4 +1,4 @@
|
||||
# cpp-ipc - C++ IPC Library
|
||||
# cpp-ipc(libipc) - C++ IPC Library
|
||||
|
||||
[](https://github.com/mutouyun/cpp-ipc/blob/master/LICENSE) [](https://travis-ci.org/mutouyun/cpp-ipc) [](https://ci.appveyor.com/project/mutouyun/cpp-ipc)
|
||||
|
||||
|
||||
2
demo/chat/main.cpp
Normal file → Executable file
2
demo/chat/main.cpp
Normal file → Executable file
@ -4,7 +4,7 @@
|
||||
#include <regex>
|
||||
#include <atomic>
|
||||
|
||||
#include "ipc.h"
|
||||
#include "libipc/ipc.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
4
include/buffer.h → include/libipc/buffer.h
Normal file → Executable file
4
include/buffer.h → include/libipc/buffer.h
Normal file → Executable file
@ -5,8 +5,8 @@
|
||||
#include <vector>
|
||||
#include <type_traits>
|
||||
|
||||
#include "export.h"
|
||||
#include "def.h"
|
||||
#include "libipc/export.h"
|
||||
#include "libipc/def.h"
|
||||
|
||||
namespace ipc {
|
||||
|
||||
0
include/def.h → include/libipc/def.h
Normal file → Executable file
0
include/def.h → include/libipc/def.h
Normal file → Executable file
0
include/export.h → include/libipc/export.h
Normal file → Executable file
0
include/export.h → include/libipc/export.h
Normal file → Executable file
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "export.h"
|
||||
#include "def.h"
|
||||
#include "buffer.h"
|
||||
#include "shm.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "libipc/export.h"
|
||||
#include "libipc/def.h"
|
||||
#include "libipc/buffer.h"
|
||||
#include "libipc/shm.h"
|
||||
|
||||
namespace ipc {
|
||||
|
||||
using handle_t = void*;
|
||||
@ -3,8 +3,8 @@
|
||||
#include <new>
|
||||
#include <utility>
|
||||
|
||||
#include "export.h"
|
||||
#include "def.h"
|
||||
#include "libipc/export.h"
|
||||
#include "libipc/def.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace mem {
|
||||
2
include/shm.h → include/libipc/shm.h
Normal file → Executable file
2
include/shm.h → include/libipc/shm.h
Normal file → Executable file
@ -2,7 +2,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "export.h"
|
||||
#include "libipc/export.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace shm {
|
||||
@ -4,8 +4,7 @@
|
||||
#include <utility> // std::forward
|
||||
#include <cstddef> // std::size_t
|
||||
|
||||
#include "export.h"
|
||||
#include "platform/detail.h"
|
||||
#include "libipc/export.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace tls {
|
||||
@ -69,7 +68,7 @@ public:
|
||||
template <typename... P>
|
||||
T* create(P&&... params) {
|
||||
destruct();
|
||||
auto ptr = detail::unique_ptr(new T(std::forward<P>(params)...));
|
||||
std::unique_ptr<T> ptr { new T(std::forward<P>(params)...) };
|
||||
if (!tls::set(this, ptr.get())) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -80,7 +79,7 @@ public:
|
||||
T* create_once(P&&... params) {
|
||||
auto p = static_cast<T*>(tls::get(this));
|
||||
if (p == nullptr) {
|
||||
auto ptr = detail::unique_ptr(new T(std::forward<P>(params)...));
|
||||
std::unique_ptr<T> ptr { new T(std::forward<P>(params)...) };
|
||||
if (!tls::set(this, ptr.get())) {
|
||||
return nullptr;
|
||||
}
|
||||
4
include/waiter.h → include/libipc/waiter.h
Normal file → Executable file
4
include/waiter.h → include/libipc/waiter.h
Normal file → Executable file
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "export.h"
|
||||
#include "def.h"
|
||||
#include "libipc/export.h"
|
||||
#include "libipc/def.h"
|
||||
|
||||
namespace ipc {
|
||||
|
||||
@ -11,12 +11,19 @@ include_directories(
|
||||
${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
if(UNIX)
|
||||
file(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/src/platform/*_linux.cpp)
|
||||
file(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/src/libipc/platform/*_linux.cpp)
|
||||
else()
|
||||
file(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/src/platform/*_win.cpp)
|
||||
file(GLOB SRC_FILES ${CMAKE_SOURCE_DIR}/src/libipc/platform/*_win.cpp)
|
||||
endif()
|
||||
aux_source_directory(${CMAKE_SOURCE_DIR}/src SRC_FILES)
|
||||
file(GLOB HEAD_FILES ${CMAKE_SOURCE_DIR}/include/*.h ${CMAKE_SOURCE_DIR}/src/*.inc ${CMAKE_SOURCE_DIR}/src/memory/*.hpp)
|
||||
|
||||
file(GLOB HEAD_FILES
|
||||
${CMAKE_SOURCE_DIR}/include/libipc/*.h
|
||||
${CMAKE_SOURCE_DIR}/src/libipc/*.inc
|
||||
${CMAKE_SOURCE_DIR}/src/libipc/circ/*.h
|
||||
${CMAKE_SOURCE_DIR}/src/libipc/memory/*.h
|
||||
${CMAKE_SOURCE_DIR}/src/libipc/platform/*.h
|
||||
${CMAKE_SOURCE_DIR}/src/libipc/utility/*.h)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES})
|
||||
if(NOT MSVC)
|
||||
|
||||
4
src/buffer.cpp
Normal file → Executable file
4
src/buffer.cpp
Normal file → Executable file
@ -1,5 +1,5 @@
|
||||
#include "buffer.h"
|
||||
#include "pimpl.h"
|
||||
#include "libipc/buffer.h"
|
||||
#include "libipc/utility/pimpl.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
|
||||
29
src/ipc.cpp
29
src/ipc.cpp
@ -1,4 +1,3 @@
|
||||
#include "ipc.h"
|
||||
|
||||
#include <type_traits>
|
||||
#include <cstring>
|
||||
@ -10,22 +9,24 @@
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
#include "def.h"
|
||||
#include "shm.h"
|
||||
#include "tls_pointer.h"
|
||||
#include "pool_alloc.h"
|
||||
#include "queue.h"
|
||||
#include "policy.h"
|
||||
#include "rw_lock.h"
|
||||
#include "log.h"
|
||||
#include "id_pool.h"
|
||||
#include "libipc/ipc.h"
|
||||
#include "libipc/def.h"
|
||||
#include "libipc/shm.h"
|
||||
#include "libipc/tls_pointer.h"
|
||||
#include "libipc/pool_alloc.h"
|
||||
#include "libipc/queue.h"
|
||||
#include "libipc/policy.h"
|
||||
#include "libipc/rw_lock.h"
|
||||
|
||||
#include "memory/resource.h"
|
||||
#include "libipc/utility/log.h"
|
||||
#include "libipc/utility/id_pool.h"
|
||||
|
||||
#include "platform/detail.h"
|
||||
#include "platform/waiter_wrapper.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
|
||||
#include "circ/elem_array.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
#include "libipc/platform/waiter_wrapper.h"
|
||||
|
||||
#include "libipc/circ/elem_array.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
6
src/circ/elem_array.h → src/libipc/circ/elem_array.h
Normal file → Executable file
6
src/circ/elem_array.h → src/libipc/circ/elem_array.h
Normal file → Executable file
@ -4,10 +4,10 @@
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
||||
#include "def.h"
|
||||
#include "libipc/def.h"
|
||||
|
||||
#include "circ/elem_def.h"
|
||||
#include "platform/detail.h"
|
||||
#include "libipc/circ/elem_def.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace circ {
|
||||
4
src/circ/elem_def.h → src/libipc/circ/elem_def.h
Normal file → Executable file
4
src/circ/elem_def.h → src/libipc/circ/elem_def.h
Normal file → Executable file
@ -5,9 +5,9 @@
|
||||
#include <cstdint>
|
||||
#include <new>
|
||||
|
||||
#include "rw_lock.h"
|
||||
#include "libipc/rw_lock.h"
|
||||
|
||||
#include "platform/detail.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace circ {
|
||||
@ -7,12 +7,12 @@
|
||||
#include <cstdlib>
|
||||
#include <cassert> // assert
|
||||
|
||||
#include "def.h"
|
||||
#include "rw_lock.h"
|
||||
#include "concept.h"
|
||||
#include "libipc/def.h"
|
||||
#include "libipc/rw_lock.h"
|
||||
|
||||
#include "memory/allocator_wrapper.h"
|
||||
#include "platform/detail.h"
|
||||
#include "libipc/utility/concept.h"
|
||||
#include "libipc/memory/allocator_wrapper.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace mem {
|
||||
@ -3,7 +3,8 @@
|
||||
#include <limits> // std::numeric_limits
|
||||
#include <utility> // std::forward
|
||||
#include <cstddef>
|
||||
#include <new> // ::new
|
||||
|
||||
#include "libipc/pool_alloc.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace mem {
|
||||
@ -86,11 +87,11 @@ public:
|
||||
|
||||
template <typename... P>
|
||||
static void construct(pointer p, P && ... params) {
|
||||
::new (static_cast<void*>(p)) value_type(std::forward<P>(params) ...);
|
||||
ipc::mem::construct(p, std::forward<P>(params)...);
|
||||
}
|
||||
|
||||
static void destroy(pointer p) {
|
||||
p->~value_type();
|
||||
ipc::mem::destruct(p);
|
||||
}
|
||||
};
|
||||
|
||||
@ -8,11 +8,11 @@
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
|
||||
#include "def.h"
|
||||
#include "libipc/def.h"
|
||||
|
||||
#include "memory/alloc.h"
|
||||
#include "memory/wrapper.h"
|
||||
#include "platform/detail.h"
|
||||
#include "libipc/memory/alloc.h"
|
||||
#include "libipc/memory/wrapper.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace mem {
|
||||
@ -8,15 +8,15 @@
|
||||
#include <cstddef>
|
||||
#include <cassert> // assert
|
||||
#include <type_traits> // std::aligned_storage_t
|
||||
#include <new> // ::new
|
||||
|
||||
#include "def.h"
|
||||
#include "rw_lock.h"
|
||||
#include "tls_pointer.h"
|
||||
#include "concept.h"
|
||||
#include "libipc/def.h"
|
||||
#include "libipc/rw_lock.h"
|
||||
#include "libipc/tls_pointer.h"
|
||||
#include "libipc/pool_alloc.h"
|
||||
|
||||
#include "memory/alloc.h"
|
||||
#include "platform/detail.h"
|
||||
#include "libipc/utility/concept.h"
|
||||
#include "libipc/memory/alloc.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace mem {
|
||||
@ -230,7 +230,9 @@ struct default_mapping_policy {
|
||||
|
||||
template <typename F, typename ... P>
|
||||
IPC_CONSTEXPR_ static void foreach(F && f, P && ... params) {
|
||||
for (std::size_t i = 0; i < classes_size; ++i) f(i, std::forward<P>(params)...);
|
||||
for (std::size_t i = 0; i < classes_size; ++i) {
|
||||
f(i, std::forward<P>(params)...);
|
||||
}
|
||||
}
|
||||
|
||||
IPC_CONSTEXPR_ static std::size_t block_size(std::size_t id) noexcept {
|
||||
@ -240,7 +242,9 @@ struct default_mapping_policy {
|
||||
template <typename F, typename D, typename ... P>
|
||||
IPC_CONSTEXPR_ static auto classify(F && f, D && d, std::size_t size, P && ... params) {
|
||||
std::size_t id = (size - base_size - 1) / iter_size;
|
||||
return (id < classes_size) ? f(id, size, std::forward<P>(params)...) : d(size, std::forward<P>(params)...);
|
||||
return (id < classes_size) ?
|
||||
f(id, size, std::forward<P>(params)...) :
|
||||
d(size, std::forward<P>(params)...);
|
||||
}
|
||||
};
|
||||
|
||||
@ -256,13 +260,13 @@ class variable_wrapper {
|
||||
|
||||
initiator() {
|
||||
MappingP::foreach([](std::size_t id, falc_t * a) {
|
||||
::new (&(a[id])) FixedAlloc(MappingP::block_size(id));
|
||||
ipc::mem::construct(&initiator::at(a, id), MappingP::block_size(id));
|
||||
}, arr_);
|
||||
}
|
||||
|
||||
~initiator() {
|
||||
MappingP::foreach([](std::size_t id, falc_t * a) {
|
||||
initiator::at(a, id).~FixedAlloc();
|
||||
ipc::mem::destruct(&initiator::at(a, id));
|
||||
}, arr_);
|
||||
}
|
||||
|
||||
10
src/platform/shm_linux.cpp → src/libipc/platform/shm_linux.cpp
Normal file → Executable file
10
src/platform/shm_linux.cpp → src/libipc/platform/shm_linux.cpp
Normal file → Executable file
@ -1,4 +1,3 @@
|
||||
#include "shm.h"
|
||||
|
||||
#include <sys/shm.h>
|
||||
#include <sys/stat.h>
|
||||
@ -13,11 +12,12 @@
|
||||
#include <utility>
|
||||
#include <cstring>
|
||||
|
||||
#include "def.h"
|
||||
#include "log.h"
|
||||
#include "pool_alloc.h"
|
||||
#include "libipc/shm.h"
|
||||
#include "libipc/def.h"
|
||||
#include "libipc/pool_alloc.h"
|
||||
|
||||
#include "memory/resource.h"
|
||||
#include "libipc/utility/log.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
|
||||
namespace {
|
||||
|
||||
14
src/platform/shm_win.cpp → src/libipc/platform/shm_win.cpp
Normal file → Executable file
14
src/platform/shm_win.cpp → src/libipc/platform/shm_win.cpp
Normal file → Executable file
@ -1,17 +1,17 @@
|
||||
#include "shm.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "def.h"
|
||||
#include "log.h"
|
||||
#include "pool_alloc.h"
|
||||
#include "libipc/shm.h"
|
||||
#include "libipc/def.h"
|
||||
#include "libipc/pool_alloc.h"
|
||||
|
||||
#include "platform/to_tchar.h"
|
||||
#include "platform/get_sa.h"
|
||||
#include "memory/resource.h"
|
||||
#include "libipc/utility/log.h"
|
||||
#include "libipc/platform/to_tchar.h"
|
||||
#include "libipc/platform/get_sa.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
|
||||
namespace {
|
||||
|
||||
41
src/libipc/platform/tls_detail_win.h
Executable file
41
src/libipc/platform/tls_detail_win.h
Executable file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map> // std::unordered_map
|
||||
#include <cassert> // assert
|
||||
|
||||
#include "libipc/tls_pointer.h"
|
||||
|
||||
#include "libipc/utility/utility.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace tls {
|
||||
|
||||
inline void tls_destruct(key_info const * pkey, void * p) {
|
||||
assert(pkey != nullptr);
|
||||
auto destructor = horrible_cast<destructor_t>(pkey->key_);
|
||||
if (destructor != nullptr) destructor(p);
|
||||
}
|
||||
|
||||
struct tls_recs : public std::unordered_map<key_info const *, void *> {
|
||||
~tls_recs() {
|
||||
for (auto & pair : *this) {
|
||||
tls_destruct(pair.first, pair.second);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
inline tls_recs * tls_get_recs() {
|
||||
thread_local tls_recs * recs_ptr = nullptr;
|
||||
if (recs_ptr == nullptr) {
|
||||
recs_ptr = new tls_recs;
|
||||
}
|
||||
assert(recs_ptr != nullptr);
|
||||
return recs_ptr;
|
||||
}
|
||||
|
||||
inline void at_thread_exit() {
|
||||
delete tls_get_recs();
|
||||
}
|
||||
|
||||
} // namespace tls
|
||||
} // namespace ipc
|
||||
@ -1,12 +1,13 @@
|
||||
#include "tls_pointer.h"
|
||||
|
||||
#include <pthread.h> // pthread_...
|
||||
|
||||
#include <atomic> // std::atomic_thread_fence
|
||||
#include <cassert> // assert
|
||||
|
||||
#include "log.h"
|
||||
#include "utility.h"
|
||||
#include "libipc/tls_pointer.h"
|
||||
|
||||
#include "libipc/utility/log.h"
|
||||
#include "libipc/utility/utility.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace tls {
|
||||
@ -1,8 +1,8 @@
|
||||
#include "tls_pointer.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#include "libipc/platform/tls_detail_win.h"
|
||||
|
||||
/**
|
||||
* @remarks
|
||||
* Windows doesn't support a per-thread destructor with its TLS primitives.
|
||||
@ -19,8 +19,6 @@
|
||||
namespace ipc {
|
||||
namespace tls {
|
||||
|
||||
void at_thread_exit();
|
||||
|
||||
namespace {
|
||||
|
||||
void NTAPI OnTlsCallback(PVOID, DWORD dwReason, PVOID) {
|
||||
46
src/libipc/platform/tls_pointer_win.h
Executable file
46
src/libipc/platform/tls_pointer_win.h
Executable file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic> // std::atomic_thread_fence
|
||||
#include <cassert> // assert
|
||||
|
||||
#include "libipc/tls_pointer.h"
|
||||
|
||||
#include "libipc/platform/tls_detail_win.h"
|
||||
#include "libipc/utility/utility.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace tls {
|
||||
|
||||
bool create(key_info * pkey, destructor_t destructor) {
|
||||
assert(pkey != nullptr);
|
||||
pkey->key_ = horrible_cast<key_t>(destructor);
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
return true;
|
||||
}
|
||||
|
||||
void release(key_info const * pkey) {
|
||||
assert(pkey != nullptr);
|
||||
assert(tls_get_recs() != nullptr);
|
||||
tls_get_recs()->erase(pkey);
|
||||
}
|
||||
|
||||
bool set(key_info const * pkey, void * ptr) {
|
||||
assert(pkey != nullptr);
|
||||
assert(tls_get_recs() != nullptr);
|
||||
(*tls_get_recs())[pkey] = ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void * get(key_info const * pkey) {
|
||||
assert(pkey != nullptr);
|
||||
assert(tls_get_recs() != nullptr);
|
||||
auto const recs = tls_get_recs();
|
||||
auto it = recs->find(pkey);
|
||||
if (it == recs->end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
} // namespace tls
|
||||
} // namespace ipc
|
||||
7
src/platform/to_tchar.h → src/libipc/platform/to_tchar.h
Normal file → Executable file
7
src/platform/to_tchar.h → src/libipc/platform/to_tchar.h
Normal file → Executable file
@ -8,10 +8,9 @@
|
||||
#include <codecvt>
|
||||
#include <cstring>
|
||||
|
||||
#include "concept.h"
|
||||
|
||||
#include "platform/detail.h"
|
||||
#include "memory/resource.h"
|
||||
#include "libipc/utility/concept.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace detail {
|
||||
8
src/platform/waiter_linux.h → src/libipc/platform/waiter_linux.h
Normal file → Executable file
8
src/platform/waiter_linux.h → src/libipc/platform/waiter_linux.h
Normal file → Executable file
@ -10,11 +10,11 @@
|
||||
#include <atomic>
|
||||
#include <tuple>
|
||||
|
||||
#include "def.h"
|
||||
#include "log.h"
|
||||
#include "libipc/def.h"
|
||||
|
||||
#include "platform/detail.h"
|
||||
#include "memory/resource.h"
|
||||
#include "libipc/utility/log.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace detail {
|
||||
16
src/platform/waiter_win.h → src/libipc/platform/waiter_win.h
Normal file → Executable file
16
src/platform/waiter_win.h → src/libipc/platform/waiter_win.h
Normal file → Executable file
@ -5,15 +5,15 @@
|
||||
#include <atomic>
|
||||
#include <tuple>
|
||||
|
||||
#include "rw_lock.h"
|
||||
#include "pool_alloc.h"
|
||||
#include "log.h"
|
||||
#include "shm.h"
|
||||
#include "libipc/rw_lock.h"
|
||||
#include "libipc/pool_alloc.h"
|
||||
#include "libipc/shm.h"
|
||||
|
||||
#include "platform/to_tchar.h"
|
||||
#include "platform/get_sa.h"
|
||||
#include "platform/detail.h"
|
||||
#include "memory/resource.h"
|
||||
#include "libipc/utility/log.h"
|
||||
#include "libipc/platform/to_tchar.h"
|
||||
#include "libipc/platform/get_sa.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace detail {
|
||||
10
src/platform/waiter_wrapper.h → src/libipc/platform/waiter_wrapper.h
Normal file → Executable file
10
src/platform/waiter_wrapper.h → src/libipc/platform/waiter_wrapper.h
Normal file → Executable file
@ -4,15 +4,15 @@
|
||||
#include <atomic>
|
||||
#include <utility>
|
||||
|
||||
#include "shm.h"
|
||||
#include "libipc/shm.h"
|
||||
|
||||
#include "memory/resource.h"
|
||||
#include "platform/detail.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || \
|
||||
defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || \
|
||||
defined(WINCE) || defined(_WIN32_WCE)
|
||||
|
||||
#include "platform/waiter_win.h"
|
||||
#include "libipc/platform/waiter_win.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace detail {
|
||||
@ -58,7 +58,7 @@ public:
|
||||
|
||||
#else /*!WIN*/
|
||||
|
||||
#include "platform/waiter_linux.h"
|
||||
#include "libipc/platform/waiter_linux.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace detail {
|
||||
6
src/policy.h → src/libipc/policy.h
Normal file → Executable file
6
src/policy.h → src/libipc/policy.h
Normal file → Executable file
@ -2,10 +2,10 @@
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "def.h"
|
||||
#include "prod_cons.h"
|
||||
#include "libipc/def.h"
|
||||
#include "libipc/prod_cons.h"
|
||||
|
||||
#include "circ/elem_array.h"
|
||||
#include "libipc/circ/elem_array.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace policy {
|
||||
@ -5,11 +5,12 @@
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
|
||||
#include "def.h"
|
||||
#include "platform/detail.h"
|
||||
#include "circ/elem_def.h"
|
||||
#include "log.h"
|
||||
#include "utility.h"
|
||||
#include "libipc/def.h"
|
||||
|
||||
#include "libipc/platform/detail.h"
|
||||
#include "libipc/circ/elem_def.h"
|
||||
#include "libipc/utility/log.h"
|
||||
#include "libipc/utility/utility.h"
|
||||
|
||||
namespace ipc {
|
||||
|
||||
@ -11,13 +11,13 @@
|
||||
#include <string>
|
||||
#include <cassert> // assert
|
||||
|
||||
#include "def.h"
|
||||
#include "shm.h"
|
||||
#include "log.h"
|
||||
#include "rw_lock.h"
|
||||
#include "libipc/def.h"
|
||||
#include "libipc/shm.h"
|
||||
#include "libipc/rw_lock.h"
|
||||
|
||||
#include "platform/detail.h"
|
||||
#include "circ/elem_def.h"
|
||||
#include "libipc/utility/log.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
#include "libipc/circ/elem_def.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace detail {
|
||||
4
src/id_pool.h → src/libipc/utility/id_pool.h
Normal file → Executable file
4
src/id_pool.h → src/libipc/utility/id_pool.h
Normal file → Executable file
@ -3,9 +3,9 @@
|
||||
#include <type_traits> // std::aligned_storage_t
|
||||
#include <cstring> // std::memcmp
|
||||
|
||||
#include "def.h"
|
||||
#include "libipc/def.h"
|
||||
|
||||
#include "platform/detail.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
|
||||
namespace ipc {
|
||||
|
||||
0
src/log.h → src/libipc/utility/log.h
Normal file → Executable file
0
src/log.h → src/libipc/utility/log.h
Normal file → Executable file
4
src/pimpl.h → src/libipc/utility/pimpl.h
Normal file → Executable file
4
src/pimpl.h → src/libipc/utility/pimpl.h
Normal file → Executable file
@ -3,8 +3,8 @@
|
||||
#include <new>
|
||||
#include <utility>
|
||||
|
||||
#include "concept.h"
|
||||
#include "pool_alloc.h"
|
||||
#include "libipc/utility/concept.h"
|
||||
#include "libipc/pool_alloc.h"
|
||||
|
||||
namespace ipc {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include <cstddef> // std::size_t
|
||||
#include <new> // std::hardware_destructive_interference_size
|
||||
|
||||
#include "platform/detail.h"
|
||||
#include "libipc/platform/detail.h"
|
||||
|
||||
namespace ipc {
|
||||
|
||||
0
src/waiter_template.inc → src/libipc/waiter_template.inc
Normal file → Executable file
0
src/waiter_template.inc → src/libipc/waiter_template.inc
Normal file → Executable file
@ -1,76 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map> // std::unordered_map
|
||||
#include <atomic> // std::atomic_thread_fence
|
||||
#include <cassert> // assert
|
||||
|
||||
#include "log.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace tls {
|
||||
|
||||
namespace {
|
||||
|
||||
inline void tls_destruct(key_info const * pkey, void * p) {
|
||||
assert(pkey != nullptr);
|
||||
auto destructor = horrible_cast<destructor_t>(pkey->key_);
|
||||
if (destructor != nullptr) destructor(p);
|
||||
}
|
||||
|
||||
struct tls_recs : public std::unordered_map<key_info const *, void *> {
|
||||
~tls_recs() {
|
||||
for (auto & pair : *this) {
|
||||
tls_destruct(pair.first, pair.second);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
inline tls_recs * tls_get_recs() {
|
||||
thread_local tls_recs * recs_ptr = nullptr;
|
||||
if (recs_ptr == nullptr) {
|
||||
recs_ptr = new tls_recs;
|
||||
}
|
||||
assert(recs_ptr != nullptr);
|
||||
return recs_ptr;
|
||||
}
|
||||
|
||||
} // internal-linkage
|
||||
|
||||
void at_thread_exit() {
|
||||
delete tls_get_recs();
|
||||
}
|
||||
|
||||
bool create(key_info * pkey, destructor_t destructor) {
|
||||
assert(pkey != nullptr);
|
||||
pkey->key_ = horrible_cast<key_t>(destructor);
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
return true;
|
||||
}
|
||||
|
||||
void release(key_info const * pkey) {
|
||||
assert(pkey != nullptr);
|
||||
assert(tls_get_recs() != nullptr);
|
||||
tls_get_recs()->erase(pkey);
|
||||
}
|
||||
|
||||
bool set(key_info const * pkey, void * ptr) {
|
||||
assert(pkey != nullptr);
|
||||
assert(tls_get_recs() != nullptr);
|
||||
(*tls_get_recs())[pkey] = ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void * get(key_info const * pkey) {
|
||||
assert(pkey != nullptr);
|
||||
assert(tls_get_recs() != nullptr);
|
||||
auto const recs = tls_get_recs();
|
||||
auto it = recs->find(pkey);
|
||||
if (it == recs->end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
} // namespace tls
|
||||
} // namespace ipc
|
||||
@ -1,6 +1,6 @@
|
||||
#include "pool_alloc.h"
|
||||
#include "libipc/pool_alloc.h"
|
||||
|
||||
#include "memory/resource.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace mem {
|
||||
|
||||
7
src/shm.cpp
Normal file → Executable file
7
src/shm.cpp
Normal file → Executable file
@ -1,10 +1,11 @@
|
||||
#include "shm.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "pimpl.h"
|
||||
#include "memory/resource.h"
|
||||
#include "libipc/shm.h"
|
||||
|
||||
#include "libipc/utility/pimpl.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
|
||||
namespace ipc {
|
||||
namespace shm {
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
#include "tls_pointer.h"
|
||||
|
||||
#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || \
|
||||
defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || \
|
||||
defined(WINCE) || defined(_WIN32_WCE)
|
||||
#include "platform/tls_pointer_win.h"
|
||||
#include "libipc/platform/tls_pointer_win.h"
|
||||
#else /*!WIN*/
|
||||
#include "platform/tls_pointer_linux.h"
|
||||
#include "libipc/platform/tls_pointer_linux.h"
|
||||
#endif/*!WIN*/
|
||||
|
||||
13
src/waiter.cpp
Normal file → Executable file
13
src/waiter.cpp
Normal file → Executable file
@ -1,9 +1,10 @@
|
||||
#include "waiter.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "pimpl.h"
|
||||
#include "platform/waiter_wrapper.h"
|
||||
#include "libipc/waiter.h"
|
||||
|
||||
#include "libipc/utility/pimpl.h"
|
||||
#include "libipc/platform/waiter_wrapper.h"
|
||||
|
||||
#undef IPC_PP_CAT_
|
||||
#undef IPC_PP_JOIN_T__
|
||||
@ -23,7 +24,7 @@ namespace ipc {
|
||||
#define IPC_OBJECT_TYPE_OPEN_PARS_
|
||||
#define IPC_OBJECT_TYPE_OPEN_ARGS_
|
||||
|
||||
#include "waiter_template.inc"
|
||||
#include "libipc/waiter_template.inc"
|
||||
|
||||
bool mutex::lock() {
|
||||
return impl(p_)->h_.lock();
|
||||
@ -41,7 +42,7 @@ bool mutex::unlock() {
|
||||
#define IPC_OBJECT_TYPE_OPEN_PARS_ , long count
|
||||
#define IPC_OBJECT_TYPE_OPEN_ARGS_ , count
|
||||
|
||||
#include "waiter_template.inc"
|
||||
#include "libipc/waiter_template.inc"
|
||||
|
||||
bool semaphore::wait(std::size_t tm) {
|
||||
return impl(p_)->h_.wait(tm);
|
||||
@ -59,7 +60,7 @@ bool semaphore::post(long count) {
|
||||
#define IPC_OBJECT_TYPE_OPEN_PARS_
|
||||
#define IPC_OBJECT_TYPE_OPEN_ARGS_
|
||||
|
||||
#include "waiter_template.inc"
|
||||
#include "libipc/waiter_template.inc"
|
||||
|
||||
bool condition::wait(mutex& mtx, std::size_t tm) {
|
||||
return impl(p_)->h_.wait(impl(mtx.p_)->h_, tm);
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#include "ipc.h"
|
||||
#include "buffer.h"
|
||||
#include "memory/resource.h"
|
||||
#include "libipc/ipc.h"
|
||||
#include "libipc/buffer.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
|
||||
#include "test.h"
|
||||
#include "thread_pool.h"
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
|
||||
#include "capo/random.hpp"
|
||||
|
||||
#include "memory/resource.h"
|
||||
#include "pool_alloc.h"
|
||||
#include "libipc/memory/resource.h"
|
||||
#include "libipc/pool_alloc.h"
|
||||
|
||||
// #include "gperftools/tcmalloc.h"
|
||||
|
||||
|
||||
@ -6,10 +6,10 @@
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "prod_cons.h"
|
||||
#include "policy.h"
|
||||
#include "circ/elem_array.h"
|
||||
#include "queue.h"
|
||||
#include "libipc/prod_cons.h"
|
||||
#include "libipc/policy.h"
|
||||
#include "libipc/circ/elem_array.h"
|
||||
#include "libipc/queue.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
#include <cstdint>
|
||||
#include <thread>
|
||||
|
||||
#include "shm.h"
|
||||
#include "libipc/shm.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace ipc::shm;
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
#include "capo/spin_lock.hpp"
|
||||
#include "capo/type_name.hpp"
|
||||
|
||||
#include "rw_lock.h"
|
||||
#include "tls_pointer.h"
|
||||
#include "libipc/rw_lock.h"
|
||||
#include "libipc/tls_pointer.h"
|
||||
|
||||
#include "test.h"
|
||||
#include "thread_pool.h"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
#include "platform/waiter_wrapper.h"
|
||||
#include "libipc/platform/waiter_wrapper.h"
|
||||
#include "test.h"
|
||||
|
||||
namespace {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user