Skip to content

Commit 130e4d6

Browse files
authored
Merge pull request #48 from mutouyun/issue-47
Issue 47
2 parents 57e5298 + 69e1586 commit 130e4d6

File tree

13 files changed

+32
-425
lines changed

13 files changed

+32
-425
lines changed

.github/workflows/c-cpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: C/C++ CI
22

33
on:
44
push:
5-
branches: [ master, develop ]
5+
branches: [ master, develop, issue-* ]
66
pull_request:
77
branches: [ master, develop ]
88

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ option(LIBIPC_BUILD_DEMOS "Build all of libipc's own demos." OFF)
77
set(CMAKE_CXX_STANDARD 17)
88
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
99
if(NOT MSVC)
10-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
10+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
1111
endif()
1212

1313
include_directories(${CMAKE_SOURCE_DIR}/include)
@@ -19,14 +19,14 @@ set(LIBIPC_PROJECT_DIR ${PROJECT_SOURCE_DIR})
1919
add_subdirectory(src)
2020

2121
if (LIBIPC_BUILD_TESTS)
22-
set(GOOGLETEST_VERSION 1.10.0)
23-
add_subdirectory(3rdparty/gtest)
24-
add_subdirectory(test)
22+
set(GOOGLETEST_VERSION 1.10.0)
23+
add_subdirectory(3rdparty/gtest)
24+
add_subdirectory(test)
2525
endif()
2626

2727
if (LIBIPC_BUILD_DEMOS)
28-
add_subdirectory(demo/chat)
29-
add_subdirectory(demo/msg_que)
28+
add_subdirectory(demo/chat)
29+
add_subdirectory(demo/msg_que)
3030
endif()
3131

3232
install(

include/libipc/export.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
*/
4545

4646
#ifndef IPC_EXPORT
47-
#if defined(__IPC_LIBRARY__)
47+
#if defined(LIBIPC_LIBRARY_SHARED_BUILDING__)
4848
# define IPC_EXPORT IPC_DECL_EXPORT
49-
#else
49+
#elif defined(LIBIPC_LIBRARY_SHARED_USING__)
5050
# define IPC_EXPORT IPC_DECL_IMPORT
51+
#else
52+
# define IPC_EXPORT
5153
#endif
5254
#endif /*IPC_EXPORT*/

include/libipc/tls_pointer.h

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
project(ipc)
22

3-
add_compile_options(-D__IPC_LIBRARY__)
3+
option(LIBIPC_BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
44

55
if(NOT MSVC)
66
add_compile_options(-fPIC)
@@ -26,11 +26,21 @@ file(GLOB HEAD_FILES
2626
${LIBIPC_PROJECT_DIR}/src/libipc/platform/*.h
2727
${LIBIPC_PROJECT_DIR}/src/libipc/utility/*.h)
2828

29-
add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES})
29+
if (LIBIPC_BUILD_SHARED_LIBS)
30+
add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES})
31+
target_compile_definitions(${PROJECT_NAME}
32+
INTERFACE
33+
LIBIPC_LIBRARY_SHARED_USING__
34+
PRIVATE
35+
LIBIPC_LIBRARY_SHARED_BUILDING__)
36+
else()
37+
add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${HEAD_FILES})
38+
endif()
39+
3040
if(NOT MSVC)
3141
target_link_libraries(${PROJECT_NAME} PUBLIC
32-
pthread
33-
$<$<NOT:$<STREQUAL:${CMAKE_SYSTEM_NAME},Windows>>:rt>)
42+
pthread
43+
$<$<NOT:$<STREQUAL:${CMAKE_SYSTEM_NAME},Windows>>:rt>)
3444
endif()
3545

3646
install(

src/ipc.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "libipc/ipc.h"
1414
#include "libipc/def.h"
1515
#include "libipc/shm.h"
16-
#include "libipc/tls_pointer.h"
1716
#include "libipc/pool_alloc.h"
1817
#include "libipc/queue.h"
1918
#include "libipc/policy.h"
@@ -253,19 +252,6 @@ struct conn_info_head {
253252
ipc::waiter cc_waiter_, wt_waiter_, rd_waiter_;
254253
ipc::shm::handle acc_h_;
255254

256-
/*
257-
* <Remarks> thread_local may have some bugs.
258-
*
259-
* <Reference>
260-
* - https://sourceforge.net/p/mingw-w64/bugs/727/
261-
* - https://sourceforge.net/p/mingw-w64/bugs/527/
262-
* - https://github.com/Alexpux/MINGW-packages/issues/2519
263-
* - https://github.com/ChaiScript/ChaiScript/issues/402
264-
* - https://developercommunity.visualstudio.com/content/problem/124121/thread-local-variables-fail-to-be-initialized-when.html
265-
* - https://software.intel.com/en-us/forums/intel-c-compiler/topic/684827
266-
*/
267-
ipc::tls::pointer<ipc::unordered_map<msg_id_t, cache_t>> recv_cache_;
268-
269255
conn_info_head(char const * name)
270256
: name_ {name}
271257
, cc_id_ {(cc_acc() == nullptr) ? 0 : cc_acc()->fetch_add(1, std::memory_order_relaxed)}
@@ -286,7 +272,8 @@ struct conn_info_head {
286272
}
287273

288274
auto& recv_cache() {
289-
return *recv_cache_.create_once();
275+
thread_local ipc::unordered_map<msg_id_t, cache_t> tls;
276+
return tls;
290277
}
291278
};
292279

src/libipc/memory/wrapper.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "libipc/def.h"
1313
#include "libipc/rw_lock.h"
14-
#include "libipc/tls_pointer.h"
1514
#include "libipc/pool_alloc.h"
1615

1716
#include "libipc/utility/concept.h"
@@ -155,18 +154,16 @@ class async_wrapper {
155154
};
156155

157156
friend class alloc_proxy;
158-
159157
using ref_t = alloc_proxy&;
160-
using tls_t = tls::pointer<alloc_proxy>;
161158

162-
tls_t tls_;
163159
std::function<ref_t()> get_alloc_;
164160

165161
public:
166162
template <typename ... P>
167163
async_wrapper(P ... pars) {
168164
get_alloc_ = [this, pars ...]()->ref_t {
169-
return *tls_.create_once(this, pars ...);
165+
thread_local alloc_proxy tls(pars ...);
166+
return tls;
170167
};
171168
}
172169

src/libipc/platform/tls_detail_win.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/libipc/platform/tls_pointer_linux.h

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)