Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
CuckooGraph authored Aug 5, 2024
1 parent b156ab2 commit f660ff5
Show file tree
Hide file tree
Showing 87 changed files with 9,526 additions and 0 deletions.
136 changes: 136 additions & 0 deletions Competitors/third_party/junction/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
cmake_minimum_required(VERSION 2.8.5)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# If this is the root project, issue a project() command so that
# the Visual Studio generator will create an .sln file.
set(CMAKE_CONFIGURATION_TYPES "Debug;RelWithAsserts;RelWithDebInfo" CACHE INTERNAL "Build configs")
project(Junction)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(JUNCTION_WITH_SAMPLES TRUE CACHE BOOL "Include all Junction samples in generated build system")
set(JUNCTION_MAKE_INSTALLABLE TRUE)
set(TURF_MAKE_INSTALLABLE TRUE)
endif()

# Default values, can be overridden by user
set(JUNCTION_USERCONFIG "" CACHE STRING "Optional path to additional config file (relative to root CMakeLists.txt)")
set(JUNCTION_WITH_FOLLY FALSE CACHE BOOL "Use Folly")
set(JUNCTION_WITH_CDS FALSE CACHE BOOL "Use CDS")
set(JUNCTION_WITH_NBDS FALSE CACHE BOOL "Use NBDS")
set(JUNCTION_WITH_TBB FALSE CACHE BOOL "Use TBB")
set(JUNCTION_WITH_TERVEL FALSE CACHE BOOL "Use Tervel")
set(JUNCTION_TRACK_GRAMPA_STATS FALSE CACHE BOOL "Enable stats in ConcurrentMap_Grampa")
set(JUNCTION_USE_STRIPING TRUE CACHE BOOL "Allocate a fixed-size ConditionBank for striped primitives")

# Initialize variables used to collect include dirs/libraries.
set(JUNCTION_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/include")
set(JUNCTION_ALL_INCLUDE_DIRS "${JUNCTION_INCLUDE_DIRS}")
set(JUNCTION_ALL_LIBRARIES junction)
set(JUNCTION_ALL_DLLS "")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

# Add turf targets and import its macros since we use them below
get_filename_component(outerPath "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
set(TURF_ROOT "${outerPath}/turf" CACHE STRING "Path to Turf")
include("${TURF_ROOT}/cmake/Macros.cmake")
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# If this is the root project, apply build settings here so that
# they're applied to all targets
ApplyTurfBuildSettings()
endif()
add_subdirectory(${TURF_ROOT} turf)
list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TURF_INCLUDE_DIRS})
list(APPEND JUNCTION_ALL_LIBRARIES ${TURF_ALL_LIBRARIES})

# Optional: Locate Folly and append it to the list of include dirs/libraries.
if(JUNCTION_WITH_FOLLY)
find_package(Folly REQUIRED)
list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${FOLLY_INCLUDE_DIR})
list(APPEND JUNCTION_ALL_LIBRARIES ${FOLLY_LIBRARIES})
endif()

# Optional: Locate CDS and append it to the list of include dirs/libraries.
if(JUNCTION_WITH_CDS)
find_package(CDS REQUIRED)
list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${CDS_INCLUDE_DIR})
list(APPEND JUNCTION_ALL_LIBRARIES ${CDS_LIBRARY})
list(APPEND JUNCTION_ALL_DLLS ${CDS_DLL})
endif()

# Optional: Locate NBDS and append it to the list of include dirs/libraries.
if(JUNCTION_WITH_NBDS)
set(NBDS_USE_TURF_HEAP FALSE CACHE BOOL "Redirect NBDS's memory allocator to use Turf")
find_package(NBDS REQUIRED)
list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${NBDS_INCLUDE_DIRS})
# If NBDS_USE_TURF_HEAP=1, then NBDS has dependencies on junction, so add junction to the linker
# command line again as needed by the GNU linker.
list(APPEND JUNCTION_ALL_LIBRARIES ${NBDS_LIBRARIES} junction)
endif()

