Skip to content

Commit 30686ad

Browse files
authored
Merge pull request #40 from Exerg/develop
Release 1.0
2 parents 39af41e + ab61631 commit 30686ad

28 files changed

Lines changed: 3222 additions & 1865 deletions

.conanfile.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[requires]
2+
gtest/1.8.1@bincrafters/stable

CMakeLists.txt

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,83 @@ cmake_minimum_required(VERSION 3.10) # For CXX_STANDARD 17 property on Visual St
22
project(WaitFreeHashMap)
33
enable_language(CXX)
44

5-
include(cmake/common.cmake)
6-
include(cmake/get_external_dependency.cmake)
5+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
6+
7+
include(ctulu)
8+
include(conan)
9+
include(setup_output_dirs)
710

811
set(CMAKE_DEBUG_POSTFIX _d)
912

1013
# By default build in Release mode
11-
if( NOT CMAKE_BUILD_TYPE )
14+
if (NOT CMAKE_BUILD_TYPE)
1215
set(CMAKE_BUILD_TYPE "Release")
1316
endif()
1417

15-
get_filename_component(root_dir ${CMAKE_SOURCE_DIR} ABSOLUTE)
18+
get_filename_component(root_dir ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE)
1619
get_filename_component(include_dir ${root_dir}/include ABSOLUTE)
17-
make_target(WaitFreeHashMapLibrary "WaitFreeHashMap" INCLUDES ${include_dir} OPTIONS cxx interface)
20+
get_filename_component(tests_dir ${root_dir}/tests ABSOLUTE)
21+
get_filename_component(example_dir ${root_dir}/examples ABSOLUTE)
22+
23+
# set parameter INTERFACE since the library is header only.
24+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
25+
message(STATUS "Activating warning on library")
26+
ctulu_create_target(WaitFreeCollections "WaitFreeCollections" INTERFACE_INCLUDES ${include_dir} CXX 17 INTERFACE)
27+
else()
28+
ctulu_create_target(WaitFreeCollections "WaitFreeCollections" INTERFACE_INCLUDES SYSTEM ${include_dir} CXX 17 INTERFACE)
29+
endif()
30+
31+
option(WFC_BUILD_EXAMPLES "Build project examples" OFF)
32+
option(WFC_BUILD_TESTS "Build project tests" OFF)
33+
option(WFC_BUILD_CLANG_FORMAT_TARGET "Build clang-format target" OFF)
34+
option(WFC_BUILD_ALL "Activate all previous options" OFF)
35+
36+
if (WFC_BUILD_ALL)
37+
set(WFC_BUILD_EXAMPLES ON)
38+
set(WFC_BUILD_TESTS ON)
39+
set(WFC_BUILD_CLANG_FORMAT_TARGET ON)
40+
endif()
41+
42+
if (WFC_BUILD_EXAMPLES)
43+
find_package(Threads REQUIRED)
44+
45+
ctulu_create_target(UnorderedMapExample1 "WaitFreeCollections" FILES ${example_dir}/unordered_map_example.cpp CXX 17 EXECUTABLE W_LEVEL 2)
46+
ctulu_target_warning_from_file(UnorderedMapExample1 ${root_dir}/cmake/warnings.txt)
47+
target_link_libraries(UnorderedMapExample1 Threads::Threads WaitFreeCollections)
48+
endif()
1849

19-
find_package(Threads REQUIRED)
20-
get_external_dependency(googletest external_libs/google_test.cmake)
50+
if (WFC_BUILD_CLANG_FORMAT_TARGET)
51+
set(DIRS "${include_dir}")
52+
if (BUILD_TESTS)
53+
list(APPEND DIRS ${test_dir})
54+
endif()
55+
if (BUILD_EXAMPLES)
56+
list(APPEND DIRS ${example_dir})
57+
endif()
2158

