mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
fix tls's defect
This commit is contained in:
parent
c8cedf11cf
commit
659989fd31
2
include/tls_pointer.h
Normal file → Executable file
2
include/tls_pointer.h
Normal file → Executable file
@ -61,7 +61,7 @@ public:
|
|||||||
|
|
||||||
template <typename... P>
|
template <typename... P>
|
||||||
T* create(P&&... params) {
|
T* create(P&&... params) {
|
||||||
thread_local auto ptr = static_cast<T*>(get(key_));
|
auto ptr = static_cast<T*>(get(key_));
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) {
|
||||||
ptr = new T(std::forward<P>(params)...);
|
ptr = new T(std::forward<P>(params)...);
|
||||||
if (!set(key_, ptr)) {
|
if (!set(key_, ptr)) {
|
||||||
|
|||||||
2
src/ipc.cpp
Normal file → Executable file
2
src/ipc.cpp
Normal file → Executable file
@ -5,7 +5,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <type_traits>
|
#include <type_traits> // aligned_storage_t
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|||||||
4
src/platform/detail.h
Normal file → Executable file
4
src/platform/detail.h
Normal file → Executable file
@ -117,7 +117,7 @@ constexpr decltype(auto) static_switch(std::size_t /*i*/, std::index_sequence<>,
|
|||||||
|
|
||||||
template <typename F, typename D, std::size_t N, std::size_t...I>
|
template <typename F, typename D, std::size_t N, std::size_t...I>
|
||||||
constexpr decltype(auto) static_switch(std::size_t i, std::index_sequence<N, I...>, F&& f, D&& def) {
|
constexpr decltype(auto) static_switch(std::size_t i, std::index_sequence<N, I...>, F&& f, D&& def) {
|
||||||
return (i == N) ? std::forward<F>(f)(std::integral_constant<size_t, N>{}) :
|
return (i == N) ? std::forward<F>(f)(std::integral_constant<std::size_t, N>{}) :
|
||||||
static_switch(i, std::index_sequence<I...>{}, std::forward<F>(f), std::forward<D>(def));
|
static_switch(i, std::index_sequence<I...>{}, std::forward<F>(f), std::forward<D>(def));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ constexpr decltype(auto) static_switch(std::size_t i, F&& f, D&& def) {
|
|||||||
|
|
||||||
template <typename F, std::size_t...I>
|
template <typename F, std::size_t...I>
|
||||||
IPC_CONSTEXPR_ void static_for(std::index_sequence<I...>, F&& f) {
|
IPC_CONSTEXPR_ void static_for(std::index_sequence<I...>, F&& f) {
|
||||||
IPC_UNUSED_ auto expand = { (std::forward<F>(f)(std::integral_constant<size_t, I>{}), 0)... };
|
IPC_UNUSED_ auto expand = { (std::forward<F>(f)(std::integral_constant<std::size_t, I>{}), 0)... };
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::size_t N, typename F>
|
template <std::size_t N, typename F>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user