# Optional: Locate Intel TBB and append it to the list of include dirs/libraries.
if(JUNCTION_WITH_TBB)
set(TBB_USE_TURF_HEAP FALSE CACHE BOOL "Redirect TBB's memory allocator to use Turf")
find_package(TBB REQUIRED)
list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TBB_INCLUDE_DIRS})
# If TBB_USE_TURF_HEAP=1, then TBB has dependencies on junction, so add junction to the linker
# command line again as needed by the GNU linker.
list(APPEND JUNCTION_ALL_LIBRARIES ${TBB_LIBRARIES} junction)
endif()

# Optional: Locate Tervel and append it to the list of include dirs/libraries.
if(JUNCTION_WITH_TERVEL)
find_package(Tervel REQUIRED)
list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TERVEL_INCLUDE_DIRS})
list(APPEND JUNCTION_ALL_LIBRARIES ${TERVEL_LIBRARIES})
endif()

# Optional: Locate libcuckoo and append it to the list of include dirs/libraries.
if(JUNCTION_WITH_LIBCUCKOO)
find_package(LibCuckoo REQUIRED)
list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${LIBCUCKOO_INCLUDE_DIRS})
endif()

# If this is the root listfile, add all samples
if((CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) AND JUNCTION_WITH_SAMPLES)
file(GLOB children samples/*)
foreach(child ${children})
if(EXISTS "${child}/CMakeLists.txt")
add_subdirectory("${child}")
endif()
endforeach()
endif()

# Gather source files.
GetFilesWithSourceGroups(GLOB_RECURSE JUNCTION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/junction junction/*.cpp junction/*.h)

# Configure autogenerated headers.
ConfigureFileIfChanged(cmake/junction_config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/junction_config.h" JUNCTION_FILES)
if(JUNCTION_USERCONFIG)
# Interpret JUNCTION_USERCONFIG relative to root project, in case Junction was added as a subdirectory
GetAbsoluteRelativeTo(absPath "${CMAKE_SOURCE_DIR}" "${JUNCTION_USERCONFIG}")
ConfigureFileIfChanged("${absPath}" "${CMAKE_CURRENT_BINARY_DIR}/include/junction_userconfig.h" JUNCTION_FILES)
else()
WriteFileIfDifferent("// JUNCTION_USERCONFIG not set when CMake was run. This is a placeholder file.\n" "${CMAKE_CURRENT_BINARY_DIR}/include/junction_userconfig.h" JUNCTION_FILES)
endif()

# Define library target.
add_library(junction ${JUNCTION_FILES})

# Set include dirs for this library (done last, so it's not inherited by subprojects like Tervel, NBDS).
include_directories(${JUNCTION_ALL_INCLUDE_DIRS})

# Make installable.
if(JUNCTION_MAKE_INSTALLABLE)
install(TARGETS junction DESTINATION lib)
install(DIRECTORY junction/ DESTINATION include/junction FILES_MATCHING PATTERN "*.h")
file(GLOB configHeaders "${CMAKE_CURRENT_BINARY_DIR}/include/*.h")
install(FILES ${configHeaders} DESTINATION include)
endif()

# Export include dirs/libraries to parent project if we were invoked using add_subdirectory().
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(JUNCTION_INCLUDE_DIRS "${JUNCTION_INCLUDE_DIRS}" PARENT_SCOPE)
set(JUNCTION_ALL_INCLUDE_DIRS "${JUNCTION_ALL_INCLUDE_DIRS}" PARENT_SCOPE)
set(JUNCTION_ALL_LIBRARIES "${JUNCTION_ALL_LIBRARIES}" PARENT_SCOPE)
set(JUNCTION_ALL_DLLS "${JUNCTION_ALL_DLLS}" PARENT_SCOPE)
endif()

23 changes: 23 additions & 0 deletions Competitors/third_party/junction/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Junction: Concurrent data structures in C++
Copyright (c) 2016, Jeff Preshing
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
115 changes: 115 additions & 0 deletions Competitors/third_party/junction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
Junction is a library of concurrent data structures in C++. It contains several hash map implementations:

junction::ConcurrentMap_Crude
junction::ConcurrentMap_Linear
junction::ConcurrentMap_Leapfrog
junction::ConcurrentMap_Grampa

[CMake](https://cmake.org/) and [Turf](https://github.com/preshing/turf) are required. See the blog post [New Concurrent Hash Maps for C++](http://preshing.com/20160201/new-concurrent-hash-maps-for-cpp/) for more information.

## License

Junction uses the Simplified BSD License. You can use the source code freely in any project, including commercial applications, as long as you give credit by publishing the contents of the `LICENSE` file in your documentation somewhere.

## Getting Started

If you just want to get the code and look around, start by cloning Junction and Turf into adjacent folders, then run CMake on Junction's `CMakeLists.txt`. You'll want to pass different arguments to `cmake` depending on your platform and IDE.

$ git clone https://github.com/preshing/junction.git
$ git clone https://github.com/preshing/turf.git
$ cd junction
$ mkdir build
$ cd build
$ cmake <additional options> ..

On Unix-like environments, `cmake` will generate a Makefile by default. On Windows, it will create a Visual Studio solution. To use a specific version of Visual Studio:

$ cmake -G "Visual Studio 14 2015" ..

To generate an Xcode project on OS X:

$ cmake -G "Xcode" ..

To generate an Xcode project for iOS:

$ cmake -G "Xcode" -DCMAKE_TOOLCHAIN_FILE=../../turf/cmake/toolchains/iOS.cmake ..

The generated build system will contain separate targets for Junction, Turf, and some sample applications.

![Solution Explorer](/docs/vs-solution.png)

Alternatively, you can run CMake on a specific sample only:

$ cd junction/samples/MapCorrectnessTests
$ mkdir build
$ cd build
$ cmake <additional options> ..

## Adding Junction to Your Project

There are several ways to add Junction to your own C++ project.

1. Add Junction as a build target in an existing CMake-based project.
2. Use CMake to build Junction and Turf, then link the static libraries into your own project.
3. Grab only the source files you need from Junction, copy them to your project and hack them until they build correctly.

Some developers will prefer approach #3, but I encourage you to try approach #1 or #2 instead. It will be easier to grab future updates that way. There are plenty of files in Junction (and Turf) that you don't really need, but it won't hurt to keep them on your hard drive either. And if you link Junction statically, the linker will exclude the parts that aren't used.

### Adding to an Existing CMake Project

If your project is already based on CMake, clone the Junction and Turf source trees somewhere, then call `add_subdirectory` on Junction's root folder from your own CMake script. This will add both Junction and Turf targets to your build system.

For a simple example, see the [junction-sample](https://github.com/preshing/junction-sample) repository.

### Building the Libraries Separately

Generate Junction's build system using the steps described in the *Getting Started* section, then use it to build the libraries you need. Add these to your own build system. Make sure to generate static libraries to avoid linking parts of the library that aren't needed.

If you build the `install` target provided by Junction's CMake script, the build system will output a clean folder containing only the headers and libs that you need. You can add this to your own project using a single include path. Choose the output directory by specifying the `CMAKE_INSTALL_PREFIX` variable to CMake. Additionally, you can specify `JUNCTION_WITH_SAMPLES=OFF` to avoid building the samples. For example:

$ cmake -DCMAKE_INSTALL_PREFIX=~/junction-install -DJUNCTION_WITH_SAMPLES=OFF ..
$ cmake --build . --target install --config RelWithDebInfo

Notes:

* Instead of running the second `cmake` command, which runs the build system, you could run your build system directly. For example, `make install` on Unix, or build the INSTALL project in Visual Studio.
* If using makefiles, you'll probably want to pass the additional option `-DCMAKE_BUILD_TYPE=RelWithDebInfo` to the first `cmake` command.

This will create the following file structure:

![Install folder](/docs/install-folder.png)

## Configuration

When you first run CMake on Junction, Turf will detect the capabilities of your compiler and write the results to a file in the build tree named `turf/include/turf_config.h`. Similarly, Junction will write `include/junction_config.h` to the build tree. You can modify the contents of those files by setting variables when CMake runs. This can be done by passing additional options to `cmake`, or by using an interactive GUI such as `cmake-gui` or `ccmake`.

For example, to configure Turf to use the C++11 standard library, you can set the `TURF_PREFER_CPP11` variable on the command line:

$ cmake -DTURF_PREFER_CPP11=1 ..

Or, using the CMake GUI:

![CMake GUI](/docs/cmake-gui.png)

Many header files in Turf, and some in Junction, are configurable using preprocessor definitions. For example, `turf/Thread.h` will switch between `turf::Thread` implementations depending on the values of `TURF_IMPL_THREAD_PATH` and `TURF_IMPL_THREAD_TYPE`. If those macros are not defined, they will be set to default values based on information from the environment. You can set them directly by providing your own header file and passing it in the `TURF_USERCONFIG` variable when CMake runs. You can place this file anywhere; CMake will copy it to Turf's build tree right next to `include/turf_config.h`.

$ cmake -DTURF_USERCONFIG=path/to/custom/turf_userconfig.h.in ..

The `JUNCTION_USERCONFIG` variable works in a similar way. As an example, take a look at the Python script `junction/samples/MapScalabilityTests/TestAllMaps.py`. This script invokes `cmake` several times, passing a different `junction_userconfig.h.in` file each time. That's how it builds the same test application using different map implementations.

## Rules and Behavior

Currently, Junction maps only work with keys and values that are pointers or pointer-sized integers. The hash function must be invertible, so that every key has a unique hash. Out of all possible keys, a _null_ key must be reserved, and out of all possible values, _null_ and _redirect_ values must be reserved. The defaults are 0 and 1. You can override those defaults by passing custom `KeyTraits` and `ValueTraits` parameters to the template.

Every thread that manipulates a Junction map must periodically call `junction::DefaultQSBR.update`, as mentioned [in the blog post](http://preshing.com/20160201/new-concurrent-hash-maps-for-cpp/). If not, the application will leak memory.

Otherwise, a Junction map is a lot like a big array of `std::atomic<>` variables, where the key is an index into the array. More precisely:

* All of a Junction map's member functions, together with its `Mutator` member functions, are atomic with respect to each other, so you can safely call them from any thread without mutual exclusion.
* If an `assign` [happens before](http://preshing.com/20130702/the-happens-before-relation/) a `get` with the same key, the `get` will return the value it inserted, except if another operation changes the value in between. Any [synchronizing operation](http://preshing.com/20130823/the-synchronizes-with-relation/) will establish this relationship.
* For Linear, Leapfrog and Grampa maps, `assign` is a [release](http://preshing.com/20120913/acquire-and-release-semantics/) operation and `get` is a [consume](http://preshing.com/20140709/the-purpose-of-memory_order_consume-in-cpp11/) operation, so you can safely pass non-atomic information between threads using a pointer. For Crude maps, all operations are relaxed.
* In the current version, you must not `assign` while concurrently using an `Iterator`.

## Feedback

If you have any feedback on improving these steps, feel free to [open an issue](https://github.com/preshing/junction/issues) on GitHub, or send a direct message using the [contact form](http://preshing.com/contact/) on my blog.
12 changes: 12 additions & 0 deletions Competitors/third_party/junction/cmake/junction_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#cmakedefine01 JUNCTION_WITH_FOLLY
#cmakedefine01 JUNCTION_WITH_CDS
#cmakedefine01 JUNCTION_WITH_NBDS
#cmakedefine01 JUNCTION_WITH_TBB
#cmakedefine01 JUNCTION_WITH_TERVEL
#cmakedefine01 JUNCTION_WITH_LIBCUCKOO
#cmakedefine01 NBDS_USE_TURF_HEAP
#cmakedefine01 TBB_USE_TURF_HEAP
#cmakedefine01 JUNCTION_TRACK_GRAMPA_STATS
#cmakedefine01 JUNCTION_USE_STRIPING

#include "junction_userconfig.h"
25 changes: 25 additions & 0 deletions Competitors/third_party/junction/cmake/modules/FindCDS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#FIXME: Deal with builds from different versions of Visual Studio
if(NOT CDS_ROOT)
find_path(CDS_ROOT NAMES cds/init.h PATHS
"${CMAKE_CURRENT_SOURCE_DIR}/../libcds"
"${CMAKE_SOURCE_DIR}/../libcds"
"${CMAKE_CURRENT_LIST_DIR}/../../../libcds"
C:/Jeff/libcds-master) # FIXME: Remove this one.
endif()

find_path(CDS_INCLUDE_DIR cds/init.h ${CDS_ROOT})
if(WIN32) #FIXME: CygWin
find_library(CDS_LIBRARY libcds-x86-vcv140.lib "${CDS_ROOT}/bin/vc.v140/Win32")
find_file(CDS_DLL libcds-x86-vcv140.dll "${CDS_ROOT}/bin/vc.v140/Win32")
else()
find_library(CDS_LIBRARY cds "${CDS_ROOT}/bin/gcc-x86-linux-0" "${CDS_ROOT}/bin/gcc-amd64-linux-0")
endif()

if(CDS_LIBRARY AND CDS_INCLUDE_DIR)
set(CDS_FOUND TRUE)
else()
message("Can't find CDS!")
if(CDS_FIND_REQUIRED)
message(FATAL_ERROR "Missing required package CDS")
endif()
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(FindPackageHandleStandardArgs)

find_library(FOLLY_LIBRARY folly)
find_library(GLOG_LIBRARY glog)
find_path(FOLLY_INCLUDE_DIR "folly/String.h")

set(FOLLY_LIBRARIES ${FOLLY_LIBRARY} ${GLOG_LIBRARY})

FIND_PACKAGE_HANDLE_STANDARD_ARGS(Folly REQUIRED_ARGS FOLLY_INCLUDE_DIR FOLLY_LIBRARIES)
11 changes: 11 additions & 0 deletions Competitors/third_party/junction/cmake/modules/FindLibCuckoo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
find_path(LIBCUCKOO_ROOT include/libcuckoo/cuckoohash_map.hh)

if(LIBCUCKOO_ROOT)
set(LIBCUCKOO_FOUND TRUE)
set(LIBCUCKOO_INCLUDE_DIRS "${LIBCUCKOO_ROOT}/include")
else()
message("Can't find libcuckoo!")
if(LibCuckoo_FIND_REQUIRED)
message(FATAL_ERROR "Missing required package libcuckoo")
endif()
endif()
37 changes: 37 additions & 0 deletions Competitors/third_party/junction/cmake/modules/FindNBDS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
include("${TURF_ROOT}/cmake/Macros.cmake")

find_path(NBDS_ROOT NAMES
include/hashtable.h
include/map.h
include/rcu.h
include/common.h
PATHS
~/nbds)
if(NBDS_ROOT)
set(NBDS_FOUND TRUE)
set(NBDS_INCLUDE_DIRS ${NBDS_ROOT}/include)
GetFilesWithSourceGroups(GLOB_RECURSE NBDS_FILES ${NBDS_ROOT} ${NBDS_ROOT}/include/*
${NBDS_ROOT}/runtime/runtime.c
${NBDS_ROOT}/runtime/rcu.c
${NBDS_ROOT}/runtime/lwt.c
${NBDS_ROOT}/runtime/random.c
${NBDS_ROOT}/datatype/nstring.c
${NBDS_ROOT}/runtime/hazard.c
${NBDS_ROOT}/map/map.c
${NBDS_ROOT}/map/list.c
${NBDS_ROOT}/map/skiplist.c
${NBDS_ROOT}/map/hashtable.c)
if(NBDS_USE_TURF_HEAP)
add_definitions(-DUSE_SYSTEM_MALLOC=1)
else()
GetFilesWithSourceGroups(GLOB NBDS_FILES ${NBDS_ROOT} ${NBDS_ROOT}/runtime/mem.c)
endif()
# FIXME: This is hacky because it relies on inheriting the same include_directories() as Junction
add_library(NBDS ${NBDS_FILES})
set(NBDS_LIBRARIES NBDS)
else()
message("Can't find NBDS!")
if(NBDS_FIND_REQUIRED)
message(FATAL_ERROR "Missing required package NBDS")
endif()
endif()
Loading

0 comments on commit f660ff5

Please sign in to comment.