22-
make_target(Sample1 "WaitFreeHashMap" example/main.cpp OPTIONS cxx executable)
23-
set_property(TARGET Sample1 PROPERTY CXX_STANDARD 17)
24-
target_link_libraries(Sample1 ${CMAKE_THREAD_LIBS_INIT} WaitFreeHashMapLibrary gtest_main)
59+
ctulu_generate_clang_format("Clang-format" DIRS ${DIRS})
60+
endif()
61+
62+
if (CMAKE_BUILD_TYPE MATCHES "Debug")
63+
set(WFC_BUILD_TESTS ON)
64+
endif()
65+
66+
if (WFC_BUILD_TESTS)
67+
message(STATUS "Enabling testing")
68+
enable_testing()
69+
70+
find_package(Threads REQUIRED)
71+
72+
conan_check(REQUIRED)
73+
conan_cmake_run(CONANFILE .conanfile.txt BASIC_SETUP CMAKE_TARGETS BUILD missing)
74+
75+
ctulu_create_target(UnorderedMapTests "WaitFreeCollections" DIRS ${tests_dir}/unordered_map/ TEST CXX 17 W_LEVEL 2)
76+
ctulu_target_warning_from_file(UnorderedMapTests ${root_dir}/cmake/warnings.txt)
77+
target_link_libraries(UnorderedMapTests WaitFreeCollections CONAN_PKG::gtest Threads::Threads)
78+
79+
ctulu_create_target(UtilityTests "WaitFreeCollections" DIRS ${tests_dir}/utility/ TEST CXX 17 W_LEVEL 2)
80+
ctulu_target_warning_from_file(UtilityTests ${root_dir}/cmake/warnings.txt)
81+
target_link_libraries(UtilityTests WaitFreeCollections CONAN_PKG::gtest)
82+
endif()
2583

26-
make_target(unit_tests "WaitFreeHashMap" test/single_thread_test.cpp OPTIONS cxx executable)
27-
set_property(TARGET unit_tests PROPERTY CXX_STANDARD 17)
28-
target_link_libraries(unit_tests WaitFreeHashMapLibrary gtest_main)
29-
add_test(NAME example_test COMMAND unit_tests)
84+
#set(CMAKE_VERBOSE_MAKEFILE 1)

README.md

Lines changed: 173 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,183 @@
1-
# WaitFreeHashMap
1+
# WaitFreeCollections
2+
3+
<table>
4+
<tr>
5+
<td><strong>master branch</strong></td>
6+
<td>
7+
<a href="https://ci.appveyor.com/project/CBenoit/waitfreecollections/branch/master"><img src="https://ci.appveyor.com/api/projects/status/sucn29if5de65t01/branch/master?svg=true"></a>
8+
</td>
9+
</tr>
10+
<tr>
11+
<td><strong>develop branch</strong></td>
12+
<td>
13+
<a href="https://ci.appveyor.com/project/CBenoit/waitfreecollections/branch/develop"><img src="https://ci.appveyor.com/api/projects/status/sucn29if5de65t01/branch/develop?svg=true"></a>
14+
</td>
15+
</tr>
16+
<tr>
17+
<td><strong>License</strong></td>
18+
<td>
19+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg"></a>
20+
</td>
21+
</tr>
22+
</table>
23+
24+
A header-only library providing wait-free collections such as hash map and double ended queue (deque).
25+
26+
## Wait-Free Hash Map
27+
28+
An implementation of a wait-free hash map as described in the article
229

3-
An implementation of an hashmap described in the article:
430
> P. Laborde, S. Feldman et D. Dechev, « A Wait-Free Hash Map », <br>
531
> International Journal of Parallel Programming, t. 45, n o 3, p. 421-448, 2017, issn : 1573-7640. <br>
632
> doi : https://doi.org/10.1007/s10766-015-0376-3
733
8-
# Copyright
34+
See [unordered_map example](./examples/unordered_map_example.cpp) in `examples` folder.
935

10-
License: MIT
36+
## Double ended queue (Deque)
37+
38+
WIP
1139

12-
# Requirements
40+
## Requirements
1341

1442
- Compiler which supports C++17
1543
- CMake ≥ 3.10
44+
45+
## Minimal unordered map example
46+
47+
```cpp
48+
#include <iostream>
49+
#include <thread>
50+
51+
#include <wfc/unordered_map.hpp>
52+
53+
constexpr int nbr_threads = 16;
54+
55+
int main()
56+
{
57+
wfc::unordered_map<std::size_t, std::size_t> m(4, nbr_threads, nbr_threads);
58+
59+
std::array<std::thread, nbr_threads> threads;
60+
for (std::size_t i = 0; i < nbr_threads; ++i)
61+
{
62+
threads[i] = std::thread([&m, i]() {
63+
m.insert(i, i);
64+
});
65+
}
66+
67+
for (auto& t: threads)
68+
{
69+
t.join();
70+
}
71+
72+
m.visit([](std::pair<const std::size_t, std::size_t> p) {
73+
std::cout << '[' << p.first << '-' << p.second << "]\n";
74+
});
75+
76+
return 0;
77+
}
78+
```
79+
80+
This should output:
81+
82+
```
83+
[0-0]
84+
[1-1]
85+
[2-2]
86+
[3-3]
87+
[4-4]
88+
[5-5]
89+
[6-6]
90+
[7-7]
91+
[8-8]
92+
[9-9]
93+
[10-10]
94+
[11-11]
95+
[12-12]
96+
[13-13]
97+
[14-14]
98+
[15-15]
99+
```
100+
101+
## How to import the library using CMake
102+
103+
To include the library, you may copy / paste the content of this repository in a subfolder (such as `externals`) or use a git submodule.
104+
105+
Then, in you CMakeLists.txt file, you just have to do something similar to:
106+
107+
```cmake
108+
cmake_minimum_required(VERSION 3.10)
109+
project(MyProject)
110+
enable_language(CXX)
111+
set(CMAKE_CXX_STANDARD 17)
112+
113+
add_subdirectory(externals/WaitFreeCollections)
114+
115+
find_package(Threads REQUIRED) # you'll probably need that one too
116+
117+
add_executable(MyTarget src/main.cpp)
118+
target_link_libraries(MyTarget Threads::Threads WaitFreeCollections)
119+
```
120+
121+
At this point, the project hierarchy looks like:
122+
123+
```
124+
|- CMakeLists.txt
125+
|- src/
126+
|- main.cpp
127+
|- externals/
128+
|- WaitFreeCollections/
129+
|- ...
130+
```
131+
132+
You may try to use the minimal example above as your `main.cpp`.
133+
134+
Also, since this is a header-only library, you may copy / paste the content of the include folder in your
135+
project to achieve similar results (maybe a little bit less clean though).
136+
137+
## Build targets
138+
139+
You don't need to actually build the library beforehand to use it in your project due to the "header-only" nature of it.
140+
The build targets in this repository are for tests, exemples and code formatting.
141+
These are good to know should you contribute to this project or play with the exemples.
142+
143+
First, you need to create a sub-directory to run `cmake` from it. Then you can build using `make`.
144+
145+
```
146+
$ mkdir build
147+
$ cmake .. -DWFC_BUILD_ALL=1
148+
```
149+
150+
By default, everything is build in Release mode. You can pass `-DCMAKE_BUILD_TYPE=Debug` to `cmake` to ask Debug builds.
151+
This will also activate useful features for developing purposes such as the holy warnings.
152+
The `-DWFC_BUILD_ALL=1` parameter will tell CMake to include all our targets in the build process.
153+
154+
CMake will generate several targets that you can build separately using the `--target` parameter:
155+
156+
- `UnorderedMapExample1`
157+
- `UtilityTests`
158+
- `UnorderedMapTests`
159+
- `Clang-format`
160+
161+
For instance, to build the `UnorderedMapTests` run
162+
163+
```
164+
$ cmake --build . --target UnorderedMapTests
165+
```
166+
167+
You can also build everything by not giving any specific target.
168+
Produced executables are inside the `bin` folder.
169+
170+
Note that the `Clang-format` target does not produce anything.
171+
It just run the clang formatter.
172+
Also this target needs to be called explicitly.
173+
174+
For more details, see the [CMakeLists.txt](CMakeLists.txt) file.
175+
176+
## Copyright
177+
178+
License: MIT
179+
180+
Main contributors:
181+
182+
- [Jérôme Boulmier](https://github.com/Lomadriel)
183+
- [Benoît Cortier](https://github.com/CBenoit)

appveyor.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
image: ubuntu
2+
3+
install:
4+
# install conan
5+
- sudo pip install conan --upgrade
6+
7+
before_build:
8+
# update gcc and g++ alternatives
9+
- sudo update-alternatives --set gcc /usr/bin/gcc-8
10+
11+
- gcc --version
12+
- g++ --version
13+
- cmake --version
14+
15+
- mkdir ${APPVEYOR_BUILD_FOLDER}/debug_build
16+
- cd ${APPVEYOR_BUILD_FOLDER}/debug_build
17+
- cmake .. -DWFC_BUILD_ALL=1 -DCMAKE_BUILD_TYPE=Debug
18+
19+
- mkdir ${APPVEYOR_BUILD_FOLDER}/release_build
20+
- cd ${APPVEYOR_BUILD_FOLDER}/release_build
21+
- cmake .. -DWFC_BUILD_ALL=1 -DCMAKE_BUILD_TYPE=Release
22+
23+
build_script:
24+
- cd ${APPVEYOR_BUILD_FOLDER}/debug_build
25+
- make
26+
27+
- cd ${APPVEYOR_BUILD_FOLDER}/release_build
28+
- make
29+
30+
test_script:
31+
- ${APPVEYOR_BUILD_FOLDER}/debug_build/bin/UnorderedMapTests
32+
- ${APPVEYOR_BUILD_FOLDER}/debug_build/bin/UtilityTests
33+
- ${APPVEYOR_BUILD_FOLDER}/release_build/bin/UnorderedMapTests
34+
- ${APPVEYOR_BUILD_FOLDER}/release_build/bin/UtilityTests
35+

0 commit comments

Comments
 (0)