From df6714001e73e0abcfb25a6201fbb0ef0617cdbe Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Tue, 11 Nov 2025 13:15:51 -0400 Subject: [PATCH 01/34] A0 Add OS conditions to cmake presets --- CMakePresets.json | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 1a7f24bc..bdafdece 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -30,6 +30,11 @@ "inherits": "base", "cacheVariables": { "VCPKG_TARGET_TRIPLET": "x64-windows-static" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" } }, { @@ -38,6 +43,11 @@ "inherits": "base", "cacheVariables": { "VCPKG_TARGET_TRIPLET": "x64-linux" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" } }, { @@ -50,6 +60,11 @@ "VCPKG_TARGET_ARCHITECTURE": "arm64", "VCPKG_OSX_ARCHITECTURES": "arm64", "VCPKG_CRT_LINKAGE": "dynamic" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" } }, { @@ -201,7 +216,9 @@ "name": "msvc2022-debug", "inherits": "base-package", "configurePreset": "msvc2022-debug", - "configurations": [ "Debug" ] + "configurations": [ + "Debug" + ] }, { "name": "msvc2022-shared", @@ -212,19 +229,25 @@ "name": "msvc2022-shared-debug", "inherits": "base-package", "configurePreset": "msvc2022-shared-debug", - "configurations": [ "Debug" ] + "configurations": [ + "Debug" + ] }, { "name": "gcc", "inherits": "base-package", "configurePreset": "gcc", - "configurations": [ "Debug" ] + "configurations": [ + "Debug" + ] }, { "name": "clang-osx", "inherits": "base-package", "configurePreset": "clang-osx", - "configurations": [ "Debug" ] + "configurations": [ + "Debug" + ] } ], "workflowPresets": [ From 1ca7ae37171f1582b15795cb32318ddfa328bbce Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Tue, 11 Nov 2025 13:17:35 -0400 Subject: [PATCH 02/34] A0 Fix cmake 4.0+ warning in VersionInfoTarget Notes: - Silences warning about policy CMP0174 blah blah cmake_parse_arguments setting empty string args blah blah Refs: - "https://cmake.org/cmake/help/latest/policy/CMP0174.html" --- cmake/VersionInfoTarget.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/VersionInfoTarget.cmake b/cmake/VersionInfoTarget.cmake index 7e473198..3210b039 100644 --- a/cmake/VersionInfoTarget.cmake +++ b/cmake/VersionInfoTarget.cmake @@ -24,7 +24,7 @@ SOFTWARE. # # source: # -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.10...4.0) #[=============================================================================[ adds two cmake targets: From dfb61d44395dae2e69e082fa0651d16b0464cf07 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Tue, 11 Nov 2025 13:25:33 -0400 Subject: [PATCH 03/34] A0 Remove hardcoded build jobs from presets --- CMakePresets.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index bdafdece..66b338f1 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -145,8 +145,7 @@ { "name": "base-build", "hidden": true, - "targets": "install", - "jobs": 4 + "targets": "install" }, { "name": "msvc2022", From 127d188e50174f1feb1cfa3726b69f9e8fb6e985 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Tue, 24 Feb 2026 19:52:19 -0400 Subject: [PATCH 04/34] A0 Always store *.sh scripts with LF line endings --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 62973832..5e2dd59e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ *.ty linguist-language=TypeScript +*.sh text eol=LF From 06aaa70ee20be3ebc55378efd8837900525b6f05 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Tue, 24 Feb 2026 19:58:52 -0400 Subject: [PATCH 05/34] A0 Add CMake presets for 'clang-windows' --- CMakePresets.json | 185 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 156 insertions(+), 29 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 66b338f1..13ce9285 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -99,10 +99,30 @@ "CMAKE_CXX_COMPILER": "clang++" } }, + { + "name": "clang-windows", + "inherits": "base-windows", + "displayName": "Clang - Release", + "description": "Using clang compiler", + "generator": "Ninja", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl.exe", + "CMAKE_CXX_COMPILER": "clang-cl.exe" + } + }, + { + "name": "clang-windows-debug", + "inherits": "clang-windows", + "displayName": "Clang - Debug", + "description": "Using clang compiler (debug build)", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, { "name": "msvc2022", "inherits": "base-windows", - "displayName": "Visual Studio Community 2022 - amd64 - Release", + "displayName": "Visual Studio 2022 - amd64 - Release", "description": "Using compilers for Visual Studio 17 2022", "generator": "Visual Studio 17 2022", "toolset": "host=x64", @@ -115,7 +135,7 @@ { "name": "msvc2022-debug", "inherits": "msvc2022", - "displayName": "Visual Studio Community 2022 - amd64 - Debug", + "displayName": "Visual Studio 2022 - amd64 - Debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } @@ -123,7 +143,7 @@ { "name": "msvc2022-shared", "inherits": "msvc2022", - "displayName": "Visual Studio Community 2022 - amd64 - Release (.dll dependencies)", + "displayName": "Visual Studio 2022 - amd64 - Release (.dll dependencies)", "description": "Using compilers for Visual Studio 17 2022", "generator": "Visual Studio 17 2022", "toolset": "host=x64", @@ -135,7 +155,7 @@ { "name": "msvc2022-shared-debug", "inherits": "msvc2022-shared", - "displayName": "Visual Studio Community 2022 - amd64 - Debug (.dll dependencies)", + "displayName": "Visual Studio 2022 - amd64 - Debug (.dll dependencies)", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } @@ -148,50 +168,94 @@ "targets": "install" }, { - "name": "msvc2022", + "name": "base-build-windows", + "hidden": true, + "inherits": "base-build", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "base-build-linux", + "hidden": true, + "inherits": "base-build", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "base-build-osx", + "hidden": true, "inherits": "base-build", - "displayName": "Visual Studio Community 2022 - amd64 - Release", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "clang-windows", + "inherits": "base-build-windows", + "displayName": "Clang - Windows - Release", + "configurePreset": "clang-windows", + "configuration": "Release" + }, + { + "name": "clang-windows-debug", + "inherits": "base-build-windows", + "displayName": "Clang - Windows - Debug", + "configurePreset": "clang-windows-debug", + "configuration": "Debug" + }, + { + "name": "msvc2022", + "inherits": "base-build-windows", + "displayName": "Visual Studio 2022 - amd64 - Release", "configurePreset": "msvc2022", "configuration": "Release" }, { "name": "msvc2022-debug", - "inherits": "base-build", - "displayName": "Visual Studio Community 2022 - amd64 - Debug", + "inherits": "base-build-windows", + "displayName": "Visual Studio 2022 - amd64 - Debug", "configurePreset": "msvc2022-debug", "configuration": "Debug" }, { "name": "msvc2022-shared", - "inherits": "base-build", - "displayName": "Visual Studio Community 2022 - amd64 - Release (.dll dependencies)", + "inherits": "base-build-windows", + "displayName": "Visual Studio 2022 - amd64 - Release (.dll dependencies)", "configurePreset": "msvc2022-shared", "configuration": "Release" }, { "name": "msvc2022-shared-debug", - "inherits": "base-build", - "displayName": "Visual Studio Community 2022 - amd64 - Debug (.dll dependencies)", + "inherits": "base-build-windows", + "displayName": "Visual Studio 2022 - amd64 - Debug (.dll dependencies)", "configurePreset": "msvc2022-shared-debug", "configuration": "Debug" }, { "name": "gcc", - "inherits": "base-build", + "inherits": "base-build-linux", "displayName": "GCC - amd64 - Release", "configurePreset": "gcc", "configuration": "Release" }, { "name": "gcc-ninja", - "inherits": "base-build", + "inherits": "base-build-linux", "displayName": "GCC - amd64 - Release", "configurePreset": "gcc-ninja", "configuration": "Release" }, { "name": "clang-osx", - "inherits": "base-build", + "inherits": "base-build-osx", "displayName": "Clang - amd64 - Release", "configurePreset": "clang-osx", "configuration": "Release" @@ -207,13 +271,56 @@ "packageDirectory": "${sourceDir}/_packages/${presetName}" }, { - "name": "msvc2022", + "name": "base-package-windows", + "hidden": true, "inherits": "base-package", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "base-package-linux", + "hidden": true, + "inherits": "base-package", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "base-package-osx", + "hidden": true, + "inherits": "base-package", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "clang-windows", + "inherits": "base-package-windows", + "configurePreset": "clang-windows" + }, + { + "name": "clang-windows-debug", + "inherits": "base-package-windows", + "configurePreset": "clang-windows-debug", + "configurations": [ + "Debug" + ] + }, + { + "name": "msvc2022", + "inherits": "base-package-windows", "configurePreset": "msvc2022" }, { "name": "msvc2022-debug", - "inherits": "base-package", + "inherits": "base-package-windows", "configurePreset": "msvc2022-debug", "configurations": [ "Debug" @@ -221,12 +328,12 @@ }, { "name": "msvc2022-shared", - "inherits": "base-package", + "inherits": "base-package-windows", "configurePreset": "msvc2022-shared" }, { "name": "msvc2022-shared-debug", - "inherits": "base-package", + "inherits": "base-package-windows", "configurePreset": "msvc2022-shared-debug", "configurations": [ "Debug" @@ -234,22 +341,42 @@ }, { "name": "gcc", - "inherits": "base-package", - "configurePreset": "gcc", - "configurations": [ - "Debug" - ] + "inherits": "base-package-linux", + "configurePreset": "gcc" }, { "name": "clang-osx", - "inherits": "base-package", - "configurePreset": "clang-osx", - "configurations": [ - "Debug" - ] + "inherits": "base-package-osx", + "configurePreset": "clang-osx" } ], "workflowPresets": [ + { + "name": "clang-windows", + "steps": [ + { + "type": "configure", + "name": "clang-windows" + }, + { + "type": "build", + "name": "clang-windows" + } + ] + }, + { + "name": "clang-windows-debug", + "steps": [ + { + "type": "configure", + "name": "clang-windows-debug" + }, + { + "type": "build", + "name": "clang-windows-debug" + } + ] + }, { "name": "msvc2022", "steps": [ From 77e7bdaf17a64f08fab598feabd76986a26b32f6 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Tue, 24 Feb 2026 20:02:30 -0400 Subject: [PATCH 06/34] A0 Change windows 'msvc' presets to VS 2026 --- CMakePresets.json | 94 +++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 13ce9285..71b1a799 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -120,11 +120,11 @@ } }, { - "name": "msvc2022", + "name": "msvc2026", "inherits": "base-windows", - "displayName": "Visual Studio 2022 - amd64 - Release", - "description": "Using compilers for Visual Studio 17 2022", - "generator": "Visual Studio 17 2022", + "displayName": "Visual Studio 2026 - amd64 - Release", + "description": "Using compilers for Visual Studio 18 2026", + "generator": "Visual Studio 18 2026", "toolset": "host=x64", "architecture": "x64", "cacheVariables": { @@ -133,19 +133,19 @@ } }, { - "name": "msvc2022-debug", - "inherits": "msvc2022", - "displayName": "Visual Studio 2022 - amd64 - Debug", + "name": "msvc2026-debug", + "inherits": "msvc2026", + "displayName": "Visual Studio 2026 - amd64 - Debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } }, { - "name": "msvc2022-shared", - "inherits": "msvc2022", - "displayName": "Visual Studio 2022 - amd64 - Release (.dll dependencies)", - "description": "Using compilers for Visual Studio 17 2022", - "generator": "Visual Studio 17 2022", + "name": "msvc2026-shared", + "inherits": "msvc2026", + "displayName": "Visual Studio 2026 - amd64 - Release (.dll dependencies)", + "description": "Using compilers for Visual Studio 18 2026", + "generator": "Visual Studio 18 2026", "toolset": "host=x64", "architecture": "x64", "cacheVariables": { @@ -153,9 +153,9 @@ } }, { - "name": "msvc2022-shared-debug", - "inherits": "msvc2022-shared", - "displayName": "Visual Studio 2022 - amd64 - Debug (.dll dependencies)", + "name": "msvc2026-shared-debug", + "inherits": "msvc2026-shared", + "displayName": "Visual Studio 2026 - amd64 - Debug (.dll dependencies)", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } @@ -212,31 +212,31 @@ "configuration": "Debug" }, { - "name": "msvc2022", + "name": "msvc2026", "inherits": "base-build-windows", - "displayName": "Visual Studio 2022 - amd64 - Release", - "configurePreset": "msvc2022", + "displayName": "Visual Studio 2026 - amd64 - Release", + "configurePreset": "msvc2026", "configuration": "Release" }, { - "name": "msvc2022-debug", + "name": "msvc2026-debug", "inherits": "base-build-windows", - "displayName": "Visual Studio 2022 - amd64 - Debug", - "configurePreset": "msvc2022-debug", + "displayName": "Visual Studio 2026 - amd64 - Debug", + "configurePreset": "msvc2026-debug", "configuration": "Debug" }, { - "name": "msvc2022-shared", + "name": "msvc2026-shared", "inherits": "base-build-windows", - "displayName": "Visual Studio 2022 - amd64 - Release (.dll dependencies)", - "configurePreset": "msvc2022-shared", + "displayName": "Visual Studio 2026 - amd64 - Release (.dll dependencies)", + "configurePreset": "msvc2026-shared", "configuration": "Release" }, { - "name": "msvc2022-shared-debug", + "name": "msvc2026-shared-debug", "inherits": "base-build-windows", - "displayName": "Visual Studio 2022 - amd64 - Debug (.dll dependencies)", - "configurePreset": "msvc2022-shared-debug", + "displayName": "Visual Studio 2026 - amd64 - Debug (.dll dependencies)", + "configurePreset": "msvc2026-shared-debug", "configuration": "Debug" }, { @@ -314,27 +314,27 @@ ] }, { - "name": "msvc2022", + "name": "msvc2026", "inherits": "base-package-windows", - "configurePreset": "msvc2022" + "configurePreset": "msvc2026" }, { - "name": "msvc2022-debug", + "name": "msvc2026-debug", "inherits": "base-package-windows", - "configurePreset": "msvc2022-debug", + "configurePreset": "msvc2026-debug", "configurations": [ "Debug" ] }, { - "name": "msvc2022-shared", + "name": "msvc2026-shared", "inherits": "base-package-windows", - "configurePreset": "msvc2022-shared" + "configurePreset": "msvc2026-shared" }, { - "name": "msvc2022-shared-debug", + "name": "msvc2026-shared-debug", "inherits": "base-package-windows", - "configurePreset": "msvc2022-shared-debug", + "configurePreset": "msvc2026-shared-debug", "configurations": [ "Debug" ] @@ -378,54 +378,54 @@ ] }, { - "name": "msvc2022", + "name": "msvc2026", "steps": [ { "type": "configure", - "name": "msvc2022" + "name": "msvc2026" }, { "type": "build", - "name": "msvc2022" + "name": "msvc2026" } ] }, { - "name": "msvc2022-debug", + "name": "msvc2026-debug", "steps": [ { "type": "configure", - "name": "msvc2022-debug" + "name": "msvc2026-debug" }, { "type": "build", - "name": "msvc2022-debug" + "name": "msvc2026-debug" } ] }, { - "name": "msvc2022-shared", + "name": "msvc2026-shared", "steps": [ { "type": "configure", - "name": "msvc2022-shared" + "name": "msvc2026-shared" }, { "type": "build", - "name": "msvc2022-shared" + "name": "msvc2026-shared" } ] }, { - "name": "msvc2022-shared-debug", + "name": "msvc2026-shared-debug", "steps": [ { "type": "configure", - "name": "msvc2022-shared-debug" + "name": "msvc2026-shared-debug" }, { "type": "build", - "name": "msvc2022-shared-debug" + "name": "msvc2026-shared-debug" } ] }, From 73f359fee5f9e8b1abfcf36788ec6656dae378f8 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 12:19:01 -0400 Subject: [PATCH 07/34] A0 Add .claude/ to .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 1b4a732e..69b9a8ea 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ vcpkg_installed vcpkg *.log *.err +# agents +.agents/* +.claude/* +*.local.json From 6ed513c3ae915d58d57b5374505e9ff4c4ef6e91 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 12:20:01 -0400 Subject: [PATCH 08/34] A0 Add 'CL=/MP' to CMake MSVC presets --- CMakePresets.json | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 71b1a799..71c8e609 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -67,6 +67,18 @@ "rhs": "Darwin" } }, + { + "name": "base-msvc", + "hidden": true, + "inherits": "base-windows", + "generator": "Visual Studio 18 2026", + "toolset": "host=x64", + "architecture": "x64", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl.exe", + "CMAKE_CXX_COMPILER": "cl.exe" + } + }, { "name": "gcc", "inherits": "base-linux", @@ -121,42 +133,29 @@ }, { "name": "msvc2026", - "inherits": "base-windows", - "displayName": "Visual Studio 2026 - amd64 - Release", - "description": "Using compilers for Visual Studio 18 2026", - "generator": "Visual Studio 18 2026", - "toolset": "host=x64", - "architecture": "x64", - "cacheVariables": { - "CMAKE_C_COMPILER": "cl.exe", - "CMAKE_CXX_COMPILER": "cl.exe" - } + "inherits": "base-msvc" }, { "name": "msvc2026-debug", - "inherits": "msvc2026", - "displayName": "Visual Studio 2026 - amd64 - Debug", + "inherits": "base-msvc", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } }, { "name": "msvc2026-shared", - "inherits": "msvc2026", + "inherits": "base-msvc", "displayName": "Visual Studio 2026 - amd64 - Release (.dll dependencies)", - "description": "Using compilers for Visual Studio 18 2026", - "generator": "Visual Studio 18 2026", - "toolset": "host=x64", - "architecture": "x64", "cacheVariables": { "VCPKG_TARGET_TRIPLET": "x64-windows" } }, { "name": "msvc2026-shared-debug", - "inherits": "msvc2026-shared", + "inherits": "base-msvc", "displayName": "Visual Studio 2026 - amd64 - Debug (.dll dependencies)", "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-windows", "CMAKE_BUILD_TYPE": "Debug" } } @@ -175,6 +174,9 @@ "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" + }, + "environment": { + "CL": "/MP$penv{NUMBER_OF_PROCESSORS} $penv{CL}" } }, { From 659be6f9f894bd3c151900d6f21f50ba9649e480 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 12:29:07 -0400 Subject: [PATCH 09/34] A0 Fix unubilium cmake target on windwows --- unibilium/CMakeLists.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/unibilium/CMakeLists.txt b/unibilium/CMakeLists.txt index 41ea9ed6..eab74626 100644 --- a/unibilium/CMakeLists.txt +++ b/unibilium/CMakeLists.txt @@ -25,14 +25,18 @@ target_compile_definitions(unibilium PRIVATE TERMINFO_DIRS="${TERMINFO_DIRS}" ) -target_compile_options(unibilium PRIVATE - -Wall - -O2 - -std=c99 -) +if (WIN32) + set(_warning_flags /W3) +else() + set(_warning_flags -Wall) +endif() + +target_compile_options(unibilium PRIVATE ${_warning_flags}) set_target_properties(unibilium PROPERTIES POSITION_INDEPENDENT_CODE ON + C_STANDARD 99 + C_STANDARD_REQUIRED ON ) target_include_directories(unibilium PUBLIC From 66a3b6ff4aa9207f31f7b447309a8ad0ad493412 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 13:39:32 -0400 Subject: [PATCH 10/34] A0 Add basic CLAUDE.md --- CLAUDE.md | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..d6d2911f --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,151 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +**Ty** is a compiled, statically-typed programming language implementation written in C (C23 +standard). It includes a bytecode VM, optional JIT compiler (DynASM-based), garbage collector, +coroutine system, and a standard library written in Ty itself. + +## Build System + +### CMake (primary, cross-platform) + +Dependencies are managed via vcpkg. +The vcpkg root is expected at `_vcpkg/` (set in `CMakePresets.json`). +The `./scripts/setup-vcpkg.sh` script can be used to perform the initial clone of vcpkg into +the `_vcpkg` subdirectory. + +```bash +# Configure +cmake --preset + +# Build +cmake --build --preset +``` + +**Available presets** (see [CMakePresets.json](CMakePresets.json)): +- `msvc2026` / `msvc2026-debug` — Windows, Visual Studio 2026, MSVC +- `clang-windows` / `clang-windows-debug` — Windows, Clang (Ninja) +- `gcc` / `gcc-ninja` — Linux, GCC +- `clang-osx` — macOS, Apple Clang + +Build output goes to `_build//`. Binaries produced: `ty`, `tyls`, optionally `typrof`. + +### Makefile (Unix/Linux/macOS only) + +```bash +make # Default optimized build (-Og -g3) +make RELEASE=1 # Optimized release (-O3, LTO, mcpu=native) +make DEBUG=1 # Debug with ASAN +make TDEBUG=1 # Debug with ThreadSanitizer +make tyls # Build language server +make install # Install to /usr/local/bin and ~/.ty/ +make clean +``` + +**Makefile flags** (combine freely): +- `NO_JIT=1` — Disable JIT +- `LOG=1` — Enable internal logging (disabled by default via `-DTY_NO_LOG`) +- `NO_NSYNC=1` — Disable nsync synchronization +- `JEMALLOC=1` — Use jemalloc instead of mimalloc +- `LTO=1` — Force link-time optimization +- `PROFILE_TYPES=1` — Enable type system profiling + +**Pre-build requirements** (Makefile): +- `gperf` generates [include/keywords.h](include/keywords.h) from + [src/keywords.gperf](src/keywords.gperf) +- `luajit` + DynASM generates `src/jit_x64.h` or `src/jit_arm64.h` from `.dasc` files + +## Running Tests + +Tests require a built `ty` executable in the project root (or on PATH): + +```bash +make test # Runs: ./ty test.ty + +# Run a single test file +./ty --test tests/array.ty + +# Filter tests by name pattern +TEST_FILTER="dict" ./ty test.ty +``` + +The test runner [test.ty](test.ty) is written in Ty itself. It runs test files from +[tests/](tests/) in parallel with a 5-second timeout per test. + +## Architecture + +### Compilation Pipeline + +``` +Source text + → Lexer (lex.c / token.c) + → Parser + AST (parse.c) + → Type checker + Compiler → Bytecode (compiler.c, types.c) + → VM execution (vm.c) + └─ optional JIT (jit.c + jit_x64.dasc / jit_arm64.dasc) +``` + +### Core Source Modules ([src/](src/)) + +| File | Role | +|----------------|---------------------------------------------------------------| +| `compiler.c` | Type checking, compilation, constant folding (~20K LOC) | +| `types.c` | Type system: inference, constraints, refinements (~12K LOC) | +| `vm.c` | Bytecode interpreter, exception handling, coroutines (~11K LOC) | +| `functions.c` | Built-in functions and standard library glue (~10K LOC) | +| `parse.c` | Parser, AST construction (~7.5K LOC) | +| `jit.c` | JIT driver; arch-specific code in `.dasc` files (~7K LOC) | +| `gc.c` | Incremental mark-and-sweep GC with arena allocators | +| `ffi.c` | Foreign function interface via libffi | +| `value.c` | Core `Value` type (8-byte tagged union) | +| `scope.c` | Symbol tables and lexical scoping | +| `class.c` | Class system with inheritance and traits | + +### Value Representation + +All Ty values are a packed 8-byte `Value` struct (defined in [include/ty.h](include/ty.h)) with a +type byte, tag byte, and a union payload. This is the central type used throughout the VM and +compiler. + +### Executables + +- **ty** — main interpreter (entry: `ty.c`) +- **tyls** — language server (entry: `tyls.c`; compiled with `-DTY_LS`) +- **typrof** — profiler (entry: `ty.c`; compiled with `-DTY_PROFILER`) + +### Vendored Libraries + +| Library | Location | Purpose | +|------------|---------------------------------------|------------------------------------------| +| libco | [libco/](libco/) | Coroutines (lightweight cooperative threads) | +| dtoa | [dtoa/](dtoa/) | Swift's double-to-string conversion | +| libmd | [libmd/](libmd/) | MD5/SHA hash functions | +| unibilium | [unibilium/](unibilium/) | Terminal capability database | +| nsync | [nsync/](nsync/) | Google synchronization primitives (optional) | +| DynASM | [LuaJIT/dynasm/](LuaJIT/dynasm/) | JIT code generation DSL | + +### vcpkg Dependencies + +`libffi`, `sqlite3`, `utf8proc`, `pcre2`, `xxHash`, `mimalloc` + +### Standard Library + +~50 Ty modules in [lib/](lib/) — installed to `~/.ty/`. +Key modules: `prelude.ty`, `io.ty`, `os.ty`, `ffi.ty`, `http.ty`, `json.ty`, `regex.ty`, +`sqlite.ty`, `term.ty`. + +## Platform Notes + +- **Linux/macOS** + - Primary development platforms + - CMake and Makefile are both supported + +- **Windows** + - Currently unsupported, does not compile on Windows. + - Uses CMake + MSVC or clang-cl + - Required file: `ioctl_constants.h` is created as an empty stub + - Required file: `keywords.h` must be created on a platform with access to gperf and copied + into `include/keywords.h` From 389989f8aaf4018b4331245c72b0490d5e0298a9 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 13:41:12 -0400 Subject: [PATCH 11/34] A0 Small cmake fixes --- CMakeLists.txt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03c64421..f52d127a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,13 +148,20 @@ endif() set(_file_keywords_h ${_autogen_dir}/include/keywords.h) set(_gperf_input ${PROJECT_SOURCE_DIR}/src/keywords.gperf) -find_program(GPERF gperf) -if(GPERF) +set(_tgt_keywords_h "KeywordsH") +add_library(${_tgt_keywords_h} INTERFACE) +target_include_directories(${_tgt_keywords_h} + INTERFACE + ${_autogen_dir}/include +) + +find_program(GPERF_EXECUTABLE gperf) +if(GPERF_EXECUTABLE) add_custom_command( OUTPUT ${_file_keywords_h} COMMAND - ${GPERF} "${_gperf_input}" > "${_file_keywords_h}.tmp" + ${GPERF_EXECUTABLE} "${_gperf_input}" > "${_file_keywords_h}.tmp" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_file_keywords_h}.tmp" @@ -340,6 +347,7 @@ target_link_libraries(${_tgt_ty_interface} ${_tgt_ty_interface_version_info} ${_tgt_ioctlconstants_h} ${_tgt_errnoconstants_h} + ${_tgt_keywords_h} Threads::Threads # pthreads (or equivalent) libco mimalloc-static From a516ace1020d6d15715c3f3d7ce524a43d404bbb Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 13:43:10 -0400 Subject: [PATCH 12/34] A0 Fix libmd compilation on MSVC --- libmd/src/md2hl.c | 1 - libmd/src/md4hl.c | 1 - libmd/src/md5hl.c | 1 - libmd/src/rmd160hl.c | 2 -- libmd/src/sha1hl.c | 1 - libmd/src/sha224hl.c | 1 - libmd/src/sha256hl.c | 1 - libmd/src/sha384hl.c | 1 - libmd/src/sha512_256hl.c | 1 - libmd/src/sha512hl.c | 1 - 10 files changed, 11 deletions(-) diff --git a/libmd/src/md2hl.c b/libmd/src/md2hl.c index 6e21be1b..cb1fa68b 100644 --- a/libmd/src/md2hl.c +++ b/libmd/src/md2hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* diff --git a/libmd/src/md4hl.c b/libmd/src/md4hl.c index 3212abf1..9279e65a 100644 --- a/libmd/src/md4hl.c +++ b/libmd/src/md4hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* diff --git a/libmd/src/md5hl.c b/libmd/src/md5hl.c index 1adf81db..a31dad81 100644 --- a/libmd/src/md5hl.c +++ b/libmd/src/md5hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* diff --git a/libmd/src/rmd160hl.c b/libmd/src/rmd160hl.c index 27e892ef..97814d67 100644 --- a/libmd/src/rmd160hl.c +++ b/libmd/src/rmd160hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* @@ -10,7 +9,6 @@ * ---------------------------------------------------------------------------- */ - #include #include diff --git a/libmd/src/sha1hl.c b/libmd/src/sha1hl.c index 854353cd..866692da 100644 --- a/libmd/src/sha1hl.c +++ b/libmd/src/sha1hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* diff --git a/libmd/src/sha224hl.c b/libmd/src/sha224hl.c index acab8afd..bd9643ba 100644 --- a/libmd/src/sha224hl.c +++ b/libmd/src/sha224hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* diff --git a/libmd/src/sha256hl.c b/libmd/src/sha256hl.c index e802abd7..8662baa2 100644 --- a/libmd/src/sha256hl.c +++ b/libmd/src/sha256hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* diff --git a/libmd/src/sha384hl.c b/libmd/src/sha384hl.c index 281b5a6f..66c18026 100644 --- a/libmd/src/sha384hl.c +++ b/libmd/src/sha384hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* diff --git a/libmd/src/sha512_256hl.c b/libmd/src/sha512_256hl.c index e921bfad..14b3aa0b 100644 --- a/libmd/src/sha512_256hl.c +++ b/libmd/src/sha512_256hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* diff --git a/libmd/src/sha512hl.c b/libmd/src/sha512hl.c index 0b5fee47..fa0b5e54 100644 --- a/libmd/src/sha512hl.c +++ b/libmd/src/sha512hl.c @@ -1,4 +1,3 @@ -#include /* $OpenBSD: helper.c,v 1.9 2010/01/08 13:30:21 oga Exp $ */ /* From 081aa5754792888b7413ed6cd3e7ae731b7de934 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 13:43:56 -0400 Subject: [PATCH 13/34] A0 Add include/keywords.h to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 69b9a8ea..dc73159e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ vcpkg_installed vcpkg *.log *.err +# autogenerated file(s) +include/keywords.h # agents .agents/* .claude/* From 512c490d97778bd54897f542fb03ed8e610709db Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 13:47:00 -0400 Subject: [PATCH 14/34] A0 Tweak CMake style --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f52d127a..02ea3375 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,8 +216,8 @@ add_subdirectory(unibilium) # DynASM JIT code generation # --- -find_program(LUAJIT luajit) -if(LUAJIT) +find_program(LUAJIT_EXECUTABLE luajit) +if(LUAJIT_EXECUTABLE) if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") set(_jit_dasc ${PROJECT_SOURCE_DIR}/src/jit_arm64.dasc) set(_jit_hdr ${PROJECT_SOURCE_DIR}/src/jit_arm64.h) @@ -228,7 +228,7 @@ if(LUAJIT) add_custom_command( OUTPUT ${_jit_hdr} - COMMAND ${LUAJIT} ${PROJECT_SOURCE_DIR}/LuaJIT/dynasm/dynasm.lua + COMMAND ${LUAJIT_EXECUTABLE} ${PROJECT_SOURCE_DIR}/LuaJIT/dynasm/dynasm.lua -o ${_jit_hdr} ${_jit_dasc} DEPENDS ${_jit_dasc} COMMENT "Generating JIT emission header from ${_jit_dasc}" From 67cdfbffe9934eef9c4d9e44c1260b28c512385e Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 14:05:09 -0400 Subject: [PATCH 15/34] A0 Use `_tgt_` cmake vars for project-defined targets --- CMakeLists.txt | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02ea3375..0fa1d937 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,22 +183,27 @@ endif() # --- # target: libco # --- -add_library(libco) -target_sources(libco PRIVATE libco/libco.c) -target_compile_definitions(libco PRIVATE LIBCO_MP) + +set(_tgt_libco libco) +add_library(${_tgt_libco}) +target_sources(${_tgt_libco} PRIVATE libco/libco.c) +target_compile_definitions(${_tgt_libco} PRIVATE LIBCO_MP) # --- # target: dtoa # --- -add_library(dtoa) -target_sources(dtoa PRIVATE dtoa/SwiftDtoa.c) +set(_tgt_dtoa dtoa) +add_library(${_tgt_dtoa}) +target_sources(${_tgt_dtoa} PRIVATE dtoa/SwiftDtoa.c) # --- # target: libmd::md # --- + +set(_tgt_libmd libmd::md) add_subdirectory(libmd) # libmd uses C_VISIBILITY_PRESET hidden which breaks ThinLTO symbol resolution -set_target_properties(md PROPERTIES INTERPROCEDURAL_OPTIMIZATION FALSE) +set_target_properties(${_tgt_libmd} PROPERTIES INTERPROCEDURAL_OPTIMIZATION FALSE) # --- # target: nsync @@ -348,15 +353,15 @@ target_link_libraries(${_tgt_ty_interface} ${_tgt_ioctlconstants_h} ${_tgt_errnoconstants_h} ${_tgt_keywords_h} + ${_tgt_libco} + ${_tgt_libmd} + ${_tgt_dtoa} Threads::Threads # pthreads (or equivalent) - libco mimalloc-static xxHash::xxhash utf8proc::utf8proc PCRE2::8BIT unofficial::libffi::libffi - libmd::md - dtoa unofficial::sqlite3::sqlite3 $<$>:${CMAKE_DL_LIBS}> $<$>:m> From 40f09df9dd749dc46dc152522c336229286d6621 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 15:29:43 -0400 Subject: [PATCH 16/34] A0 Fix dockerfile for latest ubuntu --- docker/ubuntu-buildtools.dockerfile | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docker/ubuntu-buildtools.dockerfile b/docker/ubuntu-buildtools.dockerfile index b2398061..893ce403 100644 --- a/docker/ubuntu-buildtools.dockerfile +++ b/docker/ubuntu-buildtools.dockerfile @@ -27,18 +27,28 @@ RUN apt-get update \ "git" \ "pkg-config" \ "zip" \ + "luajit" \ + "gperf" \ "unzip" \ "build-essential" \ && apt-get clean -y \ && rm -fr /var/lib/apt/lists -# -- switch container default user +# -- switch container default user to 'user' RUN chmod -R 777 /opt ARG USER_ID ARG GROUP_ID -RUN groupadd -g ${GROUP_ID} "user" \ - && useradd -u ${USER_ID} -g "user" -m "user" +RUN if getent group ${GROUP_ID} >/dev/null 2>&1; then \ + groupmod -n "user" $(getent group ${GROUP_ID} | cut -d: -f1); \ + else \ + groupadd -g ${GROUP_ID} "user"; \ + fi \ + && if id -u ${USER_ID} >/dev/null 2>&1; then \ + usermod -l "user" -g "user" -d /home/user -m $(getent passwd ${USER_ID} | cut -d: -f1); \ + else \ + useradd -u ${USER_ID} -g "user" -m "user"; \ + fi USER "user" # -- download vcpkg From d52c4e4e4ca77213a5e8e73314032a7cc132af4a Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 15:29:58 -0400 Subject: [PATCH 17/34] A0 Update default docker cmake version => 4.2.3 --- docker/build-image-ubuntu-buildtools.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/build-image-ubuntu-buildtools.sh b/docker/build-image-ubuntu-buildtools.sh index a18957c5..658622e0 100755 --- a/docker/build-image-ubuntu-buildtools.sh +++ b/docker/build-image-ubuntu-buildtools.sh @@ -7,7 +7,7 @@ _project_dir=$(readlink -f "${_script_dir}/..") # input variables # --- -_default_cmake_version="3.21.7" +_default_cmake_version="4.2.3" _default_ubuntu_version="latest" _default_image_prefix="ty" _default_image_tag="\${UBUNTU_VERSION}" From 87e9fb3cdfe3fd266d7665ce411cdaeef7147f39 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 15:30:09 -0400 Subject: [PATCH 18/34] A0 Fix cmake error --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fa1d937..0d51d4a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,7 +203,7 @@ target_sources(${_tgt_dtoa} PRIVATE dtoa/SwiftDtoa.c) set(_tgt_libmd libmd::md) add_subdirectory(libmd) # libmd uses C_VISIBILITY_PRESET hidden which breaks ThinLTO symbol resolution -set_target_properties(${_tgt_libmd} PROPERTIES INTERPROCEDURAL_OPTIMIZATION FALSE) +set_target_properties(md PROPERTIES INTERPROCEDURAL_OPTIMIZATION FALSE) # --- # target: nsync From 51e4838355e93c671ff868bd7367a3cea55fcb20 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 15:49:13 -0400 Subject: [PATCH 19/34] A0 Use unbuffered sed in build-in-docker.sh Notes: - The previous approach was doing internal buffering, causing the lines of stderr and stdout to be interleaved in a weird way. - I could also have used the `-W interactive` argument to awk, but that is unintuitive compared to the nicely named sed flag. --- scripts/build-in-docker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build-in-docker.sh b/scripts/build-in-docker.sh index 26a7b424..b40dcebe 100755 --- a/scripts/build-in-docker.sh +++ b/scripts/build-in-docker.sh @@ -113,8 +113,8 @@ fi # --- ( - exec 1> >(>&1 awk '{print "[docker-stdout]: " $0}') # prefix stdout - exec 2> >(>&2 awk '{print "[docker-stderr]: " $0}') # prefix stderr + exec 1> >(>&1 sed --unbuffered 's/^/[docker-stdout]: /') # prefix stdout + exec 2> >(>&2 sed --unbuffered 's/^/[docker-stderr]: /') # prefix stderr docker run \ --rm \ From aeafc0a34799b591261ac1749aa2077b28cefcf4 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 15:55:23 -0400 Subject: [PATCH 20/34] A0 Allow colored cmake output from build-in-docker --- scripts/build-in-docker.sh | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/build-in-docker.sh b/scripts/build-in-docker.sh index b40dcebe..987460dc 100755 --- a/scripts/build-in-docker.sh +++ b/scripts/build-in-docker.sh @@ -122,18 +122,19 @@ fi -v "${_project_dir}:/ty/src" \ "${_arg_docker_image}" \ bash -c " - set -vx \ - && cd /ty/src \ - && cmake -S . -B '${_build_dir}' -G 'Unix Makefiles' \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX='${_install_dir}' \ - -DVCPKG_INSTALL_OPTIONS='--no-print-usage' \ - -DCMAKE_TOOLCHAIN_FILE=\${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake \ - -DVCPKG_INSTALLED_DIR='/opt/vcpkg_installed' \ - -DVCPKG_TARGET_TRIPLET='x64-linux' \ - && cmake --build '${_build_dir}' --parallel \ - && cmake --install '${_build_dir}' \ - " +export CMAKE_COLOR_DIAGNOSTICS=ON +set -evx +cd /ty/src +cmake -S . -B '${_build_dir}' -G 'Unix Makefiles' \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX='${_install_dir}' \ + -DVCPKG_INSTALL_OPTIONS='--no-print-usage' \ + -DCMAKE_TOOLCHAIN_FILE=\${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake \ + -DVCPKG_INSTALLED_DIR='/opt/vcpkg_installed' \ + -DVCPKG_TARGET_TRIPLET='x64-linux' +cmake --build '${_build_dir}' --parallel +cmake --install '${_build_dir}' +" ) || { __print_errormsg "docker run exited with non-zero error code" exit 1 From 5b426e7464a934790bf3c15f984677d6cc4334d6 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 16:51:10 -0400 Subject: [PATCH 21/34] A0 Remove build-in-ubuntu16 and ubuntu18 Notes: - Some of the vcpkg dependencies don't work in ubuntu 16 or 18 anymore --- docker/ubuntu-buildtools.dockerfile | 1 + ...{build-in-docker-ubuntu16.sh => build-in-docker-ubuntu22.sh} | 2 +- ...{build-in-docker-ubuntu18.sh => build-in-docker-ubuntu24.sh} | 2 +- scripts/build-in-docker.sh | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) rename scripts/{build-in-docker-ubuntu16.sh => build-in-docker-ubuntu22.sh} (51%) rename scripts/{build-in-docker-ubuntu18.sh => build-in-docker-ubuntu24.sh} (51%) diff --git a/docker/ubuntu-buildtools.dockerfile b/docker/ubuntu-buildtools.dockerfile index 893ce403..c18a53ef 100644 --- a/docker/ubuntu-buildtools.dockerfile +++ b/docker/ubuntu-buildtools.dockerfile @@ -30,6 +30,7 @@ RUN apt-get update \ "luajit" \ "gperf" \ "unzip" \ + "ninja-build" \ "build-essential" \ && apt-get clean -y \ && rm -fr /var/lib/apt/lists diff --git a/scripts/build-in-docker-ubuntu16.sh b/scripts/build-in-docker-ubuntu22.sh similarity index 51% rename from scripts/build-in-docker-ubuntu16.sh rename to scripts/build-in-docker-ubuntu22.sh index 77170453..e1a5117a 100755 --- a/scripts/build-in-docker-ubuntu16.sh +++ b/scripts/build-in-docker-ubuntu22.sh @@ -4,4 +4,4 @@ set -eo pipefail _script_dir=$(readlink -f "$(dirname "$0")") -"${_script_dir}/build-in-docker.sh" "$@" "ty/ubuntu-buildtools:16.04" ubuntu16 +"${_script_dir}/build-in-docker.sh" "$@" "ty/ubuntu-buildtools:22.04" ubuntu22 diff --git a/scripts/build-in-docker-ubuntu18.sh b/scripts/build-in-docker-ubuntu24.sh similarity index 51% rename from scripts/build-in-docker-ubuntu18.sh rename to scripts/build-in-docker-ubuntu24.sh index 551dbd06..2c7aabe2 100755 --- a/scripts/build-in-docker-ubuntu18.sh +++ b/scripts/build-in-docker-ubuntu24.sh @@ -4,4 +4,4 @@ set -eo pipefail _script_dir=$(readlink -f "$(dirname "$0")") -"${_script_dir}/build-in-docker.sh" "$@" "ty/ubuntu-buildtools:18.04" ubuntu18 +"${_script_dir}/build-in-docker.sh" "$@" "ty/ubuntu-buildtools:24.04" ubuntu24 diff --git a/scripts/build-in-docker.sh b/scripts/build-in-docker.sh index 987460dc..4715ee7b 100755 --- a/scripts/build-in-docker.sh +++ b/scripts/build-in-docker.sh @@ -123,6 +123,7 @@ fi "${_arg_docker_image}" \ bash -c " export CMAKE_COLOR_DIAGNOSTICS=ON +export CLICOLOR_FORCE=1 set -evx cd /ty/src cmake -S . -B '${_build_dir}' -G 'Unix Makefiles' \ From a4b6fba5e59b5c0388aa5b3f0c03cfd4a34a13fd Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 17:06:18 -0400 Subject: [PATCH 22/34] A0 Use ninja in build-in-docker.sh --- scripts/build-in-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-in-docker.sh b/scripts/build-in-docker.sh index 4715ee7b..7fa51973 100755 --- a/scripts/build-in-docker.sh +++ b/scripts/build-in-docker.sh @@ -126,7 +126,7 @@ export CMAKE_COLOR_DIAGNOSTICS=ON export CLICOLOR_FORCE=1 set -evx cd /ty/src -cmake -S . -B '${_build_dir}' -G 'Unix Makefiles' \ +cmake -S . -B '${_build_dir}' -G 'Ninja' \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX='${_install_dir}' \ -DVCPKG_INSTALL_OPTIONS='--no-print-usage' \ From 88b38f6c0df6696db9ecebe21abbf308d834375d Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 17:07:06 -0400 Subject: [PATCH 23/34] A0 Set explicit --parallel in build-in-docker Notes: - The default for ninja is _probably_ fine, but the explicit way is probably better? --- scripts/build-in-docker.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/build-in-docker.sh b/scripts/build-in-docker.sh index 7fa51973..301279ff 100755 --- a/scripts/build-in-docker.sh +++ b/scripts/build-in-docker.sh @@ -112,6 +112,8 @@ fi # build project in docker # --- +_cpu_cores=$(grep -c 'processor' /proc/cpuinfo || echo 1) + ( exec 1> >(>&1 sed --unbuffered 's/^/[docker-stdout]: /') # prefix stdout exec 2> >(>&2 sed --unbuffered 's/^/[docker-stderr]: /') # prefix stderr @@ -133,7 +135,7 @@ cmake -S . -B '${_build_dir}' -G 'Ninja' \ -DCMAKE_TOOLCHAIN_FILE=\${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake \ -DVCPKG_INSTALLED_DIR='/opt/vcpkg_installed' \ -DVCPKG_TARGET_TRIPLET='x64-linux' -cmake --build '${_build_dir}' --parallel +cmake --build '${_build_dir}' --parallel ${_cpu_cores:?} cmake --install '${_build_dir}' " ) || { From 0a3ad327a832699833c191a0955eced91e82348c Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 17:47:55 -0400 Subject: [PATCH 24/34] A0 Fix install rule for '*.ty' files --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d51d4a1..580bc879 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -443,10 +443,10 @@ install(TARGETS ${_tgt_ty} ${_tgt_ty_profiler} ${_tgt_ty_ls} DESTINATION ${CMAKE_INSTALL_BINDIR} ) -file(GLOB _ty_modules LIST_DIRECTORIES false ${PROJECT_SOURCE_DIR}/lib/*.ty) -install(FILES ${_ty_modules} +install(DIRECTORY ${PROJECT_SOURCE_DIR}/lib/ COMPONENT InstallComponentTy DESTINATION ${CMAKE_INSTALL_LIBDIR}/ty + FILES_MATCHING PATTERN "*.ty" PERMISSIONS OWNER_READ OWNER_WRITE # 6 GROUP_READ # 4 From c7a065ce4b6200b9c0938ea123310f078c364065 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 17:49:51 -0400 Subject: [PATCH 25/34] A0 Bump cmake minimum to 3.25 Notes: - Allows use of $ --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 580bc879..9ff690b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21) +cmake_minimum_required(VERSION 3.25) project(ty VERSION 0.1 LANGUAGES C) From f7015c4fec43bde15f93f14a46f28760136ddf7b Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 17:51:56 -0400 Subject: [PATCH 26/34] A0 Use LINK_LIBRARY:WHOLE_ARCHIVE genex --- CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ff690b0..c9fd1b6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -356,6 +356,7 @@ target_link_libraries(${_tgt_ty_interface} ${_tgt_libco} ${_tgt_libmd} ${_tgt_dtoa} + $ Threads::Threads # pthreads (or equivalent) mimalloc-static xxHash::xxhash @@ -374,14 +375,8 @@ if(USE_NSYNC) endif() if(APPLE) - target_link_libraries(${_tgt_ty_interface} INTERFACE - -Wl,-force_load,$ - ) target_link_options(${_tgt_ty_interface} INTERFACE -Wl,-export_dynamic) else() - target_link_libraries(${_tgt_ty_interface} INTERFACE - -Wl,--whole-archive unibilium -Wl,--no-whole-archive - ) target_link_options(${_tgt_ty_interface} INTERFACE -rdynamic) endif() From 084cac18aef019ac10358ea6a147372cd8bc5b6f Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 17:53:10 -0400 Subject: [PATCH 27/34] A0 Use 'ENABLE_EXPORTS' instead of '-rdynamic' --- CMakeLists.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9fd1b6a..4ec78630 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -374,12 +374,6 @@ if(USE_NSYNC) target_link_libraries(${_tgt_ty_interface} INTERFACE nsync) endif() -if(APPLE) - target_link_options(${_tgt_ty_interface} INTERFACE -Wl,-export_dynamic) -else() - target_link_options(${_tgt_ty_interface} INTERFACE -rdynamic) -endif() - target_include_directories(${_tgt_ty_interface} INTERFACE ${PROJECT_SOURCE_DIR}/include @@ -428,6 +422,11 @@ if(BUILD_PROFILER) target_link_libraries(${_tgt_ty_profiler} PRIVATE ${_tgt_ty_interface}) endif() +# export symbols (essentially adds the equivalent of: -rdynamic during link) +foreach(_tgt IN ITEMS ${_tgt_ty} ${_tgt_tyls} ${_tgt_typrof}) + set_target_properties(${_tgt} PROPERTIES ENABLE_EXPORTS ON) +endforeach() + # --- # install rules # --- From 66224c639cb1ab1af5bacb2c896aefa8d8fdf579 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 17:56:19 -0400 Subject: [PATCH 28/34] A0 Move vendored libs into 'vendored' subdir Changes: - Moved all vendored libraries into a subdirectory - Added a dedicated CMakeLists.txt for these libs - Added alias cmake targets with 'vendored::' prefix for these targets - Removed unnecessary target_include_directories from ty interface --- CMakeLists.txt | 54 ++++--------------- vendored/CMakeLists.txt | 41 ++++++++++++++ {dtoa => vendored/dtoa}/LICENSE.txt | 0 {dtoa => vendored/dtoa}/SwiftDtoa.c | 0 {dtoa => vendored/dtoa}/SwiftDtoa.h | 0 {dtoa => vendored/dtoa}/dtoa.h | 0 {libco => vendored/libco}/LICENSE | 0 {libco => vendored/libco}/README.md | 0 {libco => vendored/libco}/aarch64.c | 0 {libco => vendored/libco}/amd64.c | 0 {libco => vendored/libco}/arm.c | 0 {libco => vendored/libco}/fiber.c | 0 {libco => vendored/libco}/libco.c | 0 {libco => vendored/libco}/libco.h | 0 {libco => vendored/libco}/ppc.c | 0 {libco => vendored/libco}/ppc64v2.c | 0 {libco => vendored/libco}/settings.h | 0 {libco => vendored/libco}/sjlj.c | 0 {libco => vendored/libco}/ucontext.c | 0 {libco => vendored/libco}/valgrind.h | 0 {libco => vendored/libco}/x86.c | 0 {libmd => vendored/libmd}/CMakeLists.txt | 6 ++- {libmd => vendored/libmd}/COPYING | 0 {libmd => vendored/libmd}/ChangeLog | 0 {libmd => vendored/libmd}/README | 0 {libmd => vendored/libmd}/include/md2.h | 0 {libmd => vendored/libmd}/include/md4.h | 0 {libmd => vendored/libmd}/include/md5.h | 0 {libmd => vendored/libmd}/include/ripemd.h | 0 {libmd => vendored/libmd}/include/rmd160.h | 0 {libmd => vendored/libmd}/include/sha.h | 0 {libmd => vendored/libmd}/include/sha1.h | 0 {libmd => vendored/libmd}/include/sha2.h | 0 {libmd => vendored/libmd}/include/sha256.h | 0 {libmd => vendored/libmd}/include/sha512.h | 0 .../libmd}/m4/libmd-compiler.m4 | 0 {libmd => vendored/libmd}/m4/libmd-linker.m4 | 0 {libmd => vendored/libmd}/src/libmd.map | 0 {libmd => vendored/libmd}/src/local-link.h | 0 {libmd => vendored/libmd}/src/md2.c | 0 {libmd => vendored/libmd}/src/md2hl.c | 0 {libmd => vendored/libmd}/src/md4.c | 0 {libmd => vendored/libmd}/src/md4hl.c | 0 {libmd => vendored/libmd}/src/md5.c | 0 {libmd => vendored/libmd}/src/md5hl.c | 0 {libmd => vendored/libmd}/src/rmd160.c | 0 {libmd => vendored/libmd}/src/rmd160hl.c | 0 {libmd => vendored/libmd}/src/sha1.c | 0 {libmd => vendored/libmd}/src/sha1hl.c | 0 {libmd => vendored/libmd}/src/sha2.c | 0 {libmd => vendored/libmd}/src/sha224hl.c | 0 {libmd => vendored/libmd}/src/sha256hl.c | 0 {libmd => vendored/libmd}/src/sha384hl.c | 0 {libmd => vendored/libmd}/src/sha512_256hl.c | 0 {libmd => vendored/libmd}/src/sha512hl.c | 0 {nsync => vendored/nsync}/CMakeLists.txt | 0 {nsync => vendored/nsync}/LICENSE | 0 {nsync => vendored/nsync}/README | 0 {nsync => vendored/nsync}/VERSION | 0 {nsync => vendored/nsync}/internal/common.c | 0 {nsync => vendored/nsync}/internal/common.h | 0 {nsync => vendored/nsync}/internal/counter.c | 0 {nsync => vendored/nsync}/internal/cv.c | 0 {nsync => vendored/nsync}/internal/debug.c | 0 {nsync => vendored/nsync}/internal/dll.c | 0 {nsync => vendored/nsync}/internal/dll.h | 0 {nsync => vendored/nsync}/internal/headers.h | 0 {nsync => vendored/nsync}/internal/mu.c | 0 {nsync => vendored/nsync}/internal/mu_wait.c | 0 {nsync => vendored/nsync}/internal/note.c | 0 {nsync => vendored/nsync}/internal/once.c | 0 {nsync => vendored/nsync}/internal/sem.h | 0 {nsync => vendored/nsync}/internal/sem_wait.c | 0 .../nsync}/internal/sem_wait_no_note.c | 0 .../nsync}/internal/time_internal.c | 0 {nsync => vendored/nsync}/internal/wait.c | 0 .../nsync}/internal/wait_internal.h | 0 .../nsync}/platform/aarch64/cputype.h | 0 .../platform/aarch64/src/nsync_atm_aarch64.s | 0 .../nsync}/platform/arm/cputype.h | 0 .../nsync}/platform/arm/src/nsync_atm_arm.s | 0 .../nsync}/platform/clang/atomic.h | 0 .../nsync}/platform/clang/compiler.h | 0 .../nsync}/platform/freebsd/platform.h | 0 .../nsync}/platform/gcc/atomic.h | 0 .../nsync}/platform/gcc/compiler.h | 0 .../nsync}/platform/gcc_new/atomic.h | 0 .../nsync}/platform/gcc_old/atomic.h | 0 .../nsync}/platform/linux/platform.h | 0 .../linux/src/nsync_semaphore_futex.c | 0 .../nsync}/platform/macos/atomic.h | 0 .../nsync}/platform/macos/platform.h | 0 .../nsync}/platform/macos/platform_c++11_os.h | 0 .../platform/macos/src/nsync_semaphore_gcd.c | 0 .../nsync}/platform/msvc/compiler.h | 0 .../nsync}/platform/netbsd/atomic.h | 0 .../nsync}/platform/netbsd/platform.h | 0 .../nsync}/platform/openbsd/platform.h | 0 .../nsync}/platform/posix/compiler.h | 0 .../nsync}/platform/posix/cputype.h | 0 .../nsync}/platform/posix/make.common | 0 .../nsync}/platform/posix/nsync_time_init.h | 0 .../nsync}/platform/posix/platform.h | 0 .../nsync}/platform/posix/platform_c++11_os.h | 0 .../nsync}/platform/posix/src/clock_gettime.c | 0 .../nsync}/platform/posix/src/nsync_panic.c | 0 .../posix/src/nsync_semaphore_mutex.c | 0 .../posix/src/nsync_semaphore_sem_t.c | 0 .../platform/posix/src/per_thread_waiter.c | 0 .../nsync}/platform/posix/src/start_thread.c | 0 .../nsync}/platform/posix/src/time_rep.c | 0 .../platform/posix/src/time_rep_debug.c | 0 .../nsync}/platform/posix/src/yield.c | 0 .../nsync}/platform/ppc32/cputype.h | 0 .../nsync}/platform/ppc64/cputype.h | 0 .../platform/ppc64/src/nsync_atm_ppc64.s | 0 .../nsync}/platform/win32/atomic.h | 0 .../nsync}/platform/win32/platform.h | 0 .../nsync}/platform/win32/platform_c++11_os.h | 0 .../nsync}/platform/win32/src/clock_gettime.c | 0 .../platform/win32/src/init_callback_win32.c | 0 .../nsync}/platform/win32/src/nanosleep.c | 0 .../win32/src/nsync_semaphore_win32.c | 0 .../platform/win32/src/per_thread_waiter.c | 0 .../win32/src/pthread_cond_timedwait_win32.c | 0 .../platform/win32/src/pthread_key_win32.cc | 0 .../nsync}/platform/win32/src/start_thread.c | 0 .../nsync}/platform/x86_32/cputype.h | 0 .../platform/x86_32/src/nsync_atm_x86_32.s | 0 .../nsync}/platform/x86_64/cputype.h | 0 .../platform/x86_64/src/nsync_atm_x86_64.s | 0 {nsync => vendored/nsync}/public/nsync.h | 0 .../nsync}/public/nsync_atomic.h | 0 .../nsync}/public/nsync_counter.h | 0 {nsync => vendored/nsync}/public/nsync_cpp.h | 0 {nsync => vendored/nsync}/public/nsync_cv.h | 0 .../nsync}/public/nsync_debug.h | 0 {nsync => vendored/nsync}/public/nsync_mu.h | 0 .../nsync}/public/nsync_mu_wait.h | 0 {nsync => vendored/nsync}/public/nsync_note.h | 0 {nsync => vendored/nsync}/public/nsync_once.h | 0 {nsync => vendored/nsync}/public/nsync_time.h | 0 .../nsync}/public/nsync_time_internal.h | 0 .../nsync}/public/nsync_waiter.h | 0 .../unibilium}/CMakeLists.txt | 0 {unibilium => vendored/unibilium}/GPLv3 | 0 {unibilium => vendored/unibilium}/LGPLv3 | 0 {unibilium => vendored/unibilium}/LICENSE | 0 {unibilium => vendored/unibilium}/README.md | 0 {unibilium => vendored/unibilium}/unibilium.c | 0 {unibilium => vendored/unibilium}/unibilium.h | 0 {unibilium => vendored/unibilium}/uninames.c | 0 {unibilium => vendored/unibilium}/uniutil.c | 0 153 files changed, 56 insertions(+), 45 deletions(-) create mode 100644 vendored/CMakeLists.txt rename {dtoa => vendored/dtoa}/LICENSE.txt (100%) rename {dtoa => vendored/dtoa}/SwiftDtoa.c (100%) rename {dtoa => vendored/dtoa}/SwiftDtoa.h (100%) rename {dtoa => vendored/dtoa}/dtoa.h (100%) rename {libco => vendored/libco}/LICENSE (100%) rename {libco => vendored/libco}/README.md (100%) rename {libco => vendored/libco}/aarch64.c (100%) rename {libco => vendored/libco}/amd64.c (100%) rename {libco => vendored/libco}/arm.c (100%) rename {libco => vendored/libco}/fiber.c (100%) rename {libco => vendored/libco}/libco.c (100%) rename {libco => vendored/libco}/libco.h (100%) rename {libco => vendored/libco}/ppc.c (100%) rename {libco => vendored/libco}/ppc64v2.c (100%) rename {libco => vendored/libco}/settings.h (100%) rename {libco => vendored/libco}/sjlj.c (100%) rename {libco => vendored/libco}/ucontext.c (100%) rename {libco => vendored/libco}/valgrind.h (100%) rename {libco => vendored/libco}/x86.c (100%) rename {libmd => vendored/libmd}/CMakeLists.txt (97%) rename {libmd => vendored/libmd}/COPYING (100%) rename {libmd => vendored/libmd}/ChangeLog (100%) rename {libmd => vendored/libmd}/README (100%) rename {libmd => vendored/libmd}/include/md2.h (100%) rename {libmd => vendored/libmd}/include/md4.h (100%) rename {libmd => vendored/libmd}/include/md5.h (100%) rename {libmd => vendored/libmd}/include/ripemd.h (100%) rename {libmd => vendored/libmd}/include/rmd160.h (100%) rename {libmd => vendored/libmd}/include/sha.h (100%) rename {libmd => vendored/libmd}/include/sha1.h (100%) rename {libmd => vendored/libmd}/include/sha2.h (100%) rename {libmd => vendored/libmd}/include/sha256.h (100%) rename {libmd => vendored/libmd}/include/sha512.h (100%) rename {libmd => vendored/libmd}/m4/libmd-compiler.m4 (100%) rename {libmd => vendored/libmd}/m4/libmd-linker.m4 (100%) rename {libmd => vendored/libmd}/src/libmd.map (100%) rename {libmd => vendored/libmd}/src/local-link.h (100%) rename {libmd => vendored/libmd}/src/md2.c (100%) rename {libmd => vendored/libmd}/src/md2hl.c (100%) rename {libmd => vendored/libmd}/src/md4.c (100%) rename {libmd => vendored/libmd}/src/md4hl.c (100%) rename {libmd => vendored/libmd}/src/md5.c (100%) rename {libmd => vendored/libmd}/src/md5hl.c (100%) rename {libmd => vendored/libmd}/src/rmd160.c (100%) rename {libmd => vendored/libmd}/src/rmd160hl.c (100%) rename {libmd => vendored/libmd}/src/sha1.c (100%) rename {libmd => vendored/libmd}/src/sha1hl.c (100%) rename {libmd => vendored/libmd}/src/sha2.c (100%) rename {libmd => vendored/libmd}/src/sha224hl.c (100%) rename {libmd => vendored/libmd}/src/sha256hl.c (100%) rename {libmd => vendored/libmd}/src/sha384hl.c (100%) rename {libmd => vendored/libmd}/src/sha512_256hl.c (100%) rename {libmd => vendored/libmd}/src/sha512hl.c (100%) rename {nsync => vendored/nsync}/CMakeLists.txt (100%) rename {nsync => vendored/nsync}/LICENSE (100%) rename {nsync => vendored/nsync}/README (100%) rename {nsync => vendored/nsync}/VERSION (100%) rename {nsync => vendored/nsync}/internal/common.c (100%) rename {nsync => vendored/nsync}/internal/common.h (100%) rename {nsync => vendored/nsync}/internal/counter.c (100%) rename {nsync => vendored/nsync}/internal/cv.c (100%) rename {nsync => vendored/nsync}/internal/debug.c (100%) rename {nsync => vendored/nsync}/internal/dll.c (100%) rename {nsync => vendored/nsync}/internal/dll.h (100%) rename {nsync => vendored/nsync}/internal/headers.h (100%) rename {nsync => vendored/nsync}/internal/mu.c (100%) rename {nsync => vendored/nsync}/internal/mu_wait.c (100%) rename {nsync => vendored/nsync}/internal/note.c (100%) rename {nsync => vendored/nsync}/internal/once.c (100%) rename {nsync => vendored/nsync}/internal/sem.h (100%) rename {nsync => vendored/nsync}/internal/sem_wait.c (100%) rename {nsync => vendored/nsync}/internal/sem_wait_no_note.c (100%) rename {nsync => vendored/nsync}/internal/time_internal.c (100%) rename {nsync => vendored/nsync}/internal/wait.c (100%) rename {nsync => vendored/nsync}/internal/wait_internal.h (100%) rename {nsync => vendored/nsync}/platform/aarch64/cputype.h (100%) rename {nsync => vendored/nsync}/platform/aarch64/src/nsync_atm_aarch64.s (100%) rename {nsync => vendored/nsync}/platform/arm/cputype.h (100%) rename {nsync => vendored/nsync}/platform/arm/src/nsync_atm_arm.s (100%) rename {nsync => vendored/nsync}/platform/clang/atomic.h (100%) rename {nsync => vendored/nsync}/platform/clang/compiler.h (100%) rename {nsync => vendored/nsync}/platform/freebsd/platform.h (100%) rename {nsync => vendored/nsync}/platform/gcc/atomic.h (100%) rename {nsync => vendored/nsync}/platform/gcc/compiler.h (100%) rename {nsync => vendored/nsync}/platform/gcc_new/atomic.h (100%) rename {nsync => vendored/nsync}/platform/gcc_old/atomic.h (100%) rename {nsync => vendored/nsync}/platform/linux/platform.h (100%) rename {nsync => vendored/nsync}/platform/linux/src/nsync_semaphore_futex.c (100%) rename {nsync => vendored/nsync}/platform/macos/atomic.h (100%) rename {nsync => vendored/nsync}/platform/macos/platform.h (100%) rename {nsync => vendored/nsync}/platform/macos/platform_c++11_os.h (100%) rename {nsync => vendored/nsync}/platform/macos/src/nsync_semaphore_gcd.c (100%) rename {nsync => vendored/nsync}/platform/msvc/compiler.h (100%) rename {nsync => vendored/nsync}/platform/netbsd/atomic.h (100%) rename {nsync => vendored/nsync}/platform/netbsd/platform.h (100%) rename {nsync => vendored/nsync}/platform/openbsd/platform.h (100%) rename {nsync => vendored/nsync}/platform/posix/compiler.h (100%) rename {nsync => vendored/nsync}/platform/posix/cputype.h (100%) rename {nsync => vendored/nsync}/platform/posix/make.common (100%) rename {nsync => vendored/nsync}/platform/posix/nsync_time_init.h (100%) rename {nsync => vendored/nsync}/platform/posix/platform.h (100%) rename {nsync => vendored/nsync}/platform/posix/platform_c++11_os.h (100%) rename {nsync => vendored/nsync}/platform/posix/src/clock_gettime.c (100%) rename {nsync => vendored/nsync}/platform/posix/src/nsync_panic.c (100%) rename {nsync => vendored/nsync}/platform/posix/src/nsync_semaphore_mutex.c (100%) rename {nsync => vendored/nsync}/platform/posix/src/nsync_semaphore_sem_t.c (100%) rename {nsync => vendored/nsync}/platform/posix/src/per_thread_waiter.c (100%) rename {nsync => vendored/nsync}/platform/posix/src/start_thread.c (100%) rename {nsync => vendored/nsync}/platform/posix/src/time_rep.c (100%) rename {nsync => vendored/nsync}/platform/posix/src/time_rep_debug.c (100%) rename {nsync => vendored/nsync}/platform/posix/src/yield.c (100%) rename {nsync => vendored/nsync}/platform/ppc32/cputype.h (100%) rename {nsync => vendored/nsync}/platform/ppc64/cputype.h (100%) rename {nsync => vendored/nsync}/platform/ppc64/src/nsync_atm_ppc64.s (100%) rename {nsync => vendored/nsync}/platform/win32/atomic.h (100%) rename {nsync => vendored/nsync}/platform/win32/platform.h (100%) rename {nsync => vendored/nsync}/platform/win32/platform_c++11_os.h (100%) rename {nsync => vendored/nsync}/platform/win32/src/clock_gettime.c (100%) rename {nsync => vendored/nsync}/platform/win32/src/init_callback_win32.c (100%) rename {nsync => vendored/nsync}/platform/win32/src/nanosleep.c (100%) rename {nsync => vendored/nsync}/platform/win32/src/nsync_semaphore_win32.c (100%) rename {nsync => vendored/nsync}/platform/win32/src/per_thread_waiter.c (100%) rename {nsync => vendored/nsync}/platform/win32/src/pthread_cond_timedwait_win32.c (100%) rename {nsync => vendored/nsync}/platform/win32/src/pthread_key_win32.cc (100%) rename {nsync => vendored/nsync}/platform/win32/src/start_thread.c (100%) rename {nsync => vendored/nsync}/platform/x86_32/cputype.h (100%) rename {nsync => vendored/nsync}/platform/x86_32/src/nsync_atm_x86_32.s (100%) rename {nsync => vendored/nsync}/platform/x86_64/cputype.h (100%) rename {nsync => vendored/nsync}/platform/x86_64/src/nsync_atm_x86_64.s (100%) rename {nsync => vendored/nsync}/public/nsync.h (100%) rename {nsync => vendored/nsync}/public/nsync_atomic.h (100%) rename {nsync => vendored/nsync}/public/nsync_counter.h (100%) rename {nsync => vendored/nsync}/public/nsync_cpp.h (100%) rename {nsync => vendored/nsync}/public/nsync_cv.h (100%) rename {nsync => vendored/nsync}/public/nsync_debug.h (100%) rename {nsync => vendored/nsync}/public/nsync_mu.h (100%) rename {nsync => vendored/nsync}/public/nsync_mu_wait.h (100%) rename {nsync => vendored/nsync}/public/nsync_note.h (100%) rename {nsync => vendored/nsync}/public/nsync_once.h (100%) rename {nsync => vendored/nsync}/public/nsync_time.h (100%) rename {nsync => vendored/nsync}/public/nsync_time_internal.h (100%) rename {nsync => vendored/nsync}/public/nsync_waiter.h (100%) rename {unibilium => vendored/unibilium}/CMakeLists.txt (100%) rename {unibilium => vendored/unibilium}/GPLv3 (100%) rename {unibilium => vendored/unibilium}/LGPLv3 (100%) rename {unibilium => vendored/unibilium}/LICENSE (100%) rename {unibilium => vendored/unibilium}/README.md (100%) rename {unibilium => vendored/unibilium}/unibilium.c (100%) rename {unibilium => vendored/unibilium}/unibilium.h (100%) rename {unibilium => vendored/unibilium}/uninames.c (100%) rename {unibilium => vendored/unibilium}/uniutil.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ec78630..3c67211b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,12 @@ if(_lto_supported) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) endif() +# --- +# vendored libraries +# --- + +add_subdirectory(vendored) + # --- # generate ioctl constants # --- @@ -180,43 +186,6 @@ else() message(WARNING "gperf not found -- keywords.h will not be regenerated") endif() -# --- -# target: libco -# --- - -set(_tgt_libco libco) -add_library(${_tgt_libco}) -target_sources(${_tgt_libco} PRIVATE libco/libco.c) -target_compile_definitions(${_tgt_libco} PRIVATE LIBCO_MP) - -# --- -# target: dtoa -# --- -set(_tgt_dtoa dtoa) -add_library(${_tgt_dtoa}) -target_sources(${_tgt_dtoa} PRIVATE dtoa/SwiftDtoa.c) - -# --- -# target: libmd::md -# --- - -set(_tgt_libmd libmd::md) -add_subdirectory(libmd) -# libmd uses C_VISIBILITY_PRESET hidden which breaks ThinLTO symbol resolution -set_target_properties(md PROPERTIES INTERPROCEDURAL_OPTIMIZATION FALSE) - -# --- -# target: nsync -# --- -if (USE_NSYNC) - add_subdirectory(nsync) -endif() - -# --- -# target: unibilium -# --- -add_subdirectory(unibilium) - # --- # DynASM JIT code generation # --- @@ -353,10 +322,11 @@ target_link_libraries(${_tgt_ty_interface} ${_tgt_ioctlconstants_h} ${_tgt_errnoconstants_h} ${_tgt_keywords_h} - ${_tgt_libco} - ${_tgt_libmd} - ${_tgt_dtoa} - $ + vendored::libco + vendored::libmd + vendored::dtoa + $<$:vendored::nsync> + $ Threads::Threads # pthreads (or equivalent) mimalloc-static xxHash::xxhash @@ -377,8 +347,6 @@ endif() target_include_directories(${_tgt_ty_interface} INTERFACE ${PROJECT_SOURCE_DIR}/include - ${PROJECT_SOURCE_DIR}/libco - ${PROJECT_SOURCE_DIR}/dtoa ${PROJECT_SOURCE_DIR}/src ) diff --git a/vendored/CMakeLists.txt b/vendored/CMakeLists.txt new file mode 100644 index 00000000..e0bde71d --- /dev/null +++ b/vendored/CMakeLists.txt @@ -0,0 +1,41 @@ +# --- +# target: nsync +# --- + +if (USE_NSYNC) + add_subdirectory(nsync) + add_library(vendored::nsync ALIAS nsync) +endif() + +# --- +# target: unibilium +# --- + +add_subdirectory(unibilium) +add_library(vendored::unibilium ALIAS unibilium) + +# --- +# target: md +# --- + +add_subdirectory(libmd) +add_library(vendored::libmd ALIAS md) + +# --- +# target: libco +# --- + +add_library(libco) +add_library(vendored::libco ALIAS libco) +target_sources(libco PRIVATE libco/libco.c) +target_include_directories(libco PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/libco) +target_compile_definitions(libco PRIVATE LIBCO_MP) + +# --- +# target: dtoa +# --- + +add_library(dtoa) +add_library(vendored::dtoa ALIAS dtoa) +target_include_directories(dtoa PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/dtoa) +target_sources(dtoa PRIVATE dtoa/SwiftDtoa.c) diff --git a/dtoa/LICENSE.txt b/vendored/dtoa/LICENSE.txt similarity index 100% rename from dtoa/LICENSE.txt rename to vendored/dtoa/LICENSE.txt diff --git a/dtoa/SwiftDtoa.c b/vendored/dtoa/SwiftDtoa.c similarity index 100% rename from dtoa/SwiftDtoa.c rename to vendored/dtoa/SwiftDtoa.c diff --git a/dtoa/SwiftDtoa.h b/vendored/dtoa/SwiftDtoa.h similarity index 100% rename from dtoa/SwiftDtoa.h rename to vendored/dtoa/SwiftDtoa.h diff --git a/dtoa/dtoa.h b/vendored/dtoa/dtoa.h similarity index 100% rename from dtoa/dtoa.h rename to vendored/dtoa/dtoa.h diff --git a/libco/LICENSE b/vendored/libco/LICENSE similarity index 100% rename from libco/LICENSE rename to vendored/libco/LICENSE diff --git a/libco/README.md b/vendored/libco/README.md similarity index 100% rename from libco/README.md rename to vendored/libco/README.md diff --git a/libco/aarch64.c b/vendored/libco/aarch64.c similarity index 100% rename from libco/aarch64.c rename to vendored/libco/aarch64.c diff --git a/libco/amd64.c b/vendored/libco/amd64.c similarity index 100% rename from libco/amd64.c rename to vendored/libco/amd64.c diff --git a/libco/arm.c b/vendored/libco/arm.c similarity index 100% rename from libco/arm.c rename to vendored/libco/arm.c diff --git a/libco/fiber.c b/vendored/libco/fiber.c similarity index 100% rename from libco/fiber.c rename to vendored/libco/fiber.c diff --git a/libco/libco.c b/vendored/libco/libco.c similarity index 100% rename from libco/libco.c rename to vendored/libco/libco.c diff --git a/libco/libco.h b/vendored/libco/libco.h similarity index 100% rename from libco/libco.h rename to vendored/libco/libco.h diff --git a/libco/ppc.c b/vendored/libco/ppc.c similarity index 100% rename from libco/ppc.c rename to vendored/libco/ppc.c diff --git a/libco/ppc64v2.c b/vendored/libco/ppc64v2.c similarity index 100% rename from libco/ppc64v2.c rename to vendored/libco/ppc64v2.c diff --git a/libco/settings.h b/vendored/libco/settings.h similarity index 100% rename from libco/settings.h rename to vendored/libco/settings.h diff --git a/libco/sjlj.c b/vendored/libco/sjlj.c similarity index 100% rename from libco/sjlj.c rename to vendored/libco/sjlj.c diff --git a/libco/ucontext.c b/vendored/libco/ucontext.c similarity index 100% rename from libco/ucontext.c rename to vendored/libco/ucontext.c diff --git a/libco/valgrind.h b/vendored/libco/valgrind.h similarity index 100% rename from libco/valgrind.h rename to vendored/libco/valgrind.h diff --git a/libco/x86.c b/vendored/libco/x86.c similarity index 100% rename from libco/x86.c rename to vendored/libco/x86.c diff --git a/libmd/CMakeLists.txt b/vendored/libmd/CMakeLists.txt similarity index 97% rename from libmd/CMakeLists.txt rename to vendored/libmd/CMakeLists.txt index dd7d67bb..1618937d 100644 --- a/libmd/CMakeLists.txt +++ b/vendored/libmd/CMakeLists.txt @@ -51,8 +51,10 @@ add_library(libmd::md ALIAS md) set_target_properties(md PROPERTIES VERSION ${LIBMD_ABI} SOVERSION ${LIBMD_ABI_MAJOR} - C_VISIBILITY_PRESET hidden OUTPUT_NAME md + # C_VISIBILITY_PRESET hidden breaks ThinLTO symbol resolution + C_VISIBILITY_PRESET hidden + INTERPROCEDURAL_OPTIMIZATION FALSE ) target_include_directories(md @@ -95,7 +97,7 @@ if(NOT CMAKE_C_FLAGS) -Wstrict-prototypes -Wwrite-strings ) - + foreach(flag ${warning_flags}) string(REGEX REPLACE "[-=]" "_" flag_var ${flag}) check_c_compiler_flag(${flag} HAVE${flag_var}) diff --git a/libmd/COPYING b/vendored/libmd/COPYING similarity index 100% rename from libmd/COPYING rename to vendored/libmd/COPYING diff --git a/libmd/ChangeLog b/vendored/libmd/ChangeLog similarity index 100% rename from libmd/ChangeLog rename to vendored/libmd/ChangeLog diff --git a/libmd/README b/vendored/libmd/README similarity index 100% rename from libmd/README rename to vendored/libmd/README diff --git a/libmd/include/md2.h b/vendored/libmd/include/md2.h similarity index 100% rename from libmd/include/md2.h rename to vendored/libmd/include/md2.h diff --git a/libmd/include/md4.h b/vendored/libmd/include/md4.h similarity index 100% rename from libmd/include/md4.h rename to vendored/libmd/include/md4.h diff --git a/libmd/include/md5.h b/vendored/libmd/include/md5.h similarity index 100% rename from libmd/include/md5.h rename to vendored/libmd/include/md5.h diff --git a/libmd/include/ripemd.h b/vendored/libmd/include/ripemd.h similarity index 100% rename from libmd/include/ripemd.h rename to vendored/libmd/include/ripemd.h diff --git a/libmd/include/rmd160.h b/vendored/libmd/include/rmd160.h similarity index 100% rename from libmd/include/rmd160.h rename to vendored/libmd/include/rmd160.h diff --git a/libmd/include/sha.h b/vendored/libmd/include/sha.h similarity index 100% rename from libmd/include/sha.h rename to vendored/libmd/include/sha.h diff --git a/libmd/include/sha1.h b/vendored/libmd/include/sha1.h similarity index 100% rename from libmd/include/sha1.h rename to vendored/libmd/include/sha1.h diff --git a/libmd/include/sha2.h b/vendored/libmd/include/sha2.h similarity index 100% rename from libmd/include/sha2.h rename to vendored/libmd/include/sha2.h diff --git a/libmd/include/sha256.h b/vendored/libmd/include/sha256.h similarity index 100% rename from libmd/include/sha256.h rename to vendored/libmd/include/sha256.h diff --git a/libmd/include/sha512.h b/vendored/libmd/include/sha512.h similarity index 100% rename from libmd/include/sha512.h rename to vendored/libmd/include/sha512.h diff --git a/libmd/m4/libmd-compiler.m4 b/vendored/libmd/m4/libmd-compiler.m4 similarity index 100% rename from libmd/m4/libmd-compiler.m4 rename to vendored/libmd/m4/libmd-compiler.m4 diff --git a/libmd/m4/libmd-linker.m4 b/vendored/libmd/m4/libmd-linker.m4 similarity index 100% rename from libmd/m4/libmd-linker.m4 rename to vendored/libmd/m4/libmd-linker.m4 diff --git a/libmd/src/libmd.map b/vendored/libmd/src/libmd.map similarity index 100% rename from libmd/src/libmd.map rename to vendored/libmd/src/libmd.map diff --git a/libmd/src/local-link.h b/vendored/libmd/src/local-link.h similarity index 100% rename from libmd/src/local-link.h rename to vendored/libmd/src/local-link.h diff --git a/libmd/src/md2.c b/vendored/libmd/src/md2.c similarity index 100% rename from libmd/src/md2.c rename to vendored/libmd/src/md2.c diff --git a/libmd/src/md2hl.c b/vendored/libmd/src/md2hl.c similarity index 100% rename from libmd/src/md2hl.c rename to vendored/libmd/src/md2hl.c diff --git a/libmd/src/md4.c b/vendored/libmd/src/md4.c similarity index 100% rename from libmd/src/md4.c rename to vendored/libmd/src/md4.c diff --git a/libmd/src/md4hl.c b/vendored/libmd/src/md4hl.c similarity index 100% rename from libmd/src/md4hl.c rename to vendored/libmd/src/md4hl.c diff --git a/libmd/src/md5.c b/vendored/libmd/src/md5.c similarity index 100% rename from libmd/src/md5.c rename to vendored/libmd/src/md5.c diff --git a/libmd/src/md5hl.c b/vendored/libmd/src/md5hl.c similarity index 100% rename from libmd/src/md5hl.c rename to vendored/libmd/src/md5hl.c diff --git a/libmd/src/rmd160.c b/vendored/libmd/src/rmd160.c similarity index 100% rename from libmd/src/rmd160.c rename to vendored/libmd/src/rmd160.c diff --git a/libmd/src/rmd160hl.c b/vendored/libmd/src/rmd160hl.c similarity index 100% rename from libmd/src/rmd160hl.c rename to vendored/libmd/src/rmd160hl.c diff --git a/libmd/src/sha1.c b/vendored/libmd/src/sha1.c similarity index 100% rename from libmd/src/sha1.c rename to vendored/libmd/src/sha1.c diff --git a/libmd/src/sha1hl.c b/vendored/libmd/src/sha1hl.c similarity index 100% rename from libmd/src/sha1hl.c rename to vendored/libmd/src/sha1hl.c diff --git a/libmd/src/sha2.c b/vendored/libmd/src/sha2.c similarity index 100% rename from libmd/src/sha2.c rename to vendored/libmd/src/sha2.c diff --git a/libmd/src/sha224hl.c b/vendored/libmd/src/sha224hl.c similarity index 100% rename from libmd/src/sha224hl.c rename to vendored/libmd/src/sha224hl.c diff --git a/libmd/src/sha256hl.c b/vendored/libmd/src/sha256hl.c similarity index 100% rename from libmd/src/sha256hl.c rename to vendored/libmd/src/sha256hl.c diff --git a/libmd/src/sha384hl.c b/vendored/libmd/src/sha384hl.c similarity index 100% rename from libmd/src/sha384hl.c rename to vendored/libmd/src/sha384hl.c diff --git a/libmd/src/sha512_256hl.c b/vendored/libmd/src/sha512_256hl.c similarity index 100% rename from libmd/src/sha512_256hl.c rename to vendored/libmd/src/sha512_256hl.c diff --git a/libmd/src/sha512hl.c b/vendored/libmd/src/sha512hl.c similarity index 100% rename from libmd/src/sha512hl.c rename to vendored/libmd/src/sha512hl.c diff --git a/nsync/CMakeLists.txt b/vendored/nsync/CMakeLists.txt similarity index 100% rename from nsync/CMakeLists.txt rename to vendored/nsync/CMakeLists.txt diff --git a/nsync/LICENSE b/vendored/nsync/LICENSE similarity index 100% rename from nsync/LICENSE rename to vendored/nsync/LICENSE diff --git a/nsync/README b/vendored/nsync/README similarity index 100% rename from nsync/README rename to vendored/nsync/README diff --git a/nsync/VERSION b/vendored/nsync/VERSION similarity index 100% rename from nsync/VERSION rename to vendored/nsync/VERSION diff --git a/nsync/internal/common.c b/vendored/nsync/internal/common.c similarity index 100% rename from nsync/internal/common.c rename to vendored/nsync/internal/common.c diff --git a/nsync/internal/common.h b/vendored/nsync/internal/common.h similarity index 100% rename from nsync/internal/common.h rename to vendored/nsync/internal/common.h diff --git a/nsync/internal/counter.c b/vendored/nsync/internal/counter.c similarity index 100% rename from nsync/internal/counter.c rename to vendored/nsync/internal/counter.c diff --git a/nsync/internal/cv.c b/vendored/nsync/internal/cv.c similarity index 100% rename from nsync/internal/cv.c rename to vendored/nsync/internal/cv.c diff --git a/nsync/internal/debug.c b/vendored/nsync/internal/debug.c similarity index 100% rename from nsync/internal/debug.c rename to vendored/nsync/internal/debug.c diff --git a/nsync/internal/dll.c b/vendored/nsync/internal/dll.c similarity index 100% rename from nsync/internal/dll.c rename to vendored/nsync/internal/dll.c diff --git a/nsync/internal/dll.h b/vendored/nsync/internal/dll.h similarity index 100% rename from nsync/internal/dll.h rename to vendored/nsync/internal/dll.h diff --git a/nsync/internal/headers.h b/vendored/nsync/internal/headers.h similarity index 100% rename from nsync/internal/headers.h rename to vendored/nsync/internal/headers.h diff --git a/nsync/internal/mu.c b/vendored/nsync/internal/mu.c similarity index 100% rename from nsync/internal/mu.c rename to vendored/nsync/internal/mu.c diff --git a/nsync/internal/mu_wait.c b/vendored/nsync/internal/mu_wait.c similarity index 100% rename from nsync/internal/mu_wait.c rename to vendored/nsync/internal/mu_wait.c diff --git a/nsync/internal/note.c b/vendored/nsync/internal/note.c similarity index 100% rename from nsync/internal/note.c rename to vendored/nsync/internal/note.c diff --git a/nsync/internal/once.c b/vendored/nsync/internal/once.c similarity index 100% rename from nsync/internal/once.c rename to vendored/nsync/internal/once.c diff --git a/nsync/internal/sem.h b/vendored/nsync/internal/sem.h similarity index 100% rename from nsync/internal/sem.h rename to vendored/nsync/internal/sem.h diff --git a/nsync/internal/sem_wait.c b/vendored/nsync/internal/sem_wait.c similarity index 100% rename from nsync/internal/sem_wait.c rename to vendored/nsync/internal/sem_wait.c diff --git a/nsync/internal/sem_wait_no_note.c b/vendored/nsync/internal/sem_wait_no_note.c similarity index 100% rename from nsync/internal/sem_wait_no_note.c rename to vendored/nsync/internal/sem_wait_no_note.c diff --git a/nsync/internal/time_internal.c b/vendored/nsync/internal/time_internal.c similarity index 100% rename from nsync/internal/time_internal.c rename to vendored/nsync/internal/time_internal.c diff --git a/nsync/internal/wait.c b/vendored/nsync/internal/wait.c similarity index 100% rename from nsync/internal/wait.c rename to vendored/nsync/internal/wait.c diff --git a/nsync/internal/wait_internal.h b/vendored/nsync/internal/wait_internal.h similarity index 100% rename from nsync/internal/wait_internal.h rename to vendored/nsync/internal/wait_internal.h diff --git a/nsync/platform/aarch64/cputype.h b/vendored/nsync/platform/aarch64/cputype.h similarity index 100% rename from nsync/platform/aarch64/cputype.h rename to vendored/nsync/platform/aarch64/cputype.h diff --git a/nsync/platform/aarch64/src/nsync_atm_aarch64.s b/vendored/nsync/platform/aarch64/src/nsync_atm_aarch64.s similarity index 100% rename from nsync/platform/aarch64/src/nsync_atm_aarch64.s rename to vendored/nsync/platform/aarch64/src/nsync_atm_aarch64.s diff --git a/nsync/platform/arm/cputype.h b/vendored/nsync/platform/arm/cputype.h similarity index 100% rename from nsync/platform/arm/cputype.h rename to vendored/nsync/platform/arm/cputype.h diff --git a/nsync/platform/arm/src/nsync_atm_arm.s b/vendored/nsync/platform/arm/src/nsync_atm_arm.s similarity index 100% rename from nsync/platform/arm/src/nsync_atm_arm.s rename to vendored/nsync/platform/arm/src/nsync_atm_arm.s diff --git a/nsync/platform/clang/atomic.h b/vendored/nsync/platform/clang/atomic.h similarity index 100% rename from nsync/platform/clang/atomic.h rename to vendored/nsync/platform/clang/atomic.h diff --git a/nsync/platform/clang/compiler.h b/vendored/nsync/platform/clang/compiler.h similarity index 100% rename from nsync/platform/clang/compiler.h rename to vendored/nsync/platform/clang/compiler.h diff --git a/nsync/platform/freebsd/platform.h b/vendored/nsync/platform/freebsd/platform.h similarity index 100% rename from nsync/platform/freebsd/platform.h rename to vendored/nsync/platform/freebsd/platform.h diff --git a/nsync/platform/gcc/atomic.h b/vendored/nsync/platform/gcc/atomic.h similarity index 100% rename from nsync/platform/gcc/atomic.h rename to vendored/nsync/platform/gcc/atomic.h diff --git a/nsync/platform/gcc/compiler.h b/vendored/nsync/platform/gcc/compiler.h similarity index 100% rename from nsync/platform/gcc/compiler.h rename to vendored/nsync/platform/gcc/compiler.h diff --git a/nsync/platform/gcc_new/atomic.h b/vendored/nsync/platform/gcc_new/atomic.h similarity index 100% rename from nsync/platform/gcc_new/atomic.h rename to vendored/nsync/platform/gcc_new/atomic.h diff --git a/nsync/platform/gcc_old/atomic.h b/vendored/nsync/platform/gcc_old/atomic.h similarity index 100% rename from nsync/platform/gcc_old/atomic.h rename to vendored/nsync/platform/gcc_old/atomic.h diff --git a/nsync/platform/linux/platform.h b/vendored/nsync/platform/linux/platform.h similarity index 100% rename from nsync/platform/linux/platform.h rename to vendored/nsync/platform/linux/platform.h diff --git a/nsync/platform/linux/src/nsync_semaphore_futex.c b/vendored/nsync/platform/linux/src/nsync_semaphore_futex.c similarity index 100% rename from nsync/platform/linux/src/nsync_semaphore_futex.c rename to vendored/nsync/platform/linux/src/nsync_semaphore_futex.c diff --git a/nsync/platform/macos/atomic.h b/vendored/nsync/platform/macos/atomic.h similarity index 100% rename from nsync/platform/macos/atomic.h rename to vendored/nsync/platform/macos/atomic.h diff --git a/nsync/platform/macos/platform.h b/vendored/nsync/platform/macos/platform.h similarity index 100% rename from nsync/platform/macos/platform.h rename to vendored/nsync/platform/macos/platform.h diff --git a/nsync/platform/macos/platform_c++11_os.h b/vendored/nsync/platform/macos/platform_c++11_os.h similarity index 100% rename from nsync/platform/macos/platform_c++11_os.h rename to vendored/nsync/platform/macos/platform_c++11_os.h diff --git a/nsync/platform/macos/src/nsync_semaphore_gcd.c b/vendored/nsync/platform/macos/src/nsync_semaphore_gcd.c similarity index 100% rename from nsync/platform/macos/src/nsync_semaphore_gcd.c rename to vendored/nsync/platform/macos/src/nsync_semaphore_gcd.c diff --git a/nsync/platform/msvc/compiler.h b/vendored/nsync/platform/msvc/compiler.h similarity index 100% rename from nsync/platform/msvc/compiler.h rename to vendored/nsync/platform/msvc/compiler.h diff --git a/nsync/platform/netbsd/atomic.h b/vendored/nsync/platform/netbsd/atomic.h similarity index 100% rename from nsync/platform/netbsd/atomic.h rename to vendored/nsync/platform/netbsd/atomic.h diff --git a/nsync/platform/netbsd/platform.h b/vendored/nsync/platform/netbsd/platform.h similarity index 100% rename from nsync/platform/netbsd/platform.h rename to vendored/nsync/platform/netbsd/platform.h diff --git a/nsync/platform/openbsd/platform.h b/vendored/nsync/platform/openbsd/platform.h similarity index 100% rename from nsync/platform/openbsd/platform.h rename to vendored/nsync/platform/openbsd/platform.h diff --git a/nsync/platform/posix/compiler.h b/vendored/nsync/platform/posix/compiler.h similarity index 100% rename from nsync/platform/posix/compiler.h rename to vendored/nsync/platform/posix/compiler.h diff --git a/nsync/platform/posix/cputype.h b/vendored/nsync/platform/posix/cputype.h similarity index 100% rename from nsync/platform/posix/cputype.h rename to vendored/nsync/platform/posix/cputype.h diff --git a/nsync/platform/posix/make.common b/vendored/nsync/platform/posix/make.common similarity index 100% rename from nsync/platform/posix/make.common rename to vendored/nsync/platform/posix/make.common diff --git a/nsync/platform/posix/nsync_time_init.h b/vendored/nsync/platform/posix/nsync_time_init.h similarity index 100% rename from nsync/platform/posix/nsync_time_init.h rename to vendored/nsync/platform/posix/nsync_time_init.h diff --git a/nsync/platform/posix/platform.h b/vendored/nsync/platform/posix/platform.h similarity index 100% rename from nsync/platform/posix/platform.h rename to vendored/nsync/platform/posix/platform.h diff --git a/nsync/platform/posix/platform_c++11_os.h b/vendored/nsync/platform/posix/platform_c++11_os.h similarity index 100% rename from nsync/platform/posix/platform_c++11_os.h rename to vendored/nsync/platform/posix/platform_c++11_os.h diff --git a/nsync/platform/posix/src/clock_gettime.c b/vendored/nsync/platform/posix/src/clock_gettime.c similarity index 100% rename from nsync/platform/posix/src/clock_gettime.c rename to vendored/nsync/platform/posix/src/clock_gettime.c diff --git a/nsync/platform/posix/src/nsync_panic.c b/vendored/nsync/platform/posix/src/nsync_panic.c similarity index 100% rename from nsync/platform/posix/src/nsync_panic.c rename to vendored/nsync/platform/posix/src/nsync_panic.c diff --git a/nsync/platform/posix/src/nsync_semaphore_mutex.c b/vendored/nsync/platform/posix/src/nsync_semaphore_mutex.c similarity index 100% rename from nsync/platform/posix/src/nsync_semaphore_mutex.c rename to vendored/nsync/platform/posix/src/nsync_semaphore_mutex.c diff --git a/nsync/platform/posix/src/nsync_semaphore_sem_t.c b/vendored/nsync/platform/posix/src/nsync_semaphore_sem_t.c similarity index 100% rename from nsync/platform/posix/src/nsync_semaphore_sem_t.c rename to vendored/nsync/platform/posix/src/nsync_semaphore_sem_t.c diff --git a/nsync/platform/posix/src/per_thread_waiter.c b/vendored/nsync/platform/posix/src/per_thread_waiter.c similarity index 100% rename from nsync/platform/posix/src/per_thread_waiter.c rename to vendored/nsync/platform/posix/src/per_thread_waiter.c diff --git a/nsync/platform/posix/src/start_thread.c b/vendored/nsync/platform/posix/src/start_thread.c similarity index 100% rename from nsync/platform/posix/src/start_thread.c rename to vendored/nsync/platform/posix/src/start_thread.c diff --git a/nsync/platform/posix/src/time_rep.c b/vendored/nsync/platform/posix/src/time_rep.c similarity index 100% rename from nsync/platform/posix/src/time_rep.c rename to vendored/nsync/platform/posix/src/time_rep.c diff --git a/nsync/platform/posix/src/time_rep_debug.c b/vendored/nsync/platform/posix/src/time_rep_debug.c similarity index 100% rename from nsync/platform/posix/src/time_rep_debug.c rename to vendored/nsync/platform/posix/src/time_rep_debug.c diff --git a/nsync/platform/posix/src/yield.c b/vendored/nsync/platform/posix/src/yield.c similarity index 100% rename from nsync/platform/posix/src/yield.c rename to vendored/nsync/platform/posix/src/yield.c diff --git a/nsync/platform/ppc32/cputype.h b/vendored/nsync/platform/ppc32/cputype.h similarity index 100% rename from nsync/platform/ppc32/cputype.h rename to vendored/nsync/platform/ppc32/cputype.h diff --git a/nsync/platform/ppc64/cputype.h b/vendored/nsync/platform/ppc64/cputype.h similarity index 100% rename from nsync/platform/ppc64/cputype.h rename to vendored/nsync/platform/ppc64/cputype.h diff --git a/nsync/platform/ppc64/src/nsync_atm_ppc64.s b/vendored/nsync/platform/ppc64/src/nsync_atm_ppc64.s similarity index 100% rename from nsync/platform/ppc64/src/nsync_atm_ppc64.s rename to vendored/nsync/platform/ppc64/src/nsync_atm_ppc64.s diff --git a/nsync/platform/win32/atomic.h b/vendored/nsync/platform/win32/atomic.h similarity index 100% rename from nsync/platform/win32/atomic.h rename to vendored/nsync/platform/win32/atomic.h diff --git a/nsync/platform/win32/platform.h b/vendored/nsync/platform/win32/platform.h similarity index 100% rename from nsync/platform/win32/platform.h rename to vendored/nsync/platform/win32/platform.h diff --git a/nsync/platform/win32/platform_c++11_os.h b/vendored/nsync/platform/win32/platform_c++11_os.h similarity index 100% rename from nsync/platform/win32/platform_c++11_os.h rename to vendored/nsync/platform/win32/platform_c++11_os.h diff --git a/nsync/platform/win32/src/clock_gettime.c b/vendored/nsync/platform/win32/src/clock_gettime.c similarity index 100% rename from nsync/platform/win32/src/clock_gettime.c rename to vendored/nsync/platform/win32/src/clock_gettime.c diff --git a/nsync/platform/win32/src/init_callback_win32.c b/vendored/nsync/platform/win32/src/init_callback_win32.c similarity index 100% rename from nsync/platform/win32/src/init_callback_win32.c rename to vendored/nsync/platform/win32/src/init_callback_win32.c diff --git a/nsync/platform/win32/src/nanosleep.c b/vendored/nsync/platform/win32/src/nanosleep.c similarity index 100% rename from nsync/platform/win32/src/nanosleep.c rename to vendored/nsync/platform/win32/src/nanosleep.c diff --git a/nsync/platform/win32/src/nsync_semaphore_win32.c b/vendored/nsync/platform/win32/src/nsync_semaphore_win32.c similarity index 100% rename from nsync/platform/win32/src/nsync_semaphore_win32.c rename to vendored/nsync/platform/win32/src/nsync_semaphore_win32.c diff --git a/nsync/platform/win32/src/per_thread_waiter.c b/vendored/nsync/platform/win32/src/per_thread_waiter.c similarity index 100% rename from nsync/platform/win32/src/per_thread_waiter.c rename to vendored/nsync/platform/win32/src/per_thread_waiter.c diff --git a/nsync/platform/win32/src/pthread_cond_timedwait_win32.c b/vendored/nsync/platform/win32/src/pthread_cond_timedwait_win32.c similarity index 100% rename from nsync/platform/win32/src/pthread_cond_timedwait_win32.c rename to vendored/nsync/platform/win32/src/pthread_cond_timedwait_win32.c diff --git a/nsync/platform/win32/src/pthread_key_win32.cc b/vendored/nsync/platform/win32/src/pthread_key_win32.cc similarity index 100% rename from nsync/platform/win32/src/pthread_key_win32.cc rename to vendored/nsync/platform/win32/src/pthread_key_win32.cc diff --git a/nsync/platform/win32/src/start_thread.c b/vendored/nsync/platform/win32/src/start_thread.c similarity index 100% rename from nsync/platform/win32/src/start_thread.c rename to vendored/nsync/platform/win32/src/start_thread.c diff --git a/nsync/platform/x86_32/cputype.h b/vendored/nsync/platform/x86_32/cputype.h similarity index 100% rename from nsync/platform/x86_32/cputype.h rename to vendored/nsync/platform/x86_32/cputype.h diff --git a/nsync/platform/x86_32/src/nsync_atm_x86_32.s b/vendored/nsync/platform/x86_32/src/nsync_atm_x86_32.s similarity index 100% rename from nsync/platform/x86_32/src/nsync_atm_x86_32.s rename to vendored/nsync/platform/x86_32/src/nsync_atm_x86_32.s diff --git a/nsync/platform/x86_64/cputype.h b/vendored/nsync/platform/x86_64/cputype.h similarity index 100% rename from nsync/platform/x86_64/cputype.h rename to vendored/nsync/platform/x86_64/cputype.h diff --git a/nsync/platform/x86_64/src/nsync_atm_x86_64.s b/vendored/nsync/platform/x86_64/src/nsync_atm_x86_64.s similarity index 100% rename from nsync/platform/x86_64/src/nsync_atm_x86_64.s rename to vendored/nsync/platform/x86_64/src/nsync_atm_x86_64.s diff --git a/nsync/public/nsync.h b/vendored/nsync/public/nsync.h similarity index 100% rename from nsync/public/nsync.h rename to vendored/nsync/public/nsync.h diff --git a/nsync/public/nsync_atomic.h b/vendored/nsync/public/nsync_atomic.h similarity index 100% rename from nsync/public/nsync_atomic.h rename to vendored/nsync/public/nsync_atomic.h diff --git a/nsync/public/nsync_counter.h b/vendored/nsync/public/nsync_counter.h similarity index 100% rename from nsync/public/nsync_counter.h rename to vendored/nsync/public/nsync_counter.h diff --git a/nsync/public/nsync_cpp.h b/vendored/nsync/public/nsync_cpp.h similarity index 100% rename from nsync/public/nsync_cpp.h rename to vendored/nsync/public/nsync_cpp.h diff --git a/nsync/public/nsync_cv.h b/vendored/nsync/public/nsync_cv.h similarity index 100% rename from nsync/public/nsync_cv.h rename to vendored/nsync/public/nsync_cv.h diff --git a/nsync/public/nsync_debug.h b/vendored/nsync/public/nsync_debug.h similarity index 100% rename from nsync/public/nsync_debug.h rename to vendored/nsync/public/nsync_debug.h diff --git a/nsync/public/nsync_mu.h b/vendored/nsync/public/nsync_mu.h similarity index 100% rename from nsync/public/nsync_mu.h rename to vendored/nsync/public/nsync_mu.h diff --git a/nsync/public/nsync_mu_wait.h b/vendored/nsync/public/nsync_mu_wait.h similarity index 100% rename from nsync/public/nsync_mu_wait.h rename to vendored/nsync/public/nsync_mu_wait.h diff --git a/nsync/public/nsync_note.h b/vendored/nsync/public/nsync_note.h similarity index 100% rename from nsync/public/nsync_note.h rename to vendored/nsync/public/nsync_note.h diff --git a/nsync/public/nsync_once.h b/vendored/nsync/public/nsync_once.h similarity index 100% rename from nsync/public/nsync_once.h rename to vendored/nsync/public/nsync_once.h diff --git a/nsync/public/nsync_time.h b/vendored/nsync/public/nsync_time.h similarity index 100% rename from nsync/public/nsync_time.h rename to vendored/nsync/public/nsync_time.h diff --git a/nsync/public/nsync_time_internal.h b/vendored/nsync/public/nsync_time_internal.h similarity index 100% rename from nsync/public/nsync_time_internal.h rename to vendored/nsync/public/nsync_time_internal.h diff --git a/nsync/public/nsync_waiter.h b/vendored/nsync/public/nsync_waiter.h similarity index 100% rename from nsync/public/nsync_waiter.h rename to vendored/nsync/public/nsync_waiter.h diff --git a/unibilium/CMakeLists.txt b/vendored/unibilium/CMakeLists.txt similarity index 100% rename from unibilium/CMakeLists.txt rename to vendored/unibilium/CMakeLists.txt diff --git a/unibilium/GPLv3 b/vendored/unibilium/GPLv3 similarity index 100% rename from unibilium/GPLv3 rename to vendored/unibilium/GPLv3 diff --git a/unibilium/LGPLv3 b/vendored/unibilium/LGPLv3 similarity index 100% rename from unibilium/LGPLv3 rename to vendored/unibilium/LGPLv3 diff --git a/unibilium/LICENSE b/vendored/unibilium/LICENSE similarity index 100% rename from unibilium/LICENSE rename to vendored/unibilium/LICENSE diff --git a/unibilium/README.md b/vendored/unibilium/README.md similarity index 100% rename from unibilium/README.md rename to vendored/unibilium/README.md diff --git a/unibilium/unibilium.c b/vendored/unibilium/unibilium.c similarity index 100% rename from unibilium/unibilium.c rename to vendored/unibilium/unibilium.c diff --git a/unibilium/unibilium.h b/vendored/unibilium/unibilium.h similarity index 100% rename from unibilium/unibilium.h rename to vendored/unibilium/unibilium.h diff --git a/unibilium/uninames.c b/vendored/unibilium/uninames.c similarity index 100% rename from unibilium/uninames.c rename to vendored/unibilium/uninames.c diff --git a/unibilium/uniutil.c b/vendored/unibilium/uniutil.c similarity index 100% rename from unibilium/uniutil.c rename to vendored/unibilium/uniutil.c From 1cc71ab5d52eee79752b9ba098c9815969765620 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 19:13:29 -0400 Subject: [PATCH 29/34] A0 Fix Makefile w/ 'vendored' subdir --- Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 5522f693..ee8b00e5 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ CFLAGS += -std=c2x CFLAGS += -Wall CFLAGS += -Iinclude -CFLAGS += -Ilibco -CFLAGS += -Idtoa -CFLAGS += -Ilibmd/include +CFLAGS += -Ivendored/libco +CFLAGS += -Ivendored/dtoa +CFLAGS += -Ivendored/libmd/include CFLAGS += -isystem/usr/local/include CFLAGS += $(shell pkg-config --cflags libffi) CFLAGS += $(shell pcre2-config --cflags) @@ -117,7 +117,7 @@ endif ifndef NO_NSYNC CFLAGS += -DTY_USE_NSYNC - CFLAGS += -Insync/public + CFLAGS += -Ivendored/nsync/public endif # --- Default to ncpu parallel jobs --- @@ -154,9 +154,9 @@ SOURCES := $(wildcard src/*.c) OBJECTS := $(patsubst src/%.c,obj/%.o,$(SOURCES)) TYLS_OBJECTS := $(patsubst src/%.c,obj/tyls/%.o,$(SOURCES)) TYPROF_OBJECTS := $(patsubst src/%.c,obj/typrof/%.o,$(SOURCES)) -EXTERNAL := libco/libco.o dtoa/dtoa.o libmd/libmd.a +EXTERNAL := vendored/libco/libco.o vendored/dtoa/dtoa.o vendored/libmd/libmd.a ifndef NO_NSYNC - EXTERNAL += nsync/out/libnsync.a + EXTERNAL += vendored/nsync/out/libnsync.a endif ASSEMBLY := $(patsubst %.c,%.s,$(SOURCES)) @@ -196,10 +196,10 @@ asm: $(ASSEMBLY) @echo cc $< $(CC) $(CFLAGS) -S -o asm/$@ -DFILENAME=$(patsubst %.c,%,$<) $< -libco/libco.o: libco/libco.c +vendored/libco/libco.o: vendored/libco/libco.c $(CC) $(CFLAGS) -c -o $@ -DLIBCO_MP $< -dtoa/dtoa.o: dtoa/SwiftDtoa.c +vendored/dtoa/dtoa.o: vendored/dtoa/SwiftDtoa.c $(CC) $(CFLAGS) -c -o $@ $< obj/%.o: src/%.c @@ -216,7 +216,7 @@ obj/typrof/%.o: src/%.c clean: - rm -rf $(PROG) *.gcda $(OBJECTS) $(TYLS_OBJECTS) $(TYPROF_OBJECTS) libco/libco.o dtoa/dtoa.o include/keywords.h $(BUILD_SIG_FILE) + rm -rf $(PROG) *.gcda $(OBJECTS) $(TYLS_OBJECTS) $(TYPROF_OBJECTS) vendored/libco/libco.o vendored/dtoa/dtoa.o include/keywords.h $(BUILD_SIG_FILE) test: ./ty test.ty From 7c1cdae8a89a42ad0baf9d762f46ed8796ae21a7 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 19:15:55 -0400 Subject: [PATCH 30/34] A0 Add LuaJIT to .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index dc73159e..3b390088 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ _* # ides .vscode .vs +# Makefile garbage +obj/ # vcpkg vcpkg_installed vcpkg @@ -10,6 +12,8 @@ vcpkg *.err # autogenerated file(s) include/keywords.h +src/jit_x64.h +LuaJIT # agents .agents/* .claude/* From 455cd92227120c19f362edb172d5976356d4f19e Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 19:18:19 -0400 Subject: [PATCH 31/34] A0 Add note about 'LuaJIT' to CLAUDE.md --- CLAUDE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index d6d2911f..b63772e0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -57,6 +57,8 @@ make clean - `gperf` generates [include/keywords.h](include/keywords.h) from [src/keywords.gperf](src/keywords.gperf) - `luajit` + DynASM generates `src/jit_x64.h` or `src/jit_arm64.h` from `.dasc` files +- `LuaJIT` project must be cloned from `https://github.com/LuaJIT/LuaJIT` into the + project root at `/LuaJIT` so that the build can find `LuaJIT/dynasm/dynasm.lua` ## Running Tests From eec3153b77aada3a297e5bc2ebf2ed201f901b50 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 20:17:06 -0400 Subject: [PATCH 32/34] A0 Add 'luajit' to vcpkg.json Notes: - This tells vcpkg to compile it so we can reference the just-compiled version instead of relying on the user to already have a system-installed copy of luajit. --- CMakeLists.txt | 38 ++++++++++++++++++-------------------- vcpkg.json | 3 ++- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c67211b..71216432 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,29 +190,27 @@ endif() # DynASM JIT code generation # --- -find_program(LUAJIT_EXECUTABLE luajit) -if(LUAJIT_EXECUTABLE) - if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") - set(_jit_dasc ${PROJECT_SOURCE_DIR}/src/jit_arm64.dasc) - set(_jit_hdr ${PROJECT_SOURCE_DIR}/src/jit_arm64.h) - else() - set(_jit_dasc ${PROJECT_SOURCE_DIR}/src/jit_x64.dasc) - set(_jit_hdr ${PROJECT_SOURCE_DIR}/src/jit_x64.h) - endif() - - add_custom_command( - OUTPUT ${_jit_hdr} - COMMAND ${LUAJIT_EXECUTABLE} ${PROJECT_SOURCE_DIR}/LuaJIT/dynasm/dynasm.lua - -o ${_jit_hdr} ${_jit_dasc} - DEPENDS ${_jit_dasc} - COMMENT "Generating JIT emission header from ${_jit_dasc}" - VERBATIM - ) - add_custom_target(GenerateJitHeader DEPENDS ${_jit_hdr}) +find_program(LUAJIT_EXECUTABLE luajit REQUIRED + HINTS "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools/luajit" +) +if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") + set(_jit_dasc ${PROJECT_SOURCE_DIR}/src/jit_arm64.dasc) + set(_jit_hdr ${PROJECT_SOURCE_DIR}/src/jit_arm64.h) else() - message(WARNING "luajit not found -- JIT headers will not be regenerated") + set(_jit_dasc ${PROJECT_SOURCE_DIR}/src/jit_x64.dasc) + set(_jit_hdr ${PROJECT_SOURCE_DIR}/src/jit_x64.h) endif() +add_custom_command( + OUTPUT ${_jit_hdr} + COMMAND ${LUAJIT_EXECUTABLE} ${PROJECT_SOURCE_DIR}/LuaJIT/dynasm/dynasm.lua + -o ${_jit_hdr} ${_jit_dasc} + DEPENDS ${_jit_dasc} + COMMENT "Generating JIT emission header from ${_jit_dasc}" + VERBATIM +) +add_custom_target(GenerateJitHeader DEPENDS ${_jit_hdr}) + # --- # target: ty # --- diff --git a/vcpkg.json b/vcpkg.json index 4d084333..2f3479a7 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -10,6 +10,7 @@ ] }, "xxhash", - "mimalloc" + "mimalloc", + "luajit" ] } From 46d182c5a2125adea56488fc3d45ba3ea0547657 Mon Sep 17 00:00:00 2001 From: Stephen Karavos Date: Sat, 7 Mar 2026 20:19:06 -0400 Subject: [PATCH 33/34] A0 Add 'nsync' to vcpkg.json, remove vendored copy --- CMakeLists.txt | 5 +- vcpkg.json | 3 +- vendored/CMakeLists.txt | 9 - vendored/nsync/CMakeLists.txt | 181 ------ vendored/nsync/LICENSE | 202 ------- vendored/nsync/README | 248 -------- vendored/nsync/VERSION | 1 - vendored/nsync/internal/common.c | 256 -------- vendored/nsync/internal/common.h | 299 ---------- vendored/nsync/internal/counter.c | 150 ----- vendored/nsync/internal/cv.c | 495 ---------------- vendored/nsync/internal/debug.c | 293 ---------- vendored/nsync/internal/dll.c | 142 ----- vendored/nsync/internal/dll.h | 77 --- vendored/nsync/internal/headers.h | 26 - vendored/nsync/internal/mu.c | 553 ------------------ vendored/nsync/internal/mu_wait.c | 323 ---------- vendored/nsync/internal/note.c | 302 ---------- vendored/nsync/internal/once.c | 147 ----- vendored/nsync/internal/sem.h | 45 -- vendored/nsync/internal/sem_wait.c | 81 --- vendored/nsync/internal/sem_wait_no_note.c | 36 -- vendored/nsync/internal/time_internal.c | 33 -- vendored/nsync/internal/wait.c | 103 ---- vendored/nsync/internal/wait_internal.h | 36 -- vendored/nsync/platform/aarch64/cputype.h | 20 - .../platform/aarch64/src/nsync_atm_aarch64.s | 119 ---- vendored/nsync/platform/arm/cputype.h | 20 - .../nsync/platform/arm/src/nsync_atm_arm.s | 138 ----- vendored/nsync/platform/clang/atomic.h | 18 - vendored/nsync/platform/clang/compiler.h | 23 - vendored/nsync/platform/freebsd/platform.h | 32 - vendored/nsync/platform/gcc/atomic.h | 72 --- vendored/nsync/platform/gcc/compiler.h | 23 - vendored/nsync/platform/gcc_new/atomic.h | 102 ---- vendored/nsync/platform/gcc_old/atomic.h | 113 ---- vendored/nsync/platform/linux/platform.h | 38 -- .../linux/src/nsync_semaphore_futex.c | 141 ----- vendored/nsync/platform/macos/atomic.h | 109 ---- vendored/nsync/platform/macos/platform.h | 42 -- .../nsync/platform/macos/platform_c++11_os.h | 32 - .../platform/macos/src/nsync_semaphore_gcd.c | 60 -- vendored/nsync/platform/msvc/compiler.h | 23 - vendored/nsync/platform/netbsd/atomic.h | 117 ---- vendored/nsync/platform/netbsd/platform.h | 37 -- vendored/nsync/platform/openbsd/platform.h | 36 -- vendored/nsync/platform/posix/compiler.h | 23 - vendored/nsync/platform/posix/cputype.h | 20 - vendored/nsync/platform/posix/make.common | 116 ---- .../nsync/platform/posix/nsync_time_init.h | 20 - vendored/nsync/platform/posix/platform.h | 33 -- .../nsync/platform/posix/platform_c++11_os.h | 13 - .../nsync/platform/posix/src/clock_gettime.c | 29 - .../nsync/platform/posix/src/nsync_panic.c | 41 -- .../posix/src/nsync_semaphore_mutex.c | 92 --- .../posix/src/nsync_semaphore_sem_t.c | 68 --- .../platform/posix/src/per_thread_waiter.c | 48 -- .../nsync/platform/posix/src/start_thread.c | 40 -- vendored/nsync/platform/posix/src/time_rep.c | 95 --- .../nsync/platform/posix/src/time_rep_debug.c | 91 --- vendored/nsync/platform/posix/src/yield.c | 23 - vendored/nsync/platform/ppc32/cputype.h | 20 - vendored/nsync/platform/ppc64/cputype.h | 20 - .../platform/ppc64/src/nsync_atm_ppc64.s | 134 ----- vendored/nsync/platform/win32/atomic.h | 122 ---- vendored/nsync/platform/win32/platform.h | 108 ---- .../nsync/platform/win32/platform_c++11_os.h | 61 -- .../nsync/platform/win32/src/clock_gettime.c | 27 - .../platform/win32/src/init_callback_win32.c | 26 - vendored/nsync/platform/win32/src/nanosleep.c | 32 - .../win32/src/nsync_semaphore_win32.c | 79 --- .../platform/win32/src/per_thread_waiter.c | 48 -- .../win32/src/pthread_cond_timedwait_win32.c | 64 -- .../platform/win32/src/pthread_key_win32.cc | 147 ----- .../nsync/platform/win32/src/start_thread.c | 40 -- vendored/nsync/platform/x86_32/cputype.h | 20 - .../platform/x86_32/src/nsync_atm_x86_32.s | 69 --- vendored/nsync/platform/x86_64/cputype.h | 20 - .../platform/x86_64/src/nsync_atm_x86_64.s | 61 -- vendored/nsync/public/nsync.h | 27 - vendored/nsync/public/nsync_atomic.h | 64 -- vendored/nsync/public/nsync_counter.h | 62 -- vendored/nsync/public/nsync_cpp.h | 45 -- vendored/nsync/public/nsync_cv.h | 148 ----- vendored/nsync/public/nsync_debug.h | 54 -- vendored/nsync/public/nsync_mu.h | 113 ---- vendored/nsync/public/nsync_mu_wait.h | 128 ---- vendored/nsync/public/nsync_note.h | 67 --- vendored/nsync/public/nsync_once.h | 49 -- vendored/nsync/public/nsync_time.h | 61 -- vendored/nsync/public/nsync_time_internal.h | 184 ------ vendored/nsync/public/nsync_waiter.h | 155 ----- 92 files changed, 6 insertions(+), 8362 deletions(-) delete mode 100644 vendored/nsync/CMakeLists.txt delete mode 100644 vendored/nsync/LICENSE delete mode 100644 vendored/nsync/README delete mode 100644 vendored/nsync/VERSION delete mode 100644 vendored/nsync/internal/common.c delete mode 100644 vendored/nsync/internal/common.h delete mode 100644 vendored/nsync/internal/counter.c delete mode 100644 vendored/nsync/internal/cv.c delete mode 100644 vendored/nsync/internal/debug.c delete mode 100644 vendored/nsync/internal/dll.c delete mode 100644 vendored/nsync/internal/dll.h delete mode 100644 vendored/nsync/internal/headers.h delete mode 100644 vendored/nsync/internal/mu.c delete mode 100644 vendored/nsync/internal/mu_wait.c delete mode 100644 vendored/nsync/internal/note.c delete mode 100644 vendored/nsync/internal/once.c delete mode 100644 vendored/nsync/internal/sem.h delete mode 100644 vendored/nsync/internal/sem_wait.c delete mode 100644 vendored/nsync/internal/sem_wait_no_note.c delete mode 100644 vendored/nsync/internal/time_internal.c delete mode 100644 vendored/nsync/internal/wait.c delete mode 100644 vendored/nsync/internal/wait_internal.h delete mode 100644 vendored/nsync/platform/aarch64/cputype.h delete mode 100644 vendored/nsync/platform/aarch64/src/nsync_atm_aarch64.s delete mode 100644 vendored/nsync/platform/arm/cputype.h delete mode 100644 vendored/nsync/platform/arm/src/nsync_atm_arm.s delete mode 100644 vendored/nsync/platform/clang/atomic.h delete mode 100644 vendored/nsync/platform/clang/compiler.h delete mode 100644 vendored/nsync/platform/freebsd/platform.h delete mode 100644 vendored/nsync/platform/gcc/atomic.h delete mode 100644 vendored/nsync/platform/gcc/compiler.h delete mode 100644 vendored/nsync/platform/gcc_new/atomic.h delete mode 100644 vendored/nsync/platform/gcc_old/atomic.h delete mode 100644 vendored/nsync/platform/linux/platform.h delete mode 100644 vendored/nsync/platform/linux/src/nsync_semaphore_futex.c delete mode 100644 vendored/nsync/platform/macos/atomic.h delete mode 100644 vendored/nsync/platform/macos/platform.h delete mode 100644 vendored/nsync/platform/macos/platform_c++11_os.h delete mode 100644 vendored/nsync/platform/macos/src/nsync_semaphore_gcd.c delete mode 100644 vendored/nsync/platform/msvc/compiler.h delete mode 100644 vendored/nsync/platform/netbsd/atomic.h delete mode 100644 vendored/nsync/platform/netbsd/platform.h delete mode 100644 vendored/nsync/platform/openbsd/platform.h delete mode 100644 vendored/nsync/platform/posix/compiler.h delete mode 100644 vendored/nsync/platform/posix/cputype.h delete mode 100644 vendored/nsync/platform/posix/make.common delete mode 100644 vendored/nsync/platform/posix/nsync_time_init.h delete mode 100644 vendored/nsync/platform/posix/platform.h delete mode 100644 vendored/nsync/platform/posix/platform_c++11_os.h delete mode 100644 vendored/nsync/platform/posix/src/clock_gettime.c delete mode 100644 vendored/nsync/platform/posix/src/nsync_panic.c delete mode 100644 vendored/nsync/platform/posix/src/nsync_semaphore_mutex.c delete mode 100644 vendored/nsync/platform/posix/src/nsync_semaphore_sem_t.c delete mode 100644 vendored/nsync/platform/posix/src/per_thread_waiter.c delete mode 100644 vendored/nsync/platform/posix/src/start_thread.c delete mode 100644 vendored/nsync/platform/posix/src/time_rep.c delete mode 100644 vendored/nsync/platform/posix/src/time_rep_debug.c delete mode 100644 vendored/nsync/platform/posix/src/yield.c delete mode 100644 vendored/nsync/platform/ppc32/cputype.h delete mode 100644 vendored/nsync/platform/ppc64/cputype.h delete mode 100644 vendored/nsync/platform/ppc64/src/nsync_atm_ppc64.s delete mode 100644 vendored/nsync/platform/win32/atomic.h delete mode 100644 vendored/nsync/platform/win32/platform.h delete mode 100644 vendored/nsync/platform/win32/platform_c++11_os.h delete mode 100644 vendored/nsync/platform/win32/src/clock_gettime.c delete mode 100644 vendored/nsync/platform/win32/src/init_callback_win32.c delete mode 100644 vendored/nsync/platform/win32/src/nanosleep.c delete mode 100644 vendored/nsync/platform/win32/src/nsync_semaphore_win32.c delete mode 100644 vendored/nsync/platform/win32/src/per_thread_waiter.c delete mode 100644 vendored/nsync/platform/win32/src/pthread_cond_timedwait_win32.c delete mode 100644 vendored/nsync/platform/win32/src/pthread_key_win32.cc delete mode 100644 vendored/nsync/platform/win32/src/start_thread.c delete mode 100644 vendored/nsync/platform/x86_32/cputype.h delete mode 100644 vendored/nsync/platform/x86_32/src/nsync_atm_x86_32.s delete mode 100644 vendored/nsync/platform/x86_64/cputype.h delete mode 100644 vendored/nsync/platform/x86_64/src/nsync_atm_x86_64.s delete mode 100644 vendored/nsync/public/nsync.h delete mode 100644 vendored/nsync/public/nsync_atomic.h delete mode 100644 vendored/nsync/public/nsync_counter.h delete mode 100644 vendored/nsync/public/nsync_cpp.h delete mode 100644 vendored/nsync/public/nsync_cv.h delete mode 100644 vendored/nsync/public/nsync_debug.h delete mode 100644 vendored/nsync/public/nsync_mu.h delete mode 100644 vendored/nsync/public/nsync_mu_wait.h delete mode 100644 vendored/nsync/public/nsync_note.h delete mode 100644 vendored/nsync/public/nsync_once.h delete mode 100644 vendored/nsync/public/nsync_time.h delete mode 100644 vendored/nsync/public/nsync_time_internal.h delete mode 100644 vendored/nsync/public/nsync_waiter.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 71216432..77f97e10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,9 @@ find_package(utf8proc CONFIG REQUIRED) find_package(pcre2 CONFIG REQUIRED) # defines target(s): xxHash::xxhash find_package(xxHash CONFIG REQUIRED) +# defines target(s): nsync +find_package(nsync CONFIG REQUIRED) +add_library(nsync::nsync ALIAS nsync) #<-- sadly nsync doesnt do this for us # defines target(s): mimalloc, mimalloc-static find_package(mimalloc CONFIG REQUIRED) set_target_properties(mimalloc-static PROPERTIES @@ -323,8 +326,8 @@ target_link_libraries(${_tgt_ty_interface} vendored::libco vendored::libmd vendored::dtoa - $<$:vendored::nsync> $ + $<$:nsync::nsync> Threads::Threads # pthreads (or equivalent) mimalloc-static xxHash::xxhash diff --git a/vcpkg.json b/vcpkg.json index 2f3479a7..cf0dab53 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -11,6 +11,7 @@ }, "xxhash", "mimalloc", - "luajit" + "luajit", + "nsync" ] } diff --git a/vendored/CMakeLists.txt b/vendored/CMakeLists.txt index e0bde71d..563adcbf 100644 --- a/vendored/CMakeLists.txt +++ b/vendored/CMakeLists.txt @@ -1,12 +1,3 @@ -# --- -# target: nsync -# --- - -if (USE_NSYNC) - add_subdirectory(nsync) - add_library(vendored::nsync ALIAS nsync) -endif() - # --- # target: unibilium # --- diff --git a/vendored/nsync/CMakeLists.txt b/vendored/nsync/CMakeLists.txt deleted file mode 100644 index 3635828e..00000000 --- a/vendored/nsync/CMakeLists.txt +++ /dev/null @@ -1,181 +0,0 @@ -cmake_minimum_required (VERSION 2.8.12...4.0) - -if ("${CMAKE_MAJOR_VERSION}X" STREQUAL "2X") - project (nsync) -else () - file (STRINGS VERSION VERSION_STRING) - cmake_policy(SET CMP0048 NEW) - project (nsync VERSION "${VERSION_STRING}") -endif () - -set (CMAKE_POSITION_INDEPENDENT_CODE ON) - -# ----------------------------------------------------------------- -# Functions to set common options on targets. -function (set_c_target tgtname files) - if ("${CMAKE_SYSTEM_NAME}X" STREQUAL "LinuxX") - target_include_directories ("${tgtname}" BEFORE PRIVATE - "${PROJECT_SOURCE_DIR}/platform/linux" - ) - endif () -endfunction (set_c_target) - -# ----------------------------------------------------------------- -# Platform dependencies - -set (NSYNC_POSIX_SRC - "platform/posix/src/nsync_panic.c" - "platform/posix/src/per_thread_waiter.c" - "platform/posix/src/time_rep.c" - "platform/posix/src/yield.c" -) - -if ("${CMAKE_C_COMPILER_ID}X" STREQUAL "MSVCX") - add_compile_options (/wd4057 /wd4100 /wd4152 /wd4242 /wd4244 /wd4255 /wd4267) - add_compile_options (/wd4365 /wd4389 /wd4458 /wd4571 /wd4625 /wd4626 /wd4668) - add_compile_options (/wd4702 /wd4710 /wd4774 /wd4820 /wd5026 /wd5027 /wd5039) - add_compile_options (/wd5045) -endif () - -# Pick the include directory for the operating system. -if ("${CMAKE_SYSTEM_NAME}X" STREQUAL "WindowsX") - include_directories ("${PROJECT_SOURCE_DIR}/platform/win32") - - set (NSYNC_OS_SRC - ${NSYNC_POSIX_SRC} - "platform/win32/src/clock_gettime.c" - "platform/win32/src/init_callback_win32.c" - "platform/win32/src/nanosleep.c" - "platform/win32/src/nsync_semaphore_win32.c" - "platform/win32/src/pthread_cond_timedwait_win32.c" - "platform/win32/src/pthread_key_win32.cc" - ) -elseif ("${CMAKE_SYSTEM_NAME}X" STREQUAL "DarwinX") - include_directories ("${PROJECT_SOURCE_DIR}/platform/macos") - set (NSYNC_POSIX ON) - - set (NSYNC_OS_EXTRA_SRC - "platform/posix/src/clock_gettime.c" - "platform/posix/src/nsync_semaphore_mutex.c" - ) -elseif ("${CMAKE_SYSTEM_NAME}X" STREQUAL "LinuxX") - set (NSYNC_POSIX ON) - - set (NSYNC_OS_EXTRA_SRC - "platform/linux/src/nsync_semaphore_futex.c" - ) -elseif ("${CMAKE_SYSTEM_NAME}X" STREQUAL "NetBSDX") - include_directories ("${PROJECT_SOURCE_DIR}/platform/netbsd") - set (NSYNC_POSIX ON) - - set (NSYNC_OS_EXTRA_SRC - "platform/posix/src/nsync_semaphore_mutex.c" - ) -elseif ("${CMAKE_SYSTEM_NAME}X" STREQUAL "FreeBSDX") - include_directories ("${PROJECT_SOURCE_DIR}/platform/freebsd") - set (NSYNC_POSIX ON) - - set (NSYNC_OS_EXTRA_SRC - "platform/posix/src/nsync_semaphore_mutex.c" - ) -elseif ("${CMAKE_SYSTEM_NAME}X" STREQUAL "OpenBSDX") - include_directories ("${PROJECT_SOURCE_DIR}/platform/openbsd") - set (NSYNC_POSIX ON) - - set (NSYNC_OS_EXTRA_SRC - "platform/posix/src/nsync_semaphore_mutex.c" - ) -else () - set (NSYNC_POSIX ON) - - set (NSYNC_OS_EXTRA_SRC - "platform/posix/src/nsync_semaphore_mutex.c" - ) -endif () - -# Pick the include directory for the compiler. -if ("${CMAKE_C_COMPILER_ID}X" STREQUAL "GNUX") - include_directories ("${PROJECT_SOURCE_DIR}/platform/gcc") - set (THREADS_HAVE_PTHREAD_ARG ON) -elseif ("${CMAKE_C_COMPILER_ID}X" STREQUAL "ClangX") - include_directories ("${PROJECT_SOURCE_DIR}/platform/clang") - set (THREADS_HAVE_PTHREAD_ARG ON) -elseif ("${CMAKE_C_COMPILER_ID}X" STREQUAL "MSVCX") - include_directories ("${PROJECT_SOURCE_DIR}/platform/msvc") -endif () - -if (NSYNC_POSIX) - include_directories ("${PROJECT_SOURCE_DIR}/platform/posix") - - set (NSYNC_OS_SRC - ${NSYNC_POSIX_SRC} - ${NSYNC_OS_EXTRA_SRC} - ) -endif () - -# Pick the include directory for the architecture. -if (("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "x86_64X") OR - ("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "amd64X") OR - ("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "AMD64X")) - include_directories ("${PROJECT_SOURCE_DIR}/platform/x86_64") -elseif (("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "x86_32X") OR - ("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "i386X") OR - ("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "i686X")) - include_directories ("${PROJECT_SOURCE_DIR}/platform/x86_32") -elseif (("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "armv6lX") OR - ("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "armv7lX") OR - ("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "armX")) - include_directories ("${PROJECT_SOURCE_DIR}/platform/arm") -elseif (("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "aarch64X") OR - ("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "arm64X")) - include_directories ("${PROJECT_SOURCE_DIR}/platform/aarch64") -elseif (("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "ppcX") OR - ("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "ppc32X")) - include_directories ("${PROJECT_SOURCE_DIR}/platform/ppc32") -elseif (("${CMAKE_SYSTEM_PROCESSOR}X" STREQUAL "ppc64X")) - include_directories ("${PROJECT_SOURCE_DIR}/platform/ppc64") -endif () - -# Windows uses some include files from the posix directory also. -if ("${CMAKE_SYSTEM_NAME}X" STREQUAL "WindowsX") - include_directories ("${PROJECT_SOURCE_DIR}/platform/posix") -endif () - -# ----------------------------------------------------------------- - -include_directories ("${PROJECT_SOURCE_DIR}/public") -include_directories ("${PROJECT_SOURCE_DIR}/internal") - -set (NSYNC_COMMON_SRC - "internal/common.c" - "internal/counter.c" - "internal/cv.c" - "internal/debug.c" - "internal/dll.c" - "internal/mu.c" - "internal/mu_wait.c" - "internal/note.c" - "internal/once.c" - "internal/sem_wait.c" - "internal/time_internal.c" - "internal/wait.c" -) - -add_library (nsync ${NSYNC_COMMON_SRC} ${NSYNC_OS_SRC}) -set_target_properties (nsync PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR}) -target_include_directories (nsync PUBLIC - $ - $) - -set_c_target (nsync "${NSYNC_COMMON_SRC} ${NSYNC_OS_SRC}") - -find_package (Threads REQUIRED) -set (THREADS_PREFER_PTHREAD_FLAG ON) -if (THREADS_HAVE_PTHREAD_ARG) - target_compile_options (nsync PUBLIC "-pthread") -endif () -if (CMAKE_THREAD_LIBS_INIT) - target_link_libraries (nsync "${CMAKE_THREAD_LIBS_INIT}") -endif () diff --git a/vendored/nsync/LICENSE b/vendored/nsync/LICENSE deleted file mode 100644 index d6456956..00000000 --- a/vendored/nsync/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendored/nsync/README b/vendored/nsync/README deleted file mode 100644 index 70c6b9fb..00000000 --- a/vendored/nsync/README +++ /dev/null @@ -1,248 +0,0 @@ -nsync is a C library that exports various synchronization primitives: - locks - condition variables - run-once initialization - waitable counter (useful for barriers) - waitable bit (useful for cancellation, or other conditions) - -It is not an offical Google product. - -nsync may be desirable in place of pthread primitives in some cases: -- nsync locks are reader-writer locks (but are as efficient as mutexes). -- nsync locks and condition variables occupy only two words each. -- nsync works on Unix-like systems and Windows. It should be portable to - other platforms straightforwardly. -- nsync provides conditional critical sections. These fill the same role - as condition variables, but are usually easier to use, and in most common - cases are comparable in speed. They can be easier to use in two ways: - - it's not necessary to surround the "wait" operation in a while loop; - instead the condition is passed to the call as a function and arbitrary - pointer argument. - - it's not necessary to wake or signal explicitly when the condition(s) - become true; they are checked automatically. - The primary downsides are: - - they are not available in most other common synchronization APIs, and so - they may be unfamiliar (even though they date back to the 1960s), and - - if threads routinely wait on many distinct, false conditions - associated with the same lock, they may be slower than condition variables. - In this case, clients can use condition variables in the normal way; - conditional critical sections and condition variables can be used with - the same lock. -- nsync waits can be cancelled via an object passed to the wait calls, unlike - the pthread model in which threads are cancelled. This difference can be - useful if the computation needs multiple threads, or if cancellation affects - only sub-operations within a larger operation by the thread. -See the section "Extensions to locks and condition variables" below. - -Portability -=========== -The library is intended to be portable, and to be compilable on a system with -only a C90 compiler, assuming atomic operations are available from the -compiler, operating system, or assembler routines. It is able to use C11 or -C++11 atomic operations if they are available. -It can be compiled with a C++ compiler, and in its own C++ name space, if -desired, though no attempt has been made to present a class-based interface. - -Building -======== -The builds/ directory may already contain a subdirectory that -matches your platform. For example, if you're on an x86_64, -running Linux, using gcc, you might pick "x86_64.linux.gcc". - -If there is an appropriate subdirectory, in that subdirectory type: - make depend test -which will calculate dependencies, build the library and its tests, and then -run them. (On Windows, using Visual Studio ("x86_64.win32.msvc") -use "nmake" instead of "make".) - -If there is no suitable subdirectory, on most Unix-like systems you can create -one with - tools/mkmakefile.sh - -The main reason it might fail is if it cannot find a suitable implementation of -atomic operations on the platform. Atomic operations may be provided by -- compiler-dependent interfaces (currently, gcc and clang) - These are auto detected by mkmakefile.sh. -- language-specific standards (currently, C11 and C++11) - Selected in mkmakefile.sh via "-atomic c11" or "-atomic c++11". -- operating system-dependent libraries (e.g., NetBSD, MacOS, Windows) - Selected in mkmakefile.sh via "-atomic os". -- architecture-dependent libraries (e.g., x86_64, x86_32, aarch64, - arm, mips, alpha) - Selected in mkmakefile.sh via "-atomic asm"; file should be - named platforms//src/nsync_atm_.[csS] - to be found by mkmakefile.sh. -If none of these match your platform, you may need to provide -an assembly language implementation. - -Other possible issues: -- Some platforms put clock_gettime() in the realtime library. - Give "-lrt" to mkmakefile.sh. -- The version identifier of "clang" can vary by installation, - and so it may not be identified if invoked as "cc". - Give "-cc clang" to mkmakefile.sh, if clang is not detected automatically. -- Some CPU architectures have many variants, making it - difficult to rely on a single identifier. - Give "-arch " to mkmakefile.sh to specify - a particular string. - -mkmakefile.sh recognises a couple of special cases: -- MacOS doesn't provide clock_gettime(); a compatibility routine - is found in platform/posix/src/clock_gettime.c - See builds/x86_64.macos.clang/Makefile -- OpenBSD and Irix do not provide thread-local storage, which is accommodated - by adding -I../../platform/gcc_no_tls to the include path. - See, for example, builds/x86_64.openbsd.gcc/Makefile. - -Further customization is possible by editing the Makefile, directly. -For Unix-like systems is typically only a few lines long. -For example, compare - builds/x86_64.linux.g++/Makefile -with - builds/x86_64.linux.gcc/Makefile -to see how to compile the entire library in C++, rather than C. - -CMake ------ - -CMake can also be used to build: - - $ mkdir out - $ cd out/ - $ cmake .. - $ make - $ make install - -The C library will be called libnsync and C++ is libnsync_cpp. - -Tests can be disabled with the CMake option: -DNSYNC_ENABLE_TESTS=0. -To build shared libraries instead of static use: -DBUILD_SHARED_LIBS=ON. - -CMake version >= 3.0 is strongly recommended. - -Code structure -============== -public/ Public header files for library. -builds/*/ Platform-dependent build directories, each with Makefile. -internal/ Platform-independent library source code, and Makefile fragment. -platform/*/ Platform-dependent source code. -testing/ Platform-independent testing source code is in "testing". -tools/ Optional tools that can be used to create Makefile - dependencies and run tests. - -Where possible, the code avoids conditional compilation (#if, etc.), -to avoid becoming a mess of C-preprocessor directives. -The platform-dependent Makefiles set the appropriate include -paths and specify platform-dependent modules where needed. - -The build directories of the various platforms are kept separate to allow -multiple platforms to be accommodated in one shared file system. - -Differences from pthread locks and condition variables -====================================================== - -Conditional critical sections ------------------------------ -Consider the following use of a condition variable: - /* variable declarations */ - nsync_mu mu = NSYNC_MU_INIT; /* protects i */ - int i = 1; - nsync_cv cv = NSYNC_CV_INIT; /* signalled when i reaches 0 */ - - ... - - /* Waiter */ - nsync_mu_lock (&mu); - while (i != 0) { - nsync_cv_wait (&cv, &mu); - } - /* i is zero ... */ - nsync_mu_unlock (&mu); - - ... - - /* Decrementer */ - nsync_mu_lock (&mu) - i--; - if (i == 0) { - nsync_cv_broadcast (&cv); - } - nsync_mu_unlock (&mu); - -With conditional critical sections, the equivalent is: - /* variable declarations */ - nsync_mu mu = NSYNC_MU_INIT; /* protects i */ - int i = 1; - - /* Condition */ - int int_is_zero (void *v) { - return (*(int *)v == 0); - } - - ... - - /* Waiter */ - nsync_mu_lock (&mu); - nsync_mu_wait (&mu, &int_is_zero, &i) - /* i is zero ... */ - nsync_mu_unlock (&mu); - - ... - - /* Decrementer */ - nsync_mu_lock (&mu) - i--; - nsync_mu_unlock (&mu); - -For the cost of writing a function that evaluates the desired -condition, the waiter's while-loop, and the decrementer's -signalling are handled by the implementation. - -In most cases, this makes code easier to write and debug. - -The primary cost is that the implementation must check whether any waiters' -conditions have become true when releasing the lock. This cost becomes most -noticable when threads wait on many distinct, false conditions. In such cases, -some or all of the conditions can be converted to use condition variables and -explicit signalling. - -C++ users may be tempted to wrap this functionality in a way that uses -lambda expressions for the conditions. This will work, but may be less -efficient, because C++ does not provide a means to detect whether two lambda -expressions evaluate the same function. This may force the implementation to -evaluate the same false condition many more times than it otherwise might. - -Reader/writer locks -------------------- -There is no particular reason why a reader/writer lock need be -significantly slower than a simple mutex. In both cases, the lock can be -acquired or released with a single atomic read-modify-write sequence. -Thus, the type nsync_mu is a reader/writer lock. Locks with reader-sections -can be used with condition variables and conditional critical sections -without affecting correctness. - -Cancellation ------------- -The pthread API allows the cancellation of individual threads, -and once a thread has been cancelled, it is expected to terminate soon. This -can work well in some cases, but may not be convenient if an activity is -associated with many threads, or if threads routinely act on behalf of multiple -activities. - -In nsync, cancellation involves an object separate from the thread, called an -nsync_note. An nsync_note is conceptually a boolean that makes a single -transition from false to true: it starts off "unnotified", can be notified: -- by an explicit nsync_note_notify() call, -- due to a timeout, or -- due to the transition of an optional parent nsync_note. -So, for example, in a network server, a request with a deadline -might have an nsync_note associated with it. Activities associated with -that request might each have a child nsync_note, possibly with shorter -deadlines. A cancellation request from the original caller -might cancel the parent, which would cancel all the children. - -The calls nsync_cv_wait_with_deadline() and nsync_mu_wait_with_deadline() take -both a deadline and a pointer to an nsync_note, and will wake when the awaited -condition becomes true, when the deadline (if any) expires, or when the -nsync_note becomes notified. The return value indicates which of these -occurred. diff --git a/vendored/nsync/VERSION b/vendored/nsync/VERSION deleted file mode 100644 index 034552a8..00000000 --- a/vendored/nsync/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.30.0 diff --git a/vendored/nsync/internal/common.c b/vendored/nsync/internal/common.c deleted file mode 100644 index 1052b853..00000000 --- a/vendored/nsync/internal/common.c +++ /dev/null @@ -1,256 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -/* This package provides a mutex nsync_mu and a Mesa-style condition variable nsync_cv. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "atomic.h" -#include "sem.h" -#include "dll.h" -#include "wait_internal.h" -#include "common.h" - -NSYNC_CPP_START_ - -/* Implementation notes - - The implementations of nsync_mu and nsync_cv both use spinlocks to protect - their waiter queues. The spinlocks are implemented with atomic operations - and a delay loop found below. They could use pthread_mutex_t, but I wished - to have an implementation independent of pthread mutexes and condition - variables. - - nsync_mu and nsync_cv use the same type of doubly-linked list of waiters - (see waiter.c). This allows waiters to be transferred from the cv queue to - the mu queue when a thread is logically woken from the cv but would - immediately go to sleep on the mu. See the wake_waiters() call. - - In mu, the "designated waker" is a thread that was waiting on mu, has been - woken up, but as yet has neither acquired nor gone back to waiting. The - presence of such a thread is indicated by the MU_DESIG_WAKER bit in the mu - word. This bit allows the nsync_mu_unlock() code to avoid waking a second - waiter when there's already one that will wake the next thread when the time - comes. This speeds things up when the lock is heavily contended, and the - critical sections are small. - - The weasel words "with high probability" in the specification of - nsync_mu_trylock() and nsync_mu_rtrylock() prevent clients from believing - that they can determine with certainty whether another thread has given up a - lock yet. This, together with the requirement that a thread that acquired a - mutex must release it (rather than it being released by another thread), - prohibits clients from using mu as a sort of semaphore. The intent is that - it be used only for traditional mutual exclusion, and that clients that need - a semaphore should use one. This leaves room for certain future - optimizations, and make it easier to apply detection of potential races via - candidate lock-set algorithms, should that ever be desired. - - The nsync_mu_wait_with_deadline() and nsync_mu_wait_with_deadline() calls use an - absolute rather than a relative timeout. This is less error prone, as - described in the comment on nsync_cv_wait_with_deadline(). Alas, relative - timeouts are seductive in trivial examples (such as tests). These are the - first things that people try, so they are likely to be requested. If enough - people complain we could give them that particular piece of rope. - - Excessive evaluations of the same wait condition are avoided by maintaining - waiter.same_condition as a doubly-linked list of waiters with the same - non-NULL wait condition that are also adjacent in the waiter list. This does - well even with large numbers of threads if there is at most one - wait condition that can be false at any given time (such as in a - producer/consumer queue, which cannot be both empty and full - simultaneously). One could imagine a queueing mechanism that would - guarantee to evaluate each condition at most once per wakeup, but that would - be substantially more complex, and would still degrade if the number of - distinct wakeup conditions were high. So clients are advised to resort to - condition variables if they have many distinct wakeup conditions. */ - -/* Used in spinloops to delay resumption of the loop. - Usage: - unsigned attempts = 0; - while (try_something) { - attempts = nsync_spin_delay_ (attempts); - } */ -unsigned nsync_spin_delay_ (unsigned attempts) { - if (attempts < 7) { - volatile int i; - for (i = 0; i != 1 << attempts; i++) { - } - attempts++; - } else { - nsync_yield_ (); - } - return (attempts); -} - -/* Spin until (*w & test) == 0, then atomically perform *w = ((*w | set) & - ~clear), perform an acquire barrier, and return the previous value of *w. - */ -uint32_t nsync_spin_test_and_set_ (nsync_atomic_uint32_ *w, uint32_t test, - uint32_t set, uint32_t clear) { - unsigned attempts = 0; /* CV_SPINLOCK retry count */ - uint32_t old = ATM_LOAD (w); - while ((old & test) != 0 || !ATM_CAS_ACQ (w, old, (old | set) & ~clear)) { - attempts = nsync_spin_delay_ (attempts); - old = ATM_LOAD (w); - } - return (old); -} - -/* ====================================================================================== */ - -struct nsync_waiter_s *nsync_dll_nsync_waiter_ (nsync_dll_element_ *e) { - struct nsync_waiter_s *nw = (struct nsync_waiter_s *) e->container; - ASSERT (nw->tag == NSYNC_WAITER_TAG); - ASSERT (e == &nw->q); - return (nw); -} -waiter *nsync_dll_waiter_ (nsync_dll_element_ *e) { - struct nsync_waiter_s *nw = DLL_NSYNC_WAITER (e); - waiter *w = CONTAINER (waiter, nw, nw); - ASSERT ((nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0); - ASSERT (w->tag == WAITER_TAG); - ASSERT (e == &w->nw.q); - return (w); -} - -waiter *nsync_dll_waiter_samecond_ (nsync_dll_element_ *e) { - waiter *w = (waiter *) e->container; - ASSERT (w->tag == WAITER_TAG); - ASSERT (e == &w->same_condition); - return (w); -} - -/* -------------------------------- */ - -static nsync_dll_list_ free_waiters = NULL; - -/* free_waiters points to a doubly-linked list of free waiter structs. */ -static nsync_atomic_uint32_ free_waiters_mu; /* spinlock; protects free_waiters */ - -static THREAD_LOCAL waiter *waiter_for_thread; -static void waiter_destroy (void *v) { - waiter *w = (waiter *) v; - /* Reset waiter_for_thread in case another thread-local variable reuses - the waiter in its destructor while the waiter is taken by the other - thread from free_waiters. This can happen as the destruction order - of thread-local variables can be arbitrary in some platform e.g. - POSIX. */ - waiter_for_thread = NULL; - IGNORE_RACES_START (); - ASSERT ((w->flags & (WAITER_RESERVED|WAITER_IN_USE)) == WAITER_RESERVED); - w->flags &= ~WAITER_RESERVED; - nsync_spin_test_and_set_ (&free_waiters_mu, 1, 1, 0); - free_waiters = nsync_dll_make_first_in_list_ (free_waiters, &w->nw.q); - ATM_STORE_REL (&free_waiters_mu, 0); /* release store */ - IGNORE_RACES_END (); -} - -/* If non-nil, nsync_malloc_ptr_ points to a malloc-like routine that allocated - memory, used by mutex and condition variable code to allocate waiter - structs. This would allow nsync's mutexes to be used inside an - implementation of malloc(), by providing another, simpler allocator here. - The intent is that the implicit NULL value here can be overridden by a - client declaration that uses an initializer. */ -void *(*nsync_malloc_ptr_) (size_t size); - -/* Return a pointer to an unused waiter struct. - Ensures that the enclosed timer is stopped and its channel drained. */ -waiter *nsync_waiter_new_ (void) { - nsync_dll_element_ *q; - waiter *tw; - waiter *w; - if (HAVE_THREAD_LOCAL) { - tw = waiter_for_thread; - } else { - tw = (waiter *) nsync_per_thread_waiter_ (&waiter_destroy); - } - w = tw; - if (w == NULL || (w->flags & (WAITER_RESERVED|WAITER_IN_USE)) != WAITER_RESERVED) { - w = NULL; - nsync_spin_test_and_set_ (&free_waiters_mu, 1, 1, 0); - q = nsync_dll_first_ (free_waiters); - if (q != NULL) { /* If free list is non-empty, dequeue an item. */ - free_waiters = nsync_dll_remove_ (free_waiters, q); - w = DLL_WAITER (q); - } - ATM_STORE_REL (&free_waiters_mu, 0); /* release store */ - if (w == NULL) { /* If free list was empty, allocate an item. */ - if (nsync_malloc_ptr_ != NULL) { /* Use client's malloc() */ - w = (waiter *) (*nsync_malloc_ptr_) (sizeof (*w)); - } else { /* standard malloc () */ - w = (waiter *) malloc (sizeof (*w)); - } - w->tag = WAITER_TAG; - w->nw.tag = NSYNC_WAITER_TAG; - nsync_mu_semaphore_init (&w->sem); - w->nw.sem = &w->sem; - nsync_dll_init_ (&w->nw.q, &w->nw); - NSYNC_ATOMIC_UINT32_STORE_ (&w->nw.waiting, 0); - w->nw.flags = NSYNC_WAITER_FLAG_MUCV; - ATM_STORE (&w->remove_count, 0); - nsync_dll_init_ (&w->same_condition, w); - w->flags = 0; - } - if (tw == NULL) { - w->flags |= WAITER_RESERVED; - nsync_set_per_thread_waiter_ (w, &waiter_destroy); - if (HAVE_THREAD_LOCAL) { - waiter_for_thread = w; - } - } - } - w->flags |= WAITER_IN_USE; - return (w); -} - -/* Return an unused waiter struct *w to the free pool. */ -void nsync_waiter_free_ (waiter *w) { - ASSERT ((w->flags & WAITER_IN_USE) != 0); - w->flags &= ~WAITER_IN_USE; - if ((w->flags & WAITER_RESERVED) == 0) { - nsync_spin_test_and_set_ (&free_waiters_mu, 1, 1, 0); - free_waiters = nsync_dll_make_first_in_list_ (free_waiters, &w->nw.q); - ATM_STORE_REL (&free_waiters_mu, 0); /* release store */ - } -} - -/* ====================================================================================== */ - -/* writer_type points to a lock_type that describes how to manipulate a mu for a writer. */ -static lock_type Xwriter_type = { - MU_WZERO_TO_ACQUIRE, - MU_WADD_TO_ACQUIRE, - MU_WHELD_IF_NON_ZERO, - MU_WSET_WHEN_WAITING, - MU_WCLEAR_ON_ACQUIRE, - MU_WCLEAR_ON_UNCONTENDED_RELEASE -}; -lock_type *nsync_writer_type_ = &Xwriter_type; - - -/* reader_type points to a lock_type that describes how to manipulate a mu for a reader. */ -static lock_type Xreader_type = { - MU_RZERO_TO_ACQUIRE, - MU_RADD_TO_ACQUIRE, - MU_RHELD_IF_NON_ZERO, - MU_RSET_WHEN_WAITING, - MU_RCLEAR_ON_ACQUIRE, - MU_RCLEAR_ON_UNCONTENDED_RELEASE -}; -lock_type *nsync_reader_type_ = &Xreader_type; - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/common.h b/vendored/nsync/internal/common.h deleted file mode 100644 index f5a56bc1..00000000 --- a/vendored/nsync/internal/common.h +++ /dev/null @@ -1,299 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_INTERNAL_COMMON_H_ -#define NSYNC_INTERNAL_COMMON_H_ - -#include "nsync_cpp.h" -#include "platform.h" -#include "nsync_atomic.h" -#include "sem.h" -#include "nsync_waiter.h" -#include "dll.h" -#include "nsync_mu.h" -#include "nsync_note.h" - -/* Annotations for race detectors. */ -#if defined(__has_feature) && !defined(__SANITIZE_THREAD__) -#if __has_feature(thread_sanitizer) /* used by clang */ -#define __SANITIZE_THREAD__ 1 /* GCC uses this; fake it in clang */ -#endif -#endif -#if defined(__SANITIZE_THREAD__) -NSYNC_C_START_ -void AnnotateIgnoreWritesBegin (const char* file, int line); -void AnnotateIgnoreWritesEnd (const char* file, int line); -void AnnotateIgnoreReadsBegin (const char* file, int line); -void AnnotateIgnoreReadsEnd (const char* file, int line); -void AnnotateRWLockCreate (const char *file, int line, void *mu); -void AnnotateRWLockAcquired (const char *file, int line, void *mu, long write); -void AnnotateRWLockReleased (const char *file, int line, void *mu, long write); -NSYNC_C_END_ -#define RWLOCK_CREATE(mu_) AnnotateRWLockCreate (__FILE__, __LINE__, (mu_)) -#define RWLOCK_TRYACQUIRE(cond_, mu_, wrt_) do { if (cond_) { AnnotateRWLockAcquired (__FILE__, __LINE__, (mu_), (wrt_)); } } while (0) -#define RWLOCK_RELEASE(mu_, wrt_) do { AnnotateRWLockReleased (__FILE__, __LINE__, (mu_), (wrt_)); } while (0) -#define IGNORE_RACES_START() \ - do { \ - AnnotateIgnoreReadsBegin (__FILE__, __LINE__); \ - AnnotateIgnoreWritesBegin (__FILE__, __LINE__); \ - } while (0) -#define IGNORE_RACES_END() \ - do { \ - AnnotateIgnoreWritesEnd (__FILE__, __LINE__); \ - AnnotateIgnoreReadsEnd (__FILE__, __LINE__); \ - } while (0) -#else -#define RWLOCK_CREATE(mu_) -#define RWLOCK_TRYACQUIRE(cond_, mu_, wrt_) -#define RWLOCK_RELEASE(mu_, wrt_) -#define IGNORE_RACES_START() -#define IGNORE_RACES_END() -#endif - -#ifndef NSYNC_DEBUG -#define NSYNC_DEBUG 0 -#endif - -NSYNC_CPP_START_ - -/* Yield the CPU. Platform specific. */ -void nsync_yield_ (void); - -/* Retrieve the per-thread cache of the waiter object. Platform specific. */ -void *nsync_per_thread_waiter_ (void (*dest) (void *)); - -/* Set the per-thread cache of the waiter object. Platform specific. */ -void nsync_set_per_thread_waiter_ (void *v, void (*dest) (void *)); - -/* Used in spinloops to delay resumption of the loop. - Usage: - unsigned attempts = 0; - while (try_something) { - attempts = nsync_spin_delay_ (attempts); - } */ -unsigned nsync_spin_delay_ (unsigned attempts); - -/* Spin until (*w & test) == 0, then atomically perform *w = ((*w | set) & - ~clear), perform an acquire barrier, and return the previous value of *w. - */ -uint32_t nsync_spin_test_and_set_ (nsync_atomic_uint32_ *w, uint32_t test, - uint32_t set, uint32_t clear); - -/* Abort after printing the nul-temrinated string s[]. */ -void nsync_panic_ (const char *s); - -/* ---------- */ - -#define MIN_(a_,b_) ((a_) < (b_)? (a_) : (b_)) -#define MAX_(a_,b_) ((a_) > (b_)? (a_) : (b_)) - -/* ---------- */ - -/* Fields in nsync_mu.word. - - - At least one of the MU_WLOCK or MU_RLOCK_FIELD fields must be zero. - - MU_WLOCK indicates that a write lock is held. - - MU_RLOCK_FIELD is a count of readers with read locks. - - - MU_SPINLOCK represents a spinlock that must be held when manipulating the - waiter queue. - - - MU_DESIG_WAKER indicates that a former waiter has been woken, but has - neither acquired the lock nor gone back to sleep. Legal to fail to set it; - illegal to set it when no such waiter exists. - - - MU_WAITING indicates whether the waiter queue is non-empty. - The following bits should be zero if MU_WAITING is zero. - - MU_CONDITION indicates that some waiter may have an associated condition - (from nsync_mu_wait, etc.). Legal to set it with no such waiter exists, - but illegal to fail to set it with such a waiter. - - MU_WRITER_WAITING indicates that a reader that has not yet blocked - at least once should not acquire in order not to starve waiting writers. - It set when a writer blocks or a reader is woken with a writer waiting. - It is reset when a writer acquires, but set again when that writer - releases if it wakes readers and there is a waiting writer. - - MU_LONG_WAIT indicates that a waiter has been woken many times but - repeatedly failed to acquire when competing for the lock. This is used - only to prevent long-term starvation by writers. The thread that sets it - clears it when if acquires. - - MU_ALL_FALSE indicates that a complete scan of the waiter list found no - waiters with true conditions, and the lock has not been acquired by a - writer since then. This allows a reader lock to be released without - testing conditions again. It is legal to fail to set this, but illegal - to set it inappropriately. - */ -#define MU_WLOCK ((uint32_t) (1 << 0)) /* writer lock is held. */ -#define MU_SPINLOCK ((uint32_t) (1 << 1)) /* spinlock is held (protects waiters). */ -#define MU_WAITING ((uint32_t) (1 << 2)) /* waiter list is non-empty. */ -#define MU_DESIG_WAKER ((uint32_t) (1 << 3)) /* a former waiter awoke, and hasn't yet acquired or slept anew */ -#define MU_CONDITION ((uint32_t) (1 << 4)) /* the wait list contains some conditional waiters. */ -#define MU_WRITER_WAITING ((uint32_t) (1 << 5)) /* there is a writer waiting */ -#define MU_LONG_WAIT ((uint32_t) (1 << 6)) /* the waiter at the head of the queue has been waiting a long time */ -#define MU_ALL_FALSE ((uint32_t) (1 << 7)) /* all waiter conditions are false */ -#define MU_RLOCK ((uint32_t) (1 << 8)) /* low-order bit of reader count, which uses rest of word */ - -/* The constants below are derived from those above. */ -#define MU_RLOCK_FIELD (~(uint32_t) (MU_RLOCK - 1)) /* mask of reader count field */ - -#define MU_ANY_LOCK (MU_WLOCK | MU_RLOCK_FIELD) /* mask for any lock held */ - -#define MU_WZERO_TO_ACQUIRE (MU_ANY_LOCK | MU_LONG_WAIT) /* bits to be zero to acquire write lock */ -#define MU_WADD_TO_ACQUIRE (MU_WLOCK) /* add to acquire a write lock */ -#define MU_WHELD_IF_NON_ZERO (MU_WLOCK) /* if any of these bits are set, write lock is held */ -#define MU_WSET_WHEN_WAITING (MU_WAITING | MU_WRITER_WAITING) /* a writer is waiting */ -#define MU_WCLEAR_ON_ACQUIRE (MU_WRITER_WAITING) /* clear MU_WRITER_WAITING when a writer acquires */ -#define MU_WCLEAR_ON_UNCONTENDED_RELEASE (MU_ALL_FALSE) /* clear if a writer releases w/o waking */ - -/* bits to be zero to acquire read lock */ -#define MU_RZERO_TO_ACQUIRE (MU_WLOCK | MU_WRITER_WAITING | MU_LONG_WAIT) -#define MU_RADD_TO_ACQUIRE (MU_RLOCK) /* add to acquire a read lock */ -#define MU_RHELD_IF_NON_ZERO (MU_RLOCK_FIELD) /* if any of these bits are set, read lock is held */ -#define MU_RSET_WHEN_WAITING (MU_WAITING) /* indicate that some thread is waiting */ -#define MU_RCLEAR_ON_ACQUIRE ((uint32_t) 0) /* nothing to clear when a read acquires */ -#define MU_RCLEAR_ON_UNCONTENDED_RELEASE ((uint32_t) 0) /* nothing to clear when a read releases */ - - -/* A lock_type holds the values needed to manipulate a mu in some mode (read or - write). This allows some of the code to be generic, and parameterized by - the lock type. */ -typedef struct lock_type_s { - uint32_t zero_to_acquire; /* bits that must be zero to acquire */ - uint32_t add_to_acquire; /* constant to add to acquire */ - uint32_t held_if_non_zero; /* if any of these bits are set, the lock is held */ - uint32_t set_when_waiting; /* set when thread waits */ - uint32_t clear_on_acquire; /* clear when thread acquires */ - uint32_t clear_on_uncontended_release; /* clear when thread releases without waking */ -} lock_type; - - -/* writer_type points to a lock_type that describes how to manipulate a mu for a writer. */ -extern lock_type *nsync_writer_type_; - -/* reader_type points to a lock_type that describes how to manipulate a mu for a reader. */ -extern lock_type *nsync_reader_type_; - -/* ---------- */ - -/* Bits in nsync_cv.word */ - -#define CV_SPINLOCK ((uint32_t) (1 << 0)) /* protects waiters */ -#define CV_NON_EMPTY ((uint32_t) (1 << 1)) /* waiters list is non-empty */ - -/* ---------- */ - -/* Hold a pair of condition function and its argument. */ -struct wait_condition_s { - int (*f) (const void *v); - const void *v; - int (*eq) (const void *a, const void *b); -}; - -/* Return whether wait conditions *a_ and *b_ are equal and non-null. */ -#define WAIT_CONDITION_EQ(a_, b_) ((a_)->f != NULL && (a_)->f == (b_)->f && \ - ((a_)->v == (b_)->v || \ - ((a_)->eq != NULL && (*(a_)->eq) ((a_)->v, (b_)->v)))) - -/* If a waiter has waited this many times, it may set the MU_LONG_WAIT bit. */ -#define LONG_WAIT_THRESHOLD 30 - -/* ---------- */ - -#define NOTIFIED_TIME(n_) (ATM_LOAD_ACQ (&(n_)->notified) != 0? nsync_time_zero : \ - (n_)->expiry_time_valid? (n_)->expiry_time : nsync_time_no_deadline) - -/* A waiter represents a single waiter on a cv or a mu. - - To wait: - Allocate a waiter struct *w with new_waiter(), set w.waiting=1, and - w.cv_mu=nil or to the associated mu if waiting on a condition variable, then - queue w.nsync_dll on some queue, and then wait using: - while (ATM_LOAD_ACQ (&w.waiting) != 0) { nsync_mu_semaphore_p (&w.sem); } - Return *w to the freepool by calling free_waiter (w). - - To wakeup: - Remove *w from the relevant queue then: - ATM_STORE_REL (&w.waiting, 0); - nsync_mu_semaphore_v (&w.sem); */ -typedef struct { - uint32_t tag; /* debug DLL_NSYNC_WAITER, DLL_WAITER, DLL_WAITER_SAMECOND */ - nsync_semaphore sem; /* Thread waits on this semaphore. */ - struct nsync_waiter_s nw; /* An embedded nsync_waiter_s. */ - struct nsync_mu_s_ *cv_mu; /* pointer to nsync_mu associated with a cv wait */ - lock_type *l_type; /* Lock type of the mu, or nil if not associated with a mu. */ - nsync_atomic_uint32_ remove_count; /* count of removals from queue */ - struct wait_condition_s cond; /* A condition on which to acquire a mu. */ - nsync_dll_element_ same_condition; /* Links neighbours in nw.q with same non-nil condition. */ - int flags; /* see WAITER_* bits below */ -} waiter; -static const uint32_t WAITER_TAG = 0x0590239f; -static const uint32_t NSYNC_WAITER_TAG = 0x726d2ba9; - -#define WAITER_RESERVED 0x1 /* waiter reserved by a thread, even when not in use */ -#define WAITER_IN_USE 0x2 /* waiter in use by a thread */ - -#define CONTAINER(t_,f_,p_) ((t_ *) (((char *) (p_)) - offsetof (t_, f_))) -#define ASSERT(x) do { if (!(x)) { *(volatile int *)0 = 0; } } while (0) - -/* Return a pointer to the nsync_waiter_s containing nsync_dll_element_ *e. */ -#define DLL_NSYNC_WAITER(e) (NSYNC_DEBUG? nsync_dll_nsync_waiter_ (e) : \ - ((struct nsync_waiter_s *)((e)->container))) -struct nsync_waiter_s *nsync_dll_nsync_waiter_ (nsync_dll_element_ *e); - -/* Return a pointer to the waiter struct that *e is embedded in, where *e is an nw.q field. */ -#define DLL_WAITER(e) (NSYNC_DEBUG? nsync_dll_waiter_ (e) : \ - CONTAINER (waiter, nw, DLL_NSYNC_WAITER(e))) -waiter *nsync_dll_waiter_ (nsync_dll_element_ *e); - -/* Return a pointer to the waiter struct that *e is embedded in, where *e is a - same_condition field. */ -#define DLL_WAITER_SAMECOND(e) (NSYNC_DEBUG? nsync_dll_waiter_samecond_ (e) : \ - ((waiter *) ((e)->container))) -waiter *nsync_dll_waiter_samecond_ (nsync_dll_element_ *e); - -/* Return a pointer to an unused waiter struct. - Ensures that the enclosed timer is stopped and its channel drained. */ -waiter *nsync_waiter_new_ (void); - -/* Return an unused waiter struct *w to the free pool. */ -void nsync_waiter_free_ (waiter *w); - -/* ---------- */ - -/* The internals of an nync_note. See internal/note.c for details of locking - discipline. */ -struct nsync_note_s_ { - nsync_dll_element_ parent_child_link; /* parent's children, under parent->note_mu */ - int expiry_time_valid; /* whether expiry_time is valid; r/o after init */ - nsync_time expiry_time; /* expiry time, if expiry_time_valid != 0; r/o after init */ - nsync_mu note_mu; /* protects fields below except "notified" */ - nsync_cv no_children_cv; /* signalled when children becomes empty */ - uint32_t disconnecting; /* non-zero => node is being disconnected */ - nsync_atomic_uint32_ notified; /* non-zero if the note has been notified */ - struct nsync_note_s_ *parent; /* points to parent, if any */ - nsync_dll_element_ *children; /* list of children */ - nsync_dll_element_ *waiters; /* list of waiters */ -}; - -/* ---------- */ - -void nsync_mu_lock_slow_ (nsync_mu *mu, waiter *w, uint32_t clear, lock_type *l_type); -void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type); -nsync_dll_list_ nsync_remove_from_mu_queue_ (nsync_dll_list_ mu_queue, nsync_dll_element_ *e); -void nsync_maybe_merge_conditions_ (nsync_dll_element_ *p, nsync_dll_element_ *n); -nsync_time nsync_note_notified_deadline_ (nsync_note n); -int nsync_sem_wait_with_cancel_ (waiter *w, nsync_time abs_deadline, - nsync_note cancel_note); -NSYNC_CPP_END_ - -#endif /*NSYNC_INTERNAL_COMMON_H_*/ diff --git a/vendored/nsync/internal/counter.c b/vendored/nsync/internal/counter.c deleted file mode 100644 index 83af4504..00000000 --- a/vendored/nsync/internal/counter.c +++ /dev/null @@ -1,150 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "atomic.h" -#include "dll.h" -#include "sem.h" -#include "wait_internal.h" -#include "common.h" - -NSYNC_CPP_START_ - -/* Internal details of nsync_counter. */ -struct nsync_counter_s_ { - nsync_atomic_uint32_ waited; /* wait has been called */ - nsync_mu counter_mu; /* protects fields below except reads of "value" */ - nsync_atomic_uint32_ value; /* value of counter */ - struct nsync_dll_element_s_ *waiters; /* list of waiters */ -}; - -nsync_counter nsync_counter_new (uint32_t value) { - nsync_counter c = (nsync_counter) malloc (sizeof (*c)); - if (c != NULL) { - memset ((void *) c, 0, sizeof (*c)); - ATM_STORE (&c->value, value); - } - return (c); -} - -void nsync_counter_free (nsync_counter c) { - nsync_mu_lock (&c->counter_mu); - ASSERT (nsync_dll_is_empty_ (c->waiters)); - nsync_mu_unlock (&c->counter_mu); - free (c); -} - -uint32_t nsync_counter_add (nsync_counter c, int32_t delta) { - uint32_t value; - IGNORE_RACES_START (); - if (delta == 0) { - value = ATM_LOAD_ACQ (&c->value); - } else { - nsync_mu_lock (&c->counter_mu); - do { - value = ATM_LOAD (&c->value); - } while (!ATM_CAS_RELACQ (&c->value, value, value+delta)); - value += delta; - if (delta > 0) { - /* It's illegal to increase the count from zero if - there has been a waiter. */ - ASSERT (value != (uint32_t) delta || !ATM_LOAD (&c->waited)); - ASSERT (value > value - delta); /* Crash on overflow. */ - } else { - ASSERT (value < value - delta); /* Crash on overflow. */ - } - if (value == 0) { - nsync_dll_element_ *p; - while ((p = nsync_dll_first_ (c->waiters)) != NULL) { - struct nsync_waiter_s *nw = DLL_NSYNC_WAITER (p); - c->waiters = nsync_dll_remove_ (c->waiters, p); - ATM_STORE_REL (&nw->waiting, 0); - nsync_mu_semaphore_v (nw->sem); - } - } - nsync_mu_unlock (&c->counter_mu); - } - IGNORE_RACES_END (); - return (value); -} - -uint32_t nsync_counter_value (nsync_counter c) { - uint32_t result; - IGNORE_RACES_START (); - result = ATM_LOAD_ACQ (&c->value); - IGNORE_RACES_END (); - return (result); -} - -uint32_t nsync_counter_wait (nsync_counter c, nsync_time abs_deadline) { - struct nsync_waitable_s waitable; - struct nsync_waitable_s *pwaitable = &waitable; - uint32_t result = 0; - waitable.v = c; - waitable.funcs = &nsync_counter_waitable_funcs; - if (nsync_wait_n (NULL, NULL, NULL, abs_deadline, 1, &pwaitable) != 0) { - IGNORE_RACES_START (); - result = ATM_LOAD_ACQ (&c->value); - IGNORE_RACES_END (); - } - return (result); -} - -static nsync_time counter_ready_time (void *v, struct nsync_waiter_s *nw UNUSED) { - nsync_counter c = (nsync_counter) v; - nsync_time r; - ATM_STORE (&c->waited, 1); - r = (ATM_LOAD_ACQ (&c->value) == 0? nsync_time_zero : nsync_time_no_deadline); - return (r); -} - -static int counter_enqueue (void *v, struct nsync_waiter_s *nw) { - nsync_counter c = (nsync_counter) v; - int32_t value; - nsync_mu_lock (&c->counter_mu); - value = ATM_LOAD_ACQ (&c->value); - if (value != 0) { - c->waiters = nsync_dll_make_last_in_list_ (c->waiters, &nw->q); - ATM_STORE (&nw->waiting, 1); - } else { - ATM_STORE (&nw->waiting, 0); - } - nsync_mu_unlock (&c->counter_mu); - return (value != 0); -} - -static int counter_dequeue (void *v, struct nsync_waiter_s *nw) { - nsync_counter c = (nsync_counter) v; - int32_t value; - nsync_mu_lock (&c->counter_mu); - value = ATM_LOAD_ACQ (&c->value); - if (ATM_LOAD_ACQ (&nw->waiting) != 0) { - c->waiters = nsync_dll_remove_ (c->waiters, &nw->q); - ATM_STORE (&nw->waiting, 0); - } - nsync_mu_unlock (&c->counter_mu); - return (value != 0); -} - -const struct nsync_waitable_funcs_s nsync_counter_waitable_funcs = { - &counter_ready_time, - &counter_enqueue, - &counter_dequeue -}; - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/cv.c b/vendored/nsync/internal/cv.c deleted file mode 100644 index 88977643..00000000 --- a/vendored/nsync/internal/cv.c +++ /dev/null @@ -1,495 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "dll.h" -#include "sem.h" -#include "wait_internal.h" -#include "common.h" -#include "atomic.h" - -NSYNC_CPP_START_ - -/* Initialize *cv. */ -void nsync_cv_init (nsync_cv *cv) { - memset ((void *) cv, 0, sizeof (*cv)); -} - -/* Wake the cv waiters in the circular list pointed to by - to_wake_list, which may not be NULL. If the waiter is associated with a - nsync_mu, the "wakeup" may consist of transferring the waiters to the nsync_mu's - queue. Requires that every waiter is associated with the same mutex. - all_readers indicates whether all the waiters on the list are readers. */ -static void wake_waiters (nsync_dll_list_ to_wake_list, int all_readers) { - nsync_dll_element_ *p = NULL; - nsync_dll_element_ *next = NULL; - nsync_dll_element_ *first_waiter = nsync_dll_first_ (to_wake_list); - struct nsync_waiter_s *first_nw = DLL_NSYNC_WAITER (first_waiter); - waiter *first_w = NULL; - nsync_mu *pmu = NULL; - if ((first_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0) { - first_w = DLL_WAITER (first_waiter); - pmu = first_w->cv_mu; - } - if (pmu != NULL) { /* waiter is associated with the nsync_mu *pmu. */ - /* We will transfer elements of to_wake_list to *pmu if all of: - - some thread holds the lock, and - - *pmu's spinlock is not held, and - - either *pmu cannot be acquired in the mode of the first - waiter, or there's more than one thread on to_wake_list - and not all are readers, and - - we acquire the spinlock on the first try. - The spinlock acquisition also marks *pmu as having waiters. - The requirement that some thread holds the lock ensures - that at least one of the transferred waiters will be woken. - */ - uint32_t old_mu_word = ATM_LOAD (&pmu->word); - int first_cant_acquire = ((old_mu_word & first_w->l_type->zero_to_acquire) != 0); - next = nsync_dll_next_ (to_wake_list, first_waiter); - if ((old_mu_word&MU_ANY_LOCK) != 0 && - (old_mu_word&MU_SPINLOCK) == 0 && - (first_cant_acquire || (next != NULL && !all_readers)) && - ATM_CAS_ACQ (&pmu->word, old_mu_word, - (old_mu_word|MU_SPINLOCK|MU_WAITING) & - ~MU_ALL_FALSE)) { - - uint32_t set_on_release = 0; - - /* For any waiter that should be transferred, rather - than woken, move it from to_wake_list to pmu->waiters. */ - int first_is_writer = first_w->l_type == nsync_writer_type_; - int transferred_a_writer = 0; - int woke_areader = 0; - /* Transfer the first waiter iff it can't acquire *pmu. */ - if (first_cant_acquire) { - to_wake_list = nsync_dll_remove_ (to_wake_list, first_waiter); - pmu->waiters = nsync_dll_make_last_in_list_ (pmu->waiters, first_waiter); - /* tell nsync_cv_wait_with_deadline() that we - moved the waiter to *pmu's queue. */ - first_w->cv_mu = NULL; - /* first_nw.waiting is already 1, from being on - cv's waiter queue. */ - transferred_a_writer = first_is_writer; - } else { - woke_areader = !first_is_writer; - } - /* Now process the other waiters. */ - for (p = next; p != NULL; p = next) { - int p_is_writer; - struct nsync_waiter_s *p_nw = DLL_NSYNC_WAITER (p); - waiter *p_w = NULL; - if ((p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0) { - p_w = DLL_WAITER (p); - } - next = nsync_dll_next_ (to_wake_list, p); - p_is_writer = (p_w != NULL && - DLL_WAITER (p)->l_type == nsync_writer_type_); - /* We transfer this element if any of: - - the first waiter can't acquire *pmu, or - - the first waiter is a writer, or - - this element is a writer. */ - if (p_w == NULL) { - /* wake non-native waiter */ - } else if (first_cant_acquire || first_is_writer || p_is_writer) { - to_wake_list = nsync_dll_remove_ (to_wake_list, p); - pmu->waiters = nsync_dll_make_last_in_list_ (pmu->waiters, p); - /* tell nsync_cv_wait_with_deadline() - that we moved the waiter to *pmu's - queue. */ - p_w->cv_mu = NULL; - /* p_nw->waiting is already 1, from - being on cv's waiter queue. */ - transferred_a_writer = transferred_a_writer || p_is_writer; - } else { - woke_areader = woke_areader || !p_is_writer; - } - } - - /* Claim a waiting writer if we transferred one, except if we woke readers, - in which case we want those readers to be able to acquire immediately. */ - if (transferred_a_writer && !woke_areader) { - set_on_release |= MU_WRITER_WAITING; - } - - /* release *pmu's spinlock (MU_WAITING was set by CAS above) */ - old_mu_word = ATM_LOAD (&pmu->word); - while (!ATM_CAS_REL (&pmu->word, old_mu_word, - (old_mu_word|set_on_release) & ~MU_SPINLOCK)) { - old_mu_word = ATM_LOAD (&pmu->word); - } - } - } - - /* Wake any waiters we didn't manage to enqueue on the mu. */ - for (p = nsync_dll_first_ (to_wake_list); p != NULL; p = next) { - struct nsync_waiter_s *p_nw = DLL_NSYNC_WAITER (p); - next = nsync_dll_next_ (to_wake_list, p); - to_wake_list = nsync_dll_remove_ (to_wake_list, p); - /* Wake the waiter. */ - ATM_STORE_REL (&p_nw->waiting, 0); /* release store */ - nsync_mu_semaphore_v (p_nw->sem); - } -} - -/* ------------------------------------------ */ - -/* Versions of nsync_mu_lock() and nsync_mu_unlock() that take "void *" - arguments, to avoid call through a function pointer of a different type, - which is undefined. */ -static void void_mu_lock (void *mu) { - nsync_mu_lock ((nsync_mu *) mu); -} -static void void_mu_unlock (void *mu) { - nsync_mu_unlock ((nsync_mu *) mu); -} - -/* Atomically release *pmu (which must be held on entry) - and block the calling thread on *pcv. Then wait until awakened by a - call to nsync_cv_signal() or nsync_cv_broadcast() (or a spurious wakeup), or by the time - reaching abs_deadline, or by cancel_note being notified. In all cases, - reacquire *pmu, and return the reason for the call returned (0, ETIMEDOUT, - or ECANCELED). Callers should abs_deadline==nsync_time_no_deadline for no - deadline, and cancel_note==NULL for no cancellation. nsync_cv_wait_with_deadline() - should be used in a loop, as with all Mesa-style condition variables. See - examples above. - - There are two reasons for using an absolute deadline, rather than a relative - timeout---these are why pthread_cond_timedwait() also uses an absolute - deadline. First, condition variable waits have to be used in a loop; with - an absolute times, the deadline does not have to be recomputed on each - iteration. Second, in most real programmes, some activity (such as an RPC - to a server, or when guaranteeing response time in a UI), there is a - deadline imposed by the specification or the caller/user; relative delays - can shift arbitrarily with scheduling delays, and so after multiple waits - might extend beyond the expected deadline. Relative delays tend to be more - convenient mostly in tests and trivial examples than they are in real - programmes. */ -int nsync_cv_wait_with_deadline_generic (nsync_cv *pcv, void *pmu, - void (*lock) (void *), void (*unlock) (void *), - nsync_time abs_deadline, - nsync_note cancel_note) { - nsync_mu *cv_mu = NULL; - int is_reader_mu; - uint32_t old_word; - uint32_t remove_count; - int sem_outcome; - unsigned attempts; - int outcome = 0; - waiter *w; - IGNORE_RACES_START (); - w = nsync_waiter_new_ (); - ATM_STORE (&w->nw.waiting, 1); - w->cond.f = NULL; /* Not using a conditional critical section. */ - w->cond.v = NULL; - w->cond.eq = NULL; - if (lock == &void_mu_lock || - lock == (void (*) (void *)) &nsync_mu_lock || - lock == (void (*) (void *)) &nsync_mu_rlock) { - cv_mu = (nsync_mu *) pmu; - } - w->cv_mu = cv_mu; /* If *pmu is an nsync_mu, record its address, else record NULL. */ - is_reader_mu = 0; /* If true, an nsync_mu in reader mode. */ - if (cv_mu == NULL) { - w->l_type = NULL; - } else { - uint32_t old_mu_word = ATM_LOAD (&cv_mu->word); - int is_writer = (old_mu_word & MU_WHELD_IF_NON_ZERO) != 0; - int is_reader = (old_mu_word & MU_RHELD_IF_NON_ZERO) != 0; - if (is_writer) { - if (is_reader) { - nsync_panic_ ("mu held in reader and writer mode simultaneously " - "on entry to nsync_cv_wait_with_deadline()\n"); - } - w->l_type = nsync_writer_type_; - } else if (is_reader) { - w->l_type = nsync_reader_type_; - is_reader_mu = 1; - } else { - nsync_panic_ ("mu not held on entry to nsync_cv_wait_with_deadline()\n"); - } - } - - /* acquire spinlock, set non-empty */ - old_word = nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, CV_SPINLOCK|CV_NON_EMPTY, 0); - pcv->waiters = nsync_dll_make_last_in_list_ (pcv->waiters, &w->nw.q); - remove_count = ATM_LOAD (&w->remove_count); - /* Release the spin lock. */ - ATM_STORE_REL (&pcv->word, old_word|CV_NON_EMPTY); /* release store */ - - /* Release *pmu. */ - if (is_reader_mu) { - nsync_mu_runlock (cv_mu); - } else { - (*unlock) (pmu); - } - - /* wait until awoken or a timeout. */ - sem_outcome = 0; - attempts = 0; - while (ATM_LOAD_ACQ (&w->nw.waiting) != 0) { /* acquire load */ - if (sem_outcome == 0) { - sem_outcome = nsync_sem_wait_with_cancel_ (w, abs_deadline, cancel_note); - } - - if (sem_outcome != 0 && ATM_LOAD (&w->nw.waiting) != 0) { - /* A timeout or cancellation occurred, and no wakeup. - Acquire *pcv's spinlock, and confirm. */ - old_word = nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, - CV_SPINLOCK, 0); - /* Check that w wasn't removed from the queue after we - checked above, but before we acquired the spinlock. - The test of remove_count confirms that the waiter *w - is still governed by *pcv's spinlock; otherwise, some - other thread is about to set w.waiting==0. */ - if (ATM_LOAD (&w->nw.waiting) != 0) { - if (remove_count == ATM_LOAD (&w->remove_count)) { - uint32_t old_value; - /* still in cv waiter queue */ - /* Not woken, so remove *w from cv - queue, and declare a - timeout/cancellation. */ - outcome = sem_outcome; - pcv->waiters = nsync_dll_remove_ (pcv->waiters, - &w->nw.q); - do { - old_value = ATM_LOAD (&w->remove_count); - } while (!ATM_CAS (&w->remove_count, old_value, old_value+1)); - if (nsync_dll_is_empty_ (pcv->waiters)) { - old_word &= ~(CV_NON_EMPTY); - } - ATM_STORE_REL (&w->nw.waiting, 0); /* release store */ - } - } - /* Release spinlock. */ - ATM_STORE_REL (&pcv->word, old_word); /* release store */ - } - - if (ATM_LOAD (&w->nw.waiting) != 0) { - /* The delay here causes this thread ultimately to - yield to another that has dequeued this thread, but - has not yet set the waiting field to zero; a - cancellation or timeout may prevent this thread - from blocking above on the semaphore. */ - attempts = nsync_spin_delay_ (attempts); - } - } - - if (cv_mu != NULL && w->cv_mu == NULL) { /* waiter was moved to *pmu's queue, and woken. */ - /* Requeue on *pmu using existing waiter struct; current thread - is the designated waker. */ - nsync_mu_lock_slow_ (cv_mu, w, MU_DESIG_WAKER, w->l_type); - RWLOCK_TRYACQUIRE (1, cv_mu, w->l_type == nsync_writer_type_); - nsync_waiter_free_ (w); - } else { - /* Traditional case: We've woken from the cv, and need to reacquire *pmu. */ - nsync_waiter_free_ (w); - if (is_reader_mu) { - nsync_mu_rlock (cv_mu); - } else { - (*lock) (pmu); - } - } - IGNORE_RACES_END (); - return (outcome); -} - -/* Wake at least one thread if any are currently blocked on *pcv. If - the chosen thread is a reader on an nsync_mu, wake all readers and, if - possible, a writer. */ -void nsync_cv_signal (nsync_cv *pcv) { - IGNORE_RACES_START (); - if ((ATM_LOAD_ACQ (&pcv->word) & CV_NON_EMPTY) != 0) { /* acquire load */ - nsync_dll_list_ to_wake_list = NULL; /* waiters that we will wake */ - int all_readers = 0; - /* acquire spinlock */ - uint32_t old_word = nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, - CV_SPINLOCK, 0); - if (!nsync_dll_is_empty_ (pcv->waiters)) { - /* Point to first waiter that enqueued itself, and - detach it from all others. */ - struct nsync_waiter_s *first_nw; - nsync_dll_element_ *first = nsync_dll_first_ (pcv->waiters); - pcv->waiters = nsync_dll_remove_ (pcv->waiters, first); - first_nw = DLL_NSYNC_WAITER (first); - if ((first_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0) { - uint32_t old_value; - do { - old_value = - ATM_LOAD (&DLL_WAITER (first)->remove_count); - } while (!ATM_CAS (&DLL_WAITER (first)->remove_count, - old_value, old_value+1)); - } - to_wake_list = nsync_dll_make_last_in_list_ (to_wake_list, first); - if ((first_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0 && - DLL_WAITER (first)->l_type == nsync_reader_type_) { - int woke_writer; - /* If the first waiter is a reader, wake all readers, and - if it's possible, one writer. This allows reader-regions - to be added to a monitor without invalidating code in which - a client has optimized broadcast calls by converting them to - signal calls. In particular, we wake a writer when waking - readers because the readers will not invalidate the condition - that motivated the client to call nsync_cv_signal(). But we - wake at most one writer because the first writer may invalidate - the condition; the client is expecting only one writer to be - able make use of the wakeup, or he would have called - nsync_cv_broadcast(). */ - nsync_dll_element_ *p = NULL; - nsync_dll_element_ *next = NULL; - all_readers = 1; - woke_writer = 0; - for (p = nsync_dll_first_ (pcv->waiters); p != NULL; p = next) { - struct nsync_waiter_s *p_nw = DLL_NSYNC_WAITER (p); - int should_wake; - next = nsync_dll_next_ (pcv->waiters, p); - should_wake = 0; - if ((p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0 && - DLL_WAITER (p)->l_type == nsync_reader_type_) { - should_wake = 1; - } else if (!woke_writer) { - woke_writer = 1; - all_readers = 0; - should_wake = 1; - } - if (should_wake) { - pcv->waiters = nsync_dll_remove_ (pcv->waiters, p); - if ((p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0) { - uint32_t old_value; - do { - old_value = ATM_LOAD ( - &DLL_WAITER (p)->remove_count); - } while (!ATM_CAS (&DLL_WAITER (p)->remove_count, - old_value, old_value+1)); - } - to_wake_list = nsync_dll_make_last_in_list_ ( - to_wake_list, p); - } - } - } - if (nsync_dll_is_empty_ (pcv->waiters)) { - old_word &= ~(CV_NON_EMPTY); - } - } - /* Release spinlock. */ - ATM_STORE_REL (&pcv->word, old_word); /* release store */ - if (!nsync_dll_is_empty_ (to_wake_list)) { - wake_waiters (to_wake_list, all_readers); - } - } - IGNORE_RACES_END (); -} - -/* Wake all threads currently blocked on *pcv. */ -void nsync_cv_broadcast (nsync_cv *pcv) { - IGNORE_RACES_START (); - if ((ATM_LOAD_ACQ (&pcv->word) & CV_NON_EMPTY) != 0) { /* acquire load */ - nsync_dll_element_ *p; - nsync_dll_element_ *next; - int all_readers; - nsync_dll_list_ to_wake_list = NULL; /* waiters that we will wake */ - /* acquire spinlock */ - nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, CV_SPINLOCK, 0); - p = NULL; - next = NULL; - all_readers = 1; - /* Wake entire waiter list, which we leave empty. */ - for (p = nsync_dll_first_ (pcv->waiters); p != NULL; p = next) { - struct nsync_waiter_s *p_nw = DLL_NSYNC_WAITER (p); - next = nsync_dll_next_ (pcv->waiters, p); - all_readers = all_readers && (p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0 && - (DLL_WAITER (p)->l_type == nsync_reader_type_); - pcv->waiters = nsync_dll_remove_ (pcv->waiters, p); - if ((p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0) { - uint32_t old_value; - do { - old_value = ATM_LOAD (&DLL_WAITER (p)->remove_count); - } while (!ATM_CAS (&DLL_WAITER (p)->remove_count, - old_value, old_value+1)); - } - to_wake_list = nsync_dll_make_last_in_list_ (to_wake_list, p); - } - /* Release spinlock and mark queue empty. */ - ATM_STORE_REL (&pcv->word, 0); /* release store */ - if (!nsync_dll_is_empty_ (to_wake_list)) { /* Wake them. */ - wake_waiters (to_wake_list, all_readers); - } - } - IGNORE_RACES_END (); -} - -/* Wait with deadline, using an nsync_mu. */ -int nsync_cv_wait_with_deadline (nsync_cv *pcv, nsync_mu *pmu, - nsync_time abs_deadline, - nsync_note cancel_note) { - return (nsync_cv_wait_with_deadline_generic (pcv, pmu, &void_mu_lock, - &void_mu_unlock, - abs_deadline, cancel_note)); -} - -/* Atomically release *pmu and block the caller on *pcv. Wait - until awakened by a call to nsync_cv_signal() or nsync_cv_broadcast(), or a spurious - wakeup. Then reacquires *pmu, and return. The call is equivalent to a call - to nsync_cv_wait_with_deadline() with abs_deadline==nsync_time_no_deadline, and a NULL - cancel_note. It should be used in a loop, as with all standard Mesa-style - condition variables. See examples above. */ -void nsync_cv_wait (nsync_cv *pcv, nsync_mu *pmu) { - nsync_cv_wait_with_deadline (pcv, pmu, nsync_time_no_deadline, NULL); -} - -static nsync_time cv_ready_time (void *v UNUSED, struct nsync_waiter_s *nw) { - nsync_time r; - r = (nw == NULL || ATM_LOAD_ACQ (&nw->waiting) != 0? nsync_time_no_deadline : nsync_time_zero); - return (r); -} - -static int cv_enqueue (void *v, struct nsync_waiter_s *nw) { - nsync_cv *pcv = (nsync_cv *) v; - /* acquire spinlock */ - uint32_t old_word = nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, CV_SPINLOCK, 0); - pcv->waiters = nsync_dll_make_last_in_list_ (pcv->waiters, &nw->q); - ATM_STORE (&nw->waiting, 1); - /* Release spinlock. */ - ATM_STORE_REL (&pcv->word, old_word | CV_NON_EMPTY); /* release store */ - return (1); -} - -static int cv_dequeue (void *v, struct nsync_waiter_s *nw) { - nsync_cv *pcv = (nsync_cv *) v; - int was_queued = 0; - /* acquire spinlock */ - uint32_t old_word = nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, CV_SPINLOCK, 0); - if (ATM_LOAD_ACQ (&nw->waiting) != 0) { - pcv->waiters = nsync_dll_remove_ (pcv->waiters, &nw->q); - ATM_STORE (&nw->waiting, 0); - was_queued = 1; - } - if (nsync_dll_is_empty_ (pcv->waiters)) { - old_word &= ~(CV_NON_EMPTY); - } - /* Release spinlock. */ - ATM_STORE_REL (&pcv->word, old_word); /* release store */ - return (was_queued); -} - -const struct nsync_waitable_funcs_s nsync_cv_waitable_funcs = { - &cv_ready_time, - &cv_enqueue, - &cv_dequeue -}; - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/debug.c b/vendored/nsync/internal/debug.c deleted file mode 100644 index 3da9b6aa..00000000 --- a/vendored/nsync/internal/debug.c +++ /dev/null @@ -1,293 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -/* Routines for debugging. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "dll.h" -#include "sem.h" -#include "wait_internal.h" -#include "common.h" -#include "atomic.h" - -NSYNC_CPP_START_ - -/* ---------- */ - -/* An emit_buf represents a buffer into which debug information can - be written. */ -struct emit_buf { - char *start; /* start of buffer */ - int len; /* pength of buffer */ - int pos; /* position of next character to bve written */ - int overflow; /* non-zero iff buffer overflow has occurred */ -}; - -/* Initialize *b to point to start[0, .., len-1], and return b. - of to an internal static buffer if buf==NULL. */ -static struct emit_buf *emit_init (struct emit_buf *b, char *start, int len) { - b->start = start; - b->len = len; - b->pos = 0; - b->overflow = 0; - return (b); -} - - -/* Write character c to buffer *b. */ -static void emit_c (struct emit_buf *b, int c) { - if (b->pos < b->len) { - b->start[b->pos++] = c; - } else if (!b->overflow) { - static const char suffix[] = "..."; - const char *s = &suffix[sizeof (suffix)]; /* past nul */ - char *p = &b->start[b->len]; /* past end */ - while (s > suffix && p > b->start) { - *--p = *--s; - } - b->overflow = 1; - } -} - -/* A printf-like function that writes to an emit_buf. - It understands only the format specifiers %s (const char *), and %i - (uintptr_t in hex), with no modifiers. */ -static void emit_print (struct emit_buf *b, const char *fmt, ...) { - va_list ap; - va_start (ap, fmt); - while (*fmt != 0) { - int c = *fmt++; - if (c != '%') { - emit_c (b, c); - } else { - c = *fmt++; - if (c == 's') { - const char *s = va_arg (ap, const char *); - while (*s != 0) { - emit_c (b, *s++); - } - } else if (c == 'i') { - uintptr_t n = va_arg (ap, uintptr_t); - int i; - for (i = 0; (n >> i) >= 0x10; i += 4) { - } - for (; i >= 0; i -= 4) { - emit_c (b, "0123456789abcdef"[(n >> i) & 0xf]); - } - } else { - ASSERT (0); - } - } - } - va_end (ap); -} - -/* Map a bit in a uint32_t to a human-readable name. */ -struct bit_name { - uint32_t mask; - const char *name; -}; - -/* names for bits in a mu word */ -static const struct bit_name mu_bit[] = { - { MU_WLOCK, "wlock" }, - { MU_SPINLOCK, "spin" }, - { MU_WAITING, "wait" }, - { MU_DESIG_WAKER, "desig" }, - { MU_CONDITION, "cond" }, - { MU_WRITER_WAITING, "writer" }, - { MU_LONG_WAIT, "long" }, - { MU_ALL_FALSE, "false" }, - { 0, "" } /* sentinel */ -}; - -/* names for bits in a cv word */ -static const struct bit_name cv_bit[] = { - { CV_SPINLOCK, "spin" }, - { CV_NON_EMPTY, "wait" }, - { 0, "" } /* sentinel */ -}; - -/* names for bits in a waiter flags word */ -static const struct bit_name waiter_flags_bit[] = { - { WAITER_RESERVED, "rsrvd" }, - { WAITER_IN_USE, "in_use" }, - { 0, "" } /* sentinel */ -}; - -/* Emit the names of bits in word to buffer *b using names[] */ -static void emit_word (struct emit_buf *b, const struct bit_name *name, uint32_t word) { - int i; - for (i = 0; name[i].mask != 0; i++) { - if ((word & name[i].mask) != 0) { - emit_print (b, " %s", name[i].name); - } - } -} - -/* Emit the waiter queue *q to *b. */ -static void emit_waiters (struct emit_buf *b, nsync_dll_list_ list) { - nsync_dll_element_ *p = nsync_dll_first_ (list); - nsync_dll_element_ *next; - if (p != NULL) { - emit_print (b, "\nwaiters =\n"); - } - for (; p != NULL && !b->overflow; p = next) { - struct nsync_waiter_s *nw = DLL_NSYNC_WAITER (p); - waiter *w = DLL_WAITER (p); - next = NULL; - emit_print (b, " %i", (uintptr_t) w); - if (w->tag != WAITER_TAG) { - emit_print (b, "bad WAITER_TAG %i", - (uintptr_t) w->tag); - } else { - next = nsync_dll_next_ (list, p); - if (nw->tag != NSYNC_WAITER_TAG) { - emit_print (b, " bad WAITER_TAG %i", - (uintptr_t) nw->tag); - } else { - emit_print (b, " embedded=%i waiting=%i", - (uintptr_t) (w->flags & NSYNC_WAITER_FLAG_MUCV), - (uintptr_t) ATM_LOAD (&nw->waiting)); - } - emit_word (b, waiter_flags_bit, w->flags); - emit_print (b, " %s removes=%i cond=(%i %i %i)", - w->l_type == nsync_writer_type_? "writer" : - w->l_type == nsync_reader_type_? "reader" : - "??????", - (uintptr_t) ATM_LOAD (&w->remove_count), - (uintptr_t) w->cond.f, - (uintptr_t) w->cond.v, - (uintptr_t) w->cond.eq); - if (w->same_condition.next != &w->same_condition) { - emit_print (b, " same_as %i", - (uintptr_t) DLL_WAITER_SAMECOND ( - w->same_condition.next)); - } - } - emit_c (b, '\n'); - } -} - -/* Emit to *b the state of *mu, and return a pointer to *b's buffer. - - If blocking!=0, print_waiters!=0, and *mu's waiter list is non-empty, the - call will block until it can acquire the spinlock. - If print_waiters!=0, the waiter list is printed. - The spinlock is released before return if it was acquired. - blocking==0 && print_waiters!=0 is unsafe and is intended for use within - interactive debuggers. */ -static char *emit_mu_state (struct emit_buf *b, nsync_mu *mu, - int blocking, int print_waiters) { - uintptr_t word; - uintptr_t readers; - int acquired = 0; - IGNORE_RACES_START (); - word = ATM_LOAD (&mu->word); - if ((word & MU_WAITING) != 0 && print_waiters && /* can benefit from lock */ - (blocking || (word & MU_SPINLOCK) == 0)) { /* willing, or no need to wait */ - word = nsync_spin_test_and_set_ (&mu->word, MU_SPINLOCK, MU_SPINLOCK, 0); - acquired = 1; - } - readers = word / MU_RLOCK; - emit_print (b, "mu 0x%i -> 0x%i = {", (uintptr_t) mu, word); - emit_word (b, mu_bit, word); - if (readers != 0) { - emit_print (b, " readers=0x%i", readers); - } - emit_print (b, " }"); - if (print_waiters) { - emit_waiters (b, mu->waiters); - } - if (acquired) { - ATM_STORE_REL (&mu->word, word); /* release store */ - } - emit_c (b, 0); - IGNORE_RACES_END (); - return (b->start); -} - -/* Emit to *b the state of *cv, and return a pointer to *b's buffer. - - If blocking!=0, print_waiters!=0, and *cv's waiter list is non-empty, the - call will block until it can acquire the spinlock. - If print_waiters!=0, the waiter list is printed. - The spinlock is released before return if it was acquired. - blocking==0 && print_waiters!=0 is unsafe and is intended for use within - interactive debuggers. */ -static char *emit_cv_state (struct emit_buf *b, nsync_cv *cv, - int blocking, int print_waiters) { - uintptr_t word; - int acquired = 0; - IGNORE_RACES_START (); - word = ATM_LOAD (&cv->word); - if ((word & CV_NON_EMPTY) != 0 && print_waiters && /* can benefit from lock */ - (blocking || (word & CV_SPINLOCK) == 0)) { /* willing, or no need to wait */ - word = nsync_spin_test_and_set_ (&cv->word, CV_SPINLOCK, CV_SPINLOCK, 0); - acquired = 1; - } - emit_print (b, "cv 0x%i -> 0x%i = {", (uintptr_t) cv, word); - emit_word (b, cv_bit, word); - emit_print (b, " }"); - if (print_waiters) { - emit_waiters (b, cv->waiters); - } - if (acquired) { - ATM_STORE_REL (&cv->word, word); /* release store */ - } - emit_c (b, 0); - IGNORE_RACES_END (); - return (b->start); -} - -char *nsync_mu_debug_state (nsync_mu *mu, char *buf, int n) { - struct emit_buf b; - return (emit_mu_state (emit_init (&b, buf, n), mu, 0, 0)); -} - -char *nsync_cv_debug_state (nsync_cv *cv, char *buf, int n) { - struct emit_buf b; - return (emit_cv_state (emit_init (&b, buf, n), cv, 0, 0)); -} - -char *nsync_mu_debug_state_and_waiters (nsync_mu *mu, char *buf, int n) { - struct emit_buf b; - return (emit_mu_state (emit_init (&b, buf, n), mu, 1, 1)); -} - -char *nsync_cv_debug_state_and_waiters (nsync_cv *cv, char *buf, int n) { - struct emit_buf b; - return (emit_cv_state (emit_init (&b, buf, n), cv, 1, 1)); -} - -static char nsync_debug_buf[1024]; - -char *nsync_mu_debugger (nsync_mu *mu) { - struct emit_buf b; - return (emit_mu_state (emit_init (&b, nsync_debug_buf, - (int) sizeof (nsync_debug_buf)), - mu, 0, 1)); -} -char *nsync_cv_debugger (nsync_cv *cv) { - struct emit_buf b; - return (emit_cv_state (emit_init (&b, nsync_debug_buf, - (int) sizeof (nsync_debug_buf)), - cv, 0, 1)); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/dll.c b/vendored/nsync/internal/dll.c deleted file mode 100644 index 29e0458e..00000000 --- a/vendored/nsync/internal/dll.c +++ /dev/null @@ -1,142 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "dll.h" - -NSYNC_CPP_START_ - -/* Initialize *e. */ -void nsync_dll_init_ (nsync_dll_element_ *e, void *container) { - e->next = e; - e->prev = e; - e->container = container; -} - -/* Return whether list is empty. */ -int nsync_dll_is_empty_ (nsync_dll_list_ list) { - return (list == NULL); -} - -/* Remove *e from list, and returns the new list. */ -nsync_dll_list_ nsync_dll_remove_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - if (list == e) { /* removing tail of list */ - if (list->prev == list) { - list = NULL; /* removing only element of list */ - } else { - list = list->prev; - } - } - e->next->prev = e->prev; - e->prev->next = e->next; - e->next = e; - e->prev = e; - return (list); -} - -/* Cause element *n and its successors to come after element *p. - Requires n and p are non-NULL and do not point at elements of the same list. - - Unlike the other operations in this API, this operation acts on - two circular lists of elements, rather than on a "head" location that points - to such a circular list. - - If the two lists are p->p_2nd->p_mid->p_last->p and n->n_2nd->n_mid->n_last->n, - then after nsync_dll_splice_after_ (p, n), the p list would be: - p->n->n_2nd->n_mid->n_last->p_2nd->p_mid->p_last->p. */ -void nsync_dll_splice_after_ (nsync_dll_element_ *p, nsync_dll_element_ *n) { - nsync_dll_element_ *p_2nd = p->next; - nsync_dll_element_ *n_last = n->prev; - p->next = n; /* n follows p */ - n->prev = p; - n_last->next = p_2nd; /* remainder of p-list follows last of n-list */ - p_2nd->prev = n_last; -} - -/* Make element *e the first element of list, and return - the list. The resulting list will have *e as its first element, followed by - any elements in the same list as *e, followed by the elements that were - previously in list. Requires that *e not be in list. If e==NULL, list is - returned unchanged. - - Suppose the e list is e->e_2nd->e_mid->e_last->e. - Recall that a head "list" points to the last element of its list. - If list is initially null, then the outcome is: - result = e_last->e->e_2nd->e_mid->e_last - If list is initially list->list_last->list_1st->list_mid->list_last, - then the outcome is: - result = list_last->e->e_2nd->e_mid->e_last->list_1st->list_mid->list_last - */ -nsync_dll_list_ nsync_dll_make_first_in_list_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - if (e != NULL) { - if (list == NULL) { - list = e->prev; /*e->prev is e_last*/ - } else { - nsync_dll_splice_after_ (list, e); - } - } - return (list); -} - -/* Make element *e the last element of list, and return - the list. The resulting list will have *e as its last element, preceded by - any elements in the same list as *e, preceded by the elements that were - previously in list. Requires that *e not be in list. If e==NULL, list is - returned unchanged. */ -nsync_dll_list_ nsync_dll_make_last_in_list_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - if (e != NULL) { - nsync_dll_make_first_in_list_ (list, e->next); - list = e; - } - return (list); -} - -/* Return a pointer to the first element of list, or NULL if list is empty. */ -nsync_dll_element_ *nsync_dll_first_ (nsync_dll_list_ list) { - nsync_dll_element_ *first = NULL; - if (list != NULL) { - first = list->next; - } - return (first); -} - -/* Return a pointer to the last element of list, or NULL if list is empty. */ -nsync_dll_element_ *nsync_dll_last_ (nsync_dll_list_ list) { - return (list); -} - -/* Return a pointer to the next element of list following *e, - or NULL if there is no such element. */ -nsync_dll_element_ *nsync_dll_next_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - nsync_dll_element_ *next = NULL; - if (e != list) { - next = e->next; - } - return (next); -} - -/* Return a pointer to the previous element of list following *e, - or NULL if there is no such element. */ -nsync_dll_element_ *nsync_dll_prev_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - nsync_dll_element_ *prev = NULL; - if (e != list->next) { - prev = e->prev; - } - return (prev); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/dll.h b/vendored/nsync/internal/dll.h deleted file mode 100644 index d939a11b..00000000 --- a/vendored/nsync/internal/dll.h +++ /dev/null @@ -1,77 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_INTERNAL_DLL_H_ -#define NSYNC_INTERNAL_DLL_H_ - -/* Doubly linked lists. */ - -#include "nsync_cpp.h" -NSYNC_CPP_START_ - -/* A nsync_dll_element_ represents an element of a doubly-linked list of waiters. */ -typedef struct nsync_dll_element_s_ { - struct nsync_dll_element_s_ *next; - struct nsync_dll_element_s_ *prev; - void *container; /* points to the struct this nsync_dll struct is embedded in. */ -} nsync_dll_element_; - -/* A nsync_dll_list_ represents a list of nsync_dll_elements_. */ -typedef nsync_dll_element_ *nsync_dll_list_; /* last elem of circular list; nil => empty; first is x.next. */ - - -/* Initialize *e. */ -void nsync_dll_init_ (nsync_dll_element_ *e, void *container); - -/* Return whether list is empty. */ -int nsync_dll_is_empty_ (nsync_dll_list_ list); - -/* Remove *e from list, and returns the new list. */ -nsync_dll_list_ nsync_dll_remove_ (nsync_dll_list_ list, nsync_dll_element_ *e); - -/* Cause element *n and its successors to come after element *p. - Requires n and p are non-NULL and do not point at elements of the same list. */ -void nsync_dll_splice_after_ (nsync_dll_element_ *p, nsync_dll_element_ *n); - -/* Make element *e the first element of list, and return - the list. The resulting list will have *e as its first element, followed by - any elements in the same list as *e, followed by the elements that were - previously in list. Requires that *e not be in list. If e==NULL, list is - returned unchanged. */ -nsync_dll_list_ nsync_dll_make_first_in_list_ (nsync_dll_list_ list, nsync_dll_element_ *e); - -/* Make element *e the last element of list, and return - the list. The resulting list will have *e as its last element, preceded by - any elements in the same list as *e, preceded by the elements that were - previously in list. Requires that *e not be in list. If e==NULL, list is - returned unchanged. */ -nsync_dll_list_ nsync_dll_make_last_in_list_ (nsync_dll_list_ list, nsync_dll_element_ *e); - -/* Return a pointer to the first element of list, or NULL if list is empty. */ -nsync_dll_element_ *nsync_dll_first_ (nsync_dll_list_ list); - -/* Return a pointer to the last element of list, or NULL if list is empty. */ -nsync_dll_element_ *nsync_dll_last_ (nsync_dll_list_ list); - -/* Return a pointer to the next element of list following *e, - or NULL if there is no such element. */ -nsync_dll_element_ *nsync_dll_next_ (nsync_dll_list_ list, nsync_dll_element_ *e); - -/* Return a pointer to the previous element of list following *e, - or NULL if there is no such element. */ -nsync_dll_element_ *nsync_dll_prev_ (nsync_dll_list_ list, nsync_dll_element_ *e); - -NSYNC_CPP_END_ - -#endif /*NSYNC_INTERNAL_DLL_H_*/ diff --git a/vendored/nsync/internal/headers.h b/vendored/nsync/internal/headers.h deleted file mode 100644 index 7ccca9c4..00000000 --- a/vendored/nsync/internal/headers.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_INTERNAL_HEADERS_H_ -#define NSYNC_INTERNAL_HEADERS_H_ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "atomic.h" -#include "sem.h" - -#endif /*NSYNC_INTERNAL_HEADERS_H_*/ diff --git a/vendored/nsync/internal/mu.c b/vendored/nsync/internal/mu.c deleted file mode 100644 index cd04aea7..00000000 --- a/vendored/nsync/internal/mu.c +++ /dev/null @@ -1,553 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "dll.h" -#include "sem.h" -#include "wait_internal.h" -#include "common.h" -#include "atomic.h" - -NSYNC_CPP_START_ - -/* Initialize *mu. */ -void nsync_mu_init (nsync_mu *mu) { - memset ((void *) mu, 0, sizeof (*mu)); - RWLOCK_CREATE (mu); -} - -/* Release the mutex spinlock. */ -static void mu_release_spinlock (nsync_mu *mu) { - uint32_t old_word = ATM_LOAD (&mu->word); - while (!ATM_CAS_REL (&mu->word, old_word, old_word & ~MU_SPINLOCK)) { - old_word = ATM_LOAD (&mu->word); - } -} - -/* Lock *mu using the specified lock_type, waiting on *w if necessary. - "clear" should be zero if the thread has not previously slept on *mu, and - MU_DESIG_WAKER if it has; this represents bits that nsync_mu_lock_slow_() must clear when - it either acquires or sleeps on *mu. The caller owns *w on return; it is in a valid - state to be returned to the free pool. */ -void nsync_mu_lock_slow_ (nsync_mu *mu, waiter *w, uint32_t clear, lock_type *l_type) { - uint32_t zero_to_acquire; - uint32_t wait_count; - uint32_t long_wait; - unsigned attempts = 0; /* attempt count; used for spinloop backoff */ - w->cv_mu = NULL; /* not a cv wait */ - w->cond.f = NULL; /* Not using a conditional critical section. */ - w->cond.v = NULL; - w->cond.eq = NULL; - w->l_type = l_type; - zero_to_acquire = l_type->zero_to_acquire; - if (clear != 0) { - /* Only the constraints of mutual exclusion should stop a designated waker. */ - zero_to_acquire &= ~(MU_WRITER_WAITING | MU_LONG_WAIT); - } - wait_count = 0; /* number of times we waited, and were woken. */ - long_wait = 0; /* set to MU_LONG_WAIT when wait_count gets large */ - for (;;) { - uint32_t old_word = ATM_LOAD (&mu->word); - if ((old_word & zero_to_acquire) == 0) { - /* lock can be acquired; try to acquire, possibly - clearing MU_DESIG_WAKER and MU_LONG_WAIT. */ - if (ATM_CAS_ACQ (&mu->word, old_word, - (old_word+l_type->add_to_acquire) & - ~(clear|long_wait|l_type->clear_on_acquire))) { - return; - } - } else if ((old_word&MU_SPINLOCK) == 0 && - ATM_CAS_ACQ (&mu->word, old_word, - (old_word|MU_SPINLOCK|long_wait| - l_type->set_when_waiting) & ~(clear | MU_ALL_FALSE))) { - - /* Spinlock is now held, and lock is held by someone - else; MU_WAITING has also been set; queue ourselves. - There's no need to adjust same_condition here, - because w.condition==NULL. */ - ATM_STORE (&w->nw.waiting, 1); - if (wait_count == 0) { - /* first wait goes to end of queue */ - mu->waiters = nsync_dll_make_last_in_list_ (mu->waiters, - &w->nw.q); - } else { - /* subsequent waits go to front of queue */ - mu->waiters = nsync_dll_make_first_in_list_ (mu->waiters, - &w->nw.q); - } - - /* Release spinlock. Cannot use a store here, because - the current thread does not hold the mutex. If - another thread were a designated waker, the mutex - holder could be concurrently unlocking, even though - we hold the spinlock. */ - mu_release_spinlock (mu); - - /* wait until awoken. */ - while (ATM_LOAD_ACQ (&w->nw.waiting) != 0) { /* acquire load */ - nsync_mu_semaphore_p (&w->sem); - } - wait_count++; - /* If the thread has been woken more than this many - times, and still not acquired, it sets the - MU_LONG_WAIT bit to prevent thread that have not - waited from acquiring. This is the starvation - avoidance mechanism. The number is fairly high so - that we continue to benefit from the throughput of - not having running threads wait unless absolutely - necessary. */ - if (wait_count == LONG_WAIT_THRESHOLD) { /* repeatedly woken */ - long_wait = MU_LONG_WAIT; /* force others to wait at least once */ - } - - attempts = 0; - clear = MU_DESIG_WAKER; - /* Threads that have been woken at least once don't care - about waiting writers or long waiters. */ - zero_to_acquire &= ~(MU_WRITER_WAITING | MU_LONG_WAIT); - } - attempts = nsync_spin_delay_ (attempts); - } -} - -/* Attempt to acquire *mu in writer mode without blocking, and return non-zero - iff successful. Return non-zero with high probability if *mu was free on - entry. */ -int nsync_mu_trylock (nsync_mu *mu) { - int result; - IGNORE_RACES_START (); - if (ATM_CAS_ACQ (&mu->word, 0, MU_WADD_TO_ACQUIRE)) { /* acquire CAS */ - result = 1; - } else { - uint32_t old_word = ATM_LOAD (&mu->word); - result = ((old_word & MU_WZERO_TO_ACQUIRE) == 0 && - ATM_CAS_ACQ (&mu->word, old_word, - (old_word + MU_WADD_TO_ACQUIRE) & ~MU_WCLEAR_ON_ACQUIRE)); - } - IGNORE_RACES_END (); - RWLOCK_TRYACQUIRE (result, mu, 1); - return (result); -} - -/* Block until *mu is free and then acquire it in writer mode. */ -void nsync_mu_lock (nsync_mu *mu) { - IGNORE_RACES_START (); - if (!ATM_CAS_ACQ (&mu->word, 0, MU_WADD_TO_ACQUIRE)) { /* acquire CAS */ - uint32_t old_word = ATM_LOAD (&mu->word); - if ((old_word&MU_WZERO_TO_ACQUIRE) != 0 || - !ATM_CAS_ACQ (&mu->word, old_word, - (old_word+MU_WADD_TO_ACQUIRE) & ~MU_WCLEAR_ON_ACQUIRE)) { - waiter *w = nsync_waiter_new_ (); - nsync_mu_lock_slow_ (mu, w, 0, nsync_writer_type_); - nsync_waiter_free_ (w); - } - } - IGNORE_RACES_END (); - RWLOCK_TRYACQUIRE (1, mu, 1); -} - -/* Attempt to acquire *mu in reader mode without blocking, and return non-zero - iff successful. Returns non-zero with high probability if *mu was free on - entry. It may fail to acquire if a writer is waiting, to avoid starvation. - */ -int nsync_mu_rtrylock (nsync_mu *mu) { - int result; - IGNORE_RACES_START (); - if (ATM_CAS_ACQ (&mu->word, 0, MU_RADD_TO_ACQUIRE)) { /* acquire CAS */ - result = 1; - } else { - uint32_t old_word = ATM_LOAD (&mu->word); - result = ((old_word&MU_RZERO_TO_ACQUIRE) == 0 && - ATM_CAS_ACQ (&mu->word, old_word, - (old_word+MU_RADD_TO_ACQUIRE) & ~MU_RCLEAR_ON_ACQUIRE)); - } - IGNORE_RACES_END (); - RWLOCK_TRYACQUIRE (result, mu, 0); - return (result); -} - -/* Block until *mu can be acquired in reader mode and then acquire it. */ -void nsync_mu_rlock (nsync_mu *mu) { - IGNORE_RACES_START (); - if (!ATM_CAS_ACQ (&mu->word, 0, MU_RADD_TO_ACQUIRE)) { /* acquire CAS */ - uint32_t old_word = ATM_LOAD (&mu->word); - if ((old_word&MU_RZERO_TO_ACQUIRE) != 0 || - !ATM_CAS_ACQ (&mu->word, old_word, - (old_word+MU_RADD_TO_ACQUIRE) & ~MU_RCLEAR_ON_ACQUIRE)) { - waiter *w = nsync_waiter_new_ (); - nsync_mu_lock_slow_ (mu, w, 0, nsync_reader_type_); - nsync_waiter_free_ (w); - } - } - IGNORE_RACES_END (); - RWLOCK_TRYACQUIRE (1, mu, 0); -} - -/* Invoke the condition associated with *p, which is an element of - a "waiter" list. */ -static int condition_true (nsync_dll_element_ *p) { - return ((*DLL_WAITER (p)->cond.f) (DLL_WAITER (p)->cond.v)); -} - -/* If *p is an element of waiter_list (a list of "waiter" structs(, return a - pointer to the next element of the list that has a different condition. */ -static nsync_dll_element_ *skip_past_same_condition ( - nsync_dll_list_ waiter_list, nsync_dll_element_ *p) { - nsync_dll_element_ *next; - nsync_dll_element_ *last_with_same_condition = - &DLL_WAITER_SAMECOND (DLL_WAITER (p)->same_condition.prev)->nw.q; - if (last_with_same_condition != p && last_with_same_condition != p->prev) { - /* First in set with same condition, so skip to end. */ - next = nsync_dll_next_ (waiter_list, last_with_same_condition); - } else { - next = nsync_dll_next_ (waiter_list, p); - } - return (next); -} - -/* Merge the same_condition lists of *p and *n if they have the same non-NULL - condition. */ -void nsync_maybe_merge_conditions_ (nsync_dll_element_ *p, nsync_dll_element_ *n) { - if (p != NULL && n != NULL && - WAIT_CONDITION_EQ (&DLL_WAITER (p)->cond, &DLL_WAITER (n)->cond)) { - nsync_dll_splice_after_ (&DLL_WAITER (p)->same_condition, - &DLL_WAITER (n)->same_condition); - } -} - -/* Remove element *e from nsync_mu waiter queue mu_queue, fixing - up the same_condition list by merging the lists on either side if possible. - Also increment the waiter's remove_count. */ -nsync_dll_list_ nsync_remove_from_mu_queue_ (nsync_dll_list_ mu_queue, nsync_dll_element_ *e) { - /* Record previous and next elements in the original queue. */ - nsync_dll_element_ *prev = e->prev; - nsync_dll_element_ *next = e->next; - uint32_t old_value; - /* Remove. */ - mu_queue = nsync_dll_remove_ (mu_queue, e); - do { - old_value = ATM_LOAD (&DLL_WAITER (e)->remove_count); - } while (!ATM_CAS (&DLL_WAITER (e)->remove_count, old_value, old_value+1)); - if (!nsync_dll_is_empty_ (mu_queue)) { - /* Fix up same_condition. */ - nsync_dll_element_ *e_same_condition = &DLL_WAITER (e)->same_condition; - - if (e_same_condition->next != e_same_condition) { - /* *e is linked to a same_condition neighbour---just remove it. */ - e_same_condition->next->prev = e_same_condition->prev; - e_same_condition->prev->next = e_same_condition->next; - e_same_condition->next = e_same_condition; - e_same_condition->prev = e_same_condition; - } else if (prev != nsync_dll_last_ (mu_queue)) { - /* Merge the new neighbours together if we can. */ - nsync_maybe_merge_conditions_ (prev, next); - } - } - return (mu_queue); -} - -/* Unlock *mu and wake one or more waiters as appropriate after an unlock. - It is called with *mu held in mode l_type. */ -void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { - unsigned attempts = 0; /* attempt count; used for backoff */ - for (;;) { - uint32_t old_word = ATM_LOAD (&mu->word); - int testing_conditions = ((old_word & MU_CONDITION) != 0); - uint32_t early_release_mu = l_type->add_to_acquire; - uint32_t late_release_mu = 0; - if (testing_conditions) { - /* Convert to a writer lock, and release later. - - A writer lock is currently needed to test conditions - because exclusive access is needed to the list to - allow modification. The spinlock cannot be used - to achieve that, because an internal lock should not - be held when calling the external predicates. - - We must test conditions even though a reader region - cannot have made any new ones true because some - might have been true before the reader region started. - The MU_ALL_FALSE test below shortcuts the case where - the conditions are known all to be false. */ - early_release_mu = l_type->add_to_acquire - MU_WLOCK; - late_release_mu = MU_WLOCK; - } - if ((old_word&MU_WAITING) == 0 || (old_word&MU_DESIG_WAKER) != 0 || - (old_word & MU_RLOCK_FIELD) > MU_RLOCK || - (old_word & (MU_RLOCK|MU_ALL_FALSE)) == (MU_RLOCK|MU_ALL_FALSE)) { - /* no one to wake, there's a designated waker waking - up, there are still readers, or it's a reader and all waiters - have false conditions */ - if (ATM_CAS_REL (&mu->word, old_word, - (old_word - l_type->add_to_acquire) & - ~l_type->clear_on_uncontended_release)) { - return; - } - } else if ((old_word&MU_SPINLOCK) == 0 && - ATM_CAS_RELACQ (&mu->word, old_word, - (old_word-early_release_mu)|MU_SPINLOCK|MU_DESIG_WAKER)) { - nsync_dll_list_ wake; - lock_type *wake_type; - uint32_t clear_on_release; - uint32_t set_on_release; - /* The spinlock is now held, and we've set the - designated wake flag, since we're likely to wake a - thread that will become that designated waker. If - there are conditions to check, the mutex itself is - still held. */ - - nsync_dll_element_ *p = NULL; - nsync_dll_element_ *next = NULL; - - /* Swap the entire mu->waiters list into the local - "new_waiters" list. This gives us exclusive access - to the list, even if we unlock the spinlock, which - we may do if checking conditions. The loop below - will grab more new waiters that arrived while we - were checking conditions, and terminates only if no - new waiters arrive in one loop iteration. */ - nsync_dll_list_ waiters = NULL; - nsync_dll_list_ new_waiters = mu->waiters; - mu->waiters = NULL; - - /* Remove a waiter from the queue, if possible. */ - wake = NULL; /* waiters to wake. */ - wake_type = NULL; /* type of waiter(s) on wake, or NULL if wake is empty. */ - clear_on_release = MU_SPINLOCK; - set_on_release = MU_ALL_FALSE; - while (!nsync_dll_is_empty_ (new_waiters)) { /* some new waiters to consider */ - p = nsync_dll_first_ (new_waiters); - if (testing_conditions) { - /* Should we continue to test conditions? */ - if (wake_type == nsync_writer_type_) { - /* No, because we're already waking a writer, - and need wake no others.*/ - testing_conditions = 0; - } else if (wake_type == NULL && - DLL_WAITER (p)->l_type != nsync_reader_type_ && - DLL_WAITER (p)->cond.f == NULL) { - /* No, because we've woken no one, but the - first waiter is a writer with no condition, - so we will certainly wake it, and need wake - no others. */ - testing_conditions = 0; - } - } - /* If testing waiters' conditions, release the - spinlock while still holding the write lock. - This is so that the spinlock is not held - while the conditions are evaluated. */ - if (testing_conditions) { - mu_release_spinlock (mu); - } - - /* Process the new waiters picked up in this iteration of the - "while (!nsync_dll_is_empty_ (new_waiters))" loop, - and stop looking when we run out of waiters, or we find - a writer to wake up. */ - while (p != NULL && wake_type != nsync_writer_type_) { - int p_has_condition; - next = nsync_dll_next_ (new_waiters, p); - p_has_condition = (DLL_WAITER (p)->cond.f != NULL); - if (p_has_condition && !testing_conditions) { - nsync_panic_ ("checking a waiter condition " - "while unlocked\n"); - } - if (p_has_condition && !condition_true (p)) { - /* condition is false */ - /* skip to the end of the same_condition group. */ - next = skip_past_same_condition (new_waiters, p); - } else if (wake_type == NULL || - DLL_WAITER (p)->l_type == nsync_reader_type_) { - /* Wake this thread. */ - new_waiters = nsync_remove_from_mu_queue_ ( - new_waiters, p); - wake = nsync_dll_make_last_in_list_ (wake, p); - wake_type = DLL_WAITER (p)->l_type; - } else { - /* Failing to wake a writer - that could acquire if it - were first. */ - set_on_release |= MU_WRITER_WAITING; - set_on_release &= ~MU_ALL_FALSE; - } - p = next; - } - - if (p != NULL) { - /* Didn't search to end of list, so can't be sure - all conditions are false. */ - set_on_release &= ~MU_ALL_FALSE; - } - - /* If testing waiters' conditions, reacquire the spinlock - released above. */ - if (testing_conditions) { - nsync_spin_test_and_set_ (&mu->word, MU_SPINLOCK, - MU_SPINLOCK, 0); - } - - /* add the new_waiters to the last of the waiters. */ - nsync_maybe_merge_conditions_ (nsync_dll_last_ (waiters), - nsync_dll_first_ (new_waiters)); - waiters = nsync_dll_make_last_in_list_ (waiters, - nsync_dll_last_ (new_waiters)); - /* Pick up the next set of new waiters. */ - new_waiters = mu->waiters; - mu->waiters = NULL; - } - - /* Return the local waiter list to *mu. */ - mu->waiters = waiters; - - if (nsync_dll_is_empty_ (wake)) { - /* not waking a waiter => no designated waker */ - clear_on_release |= MU_DESIG_WAKER; - } - - if ((set_on_release & MU_ALL_FALSE) == 0) { - /* If not explicitly setting MU_ALL_FALSE, clear it. */ - clear_on_release |= MU_ALL_FALSE; - } - - if (nsync_dll_is_empty_ (mu->waiters)) { - /* no waiters left */ - clear_on_release |= MU_WAITING | MU_WRITER_WAITING | - MU_CONDITION | MU_ALL_FALSE; - } - - /* Release the spinlock, and possibly the lock if - late_release_mu is non-zero. Other bits are set or - cleared according to whether we woke any threads, - whether any waiters remain, and whether any of them - are writers. */ - old_word = ATM_LOAD (&mu->word); - while (!ATM_CAS_REL (&mu->word, old_word, - ((old_word-late_release_mu)|set_on_release) & - ~clear_on_release)) { /* release CAS */ - old_word = ATM_LOAD (&mu->word); - } - /* Wake the waiters. */ - for (p = nsync_dll_first_ (wake); p != NULL; p = next) { - next = nsync_dll_next_ (wake, p); - wake = nsync_dll_remove_ (wake, p); - ATM_STORE_REL (&DLL_NSYNC_WAITER (p)->waiting, 0); - nsync_mu_semaphore_v (&DLL_WAITER (p)->sem); - } - return; - } - attempts = nsync_spin_delay_ (attempts); - } -} - -/* Unlock *mu, which must be held in write mode, and wake waiters, if appropriate. */ -void nsync_mu_unlock (nsync_mu *mu) { - RWLOCK_RELEASE (mu, 1); - IGNORE_RACES_START (); - /* C is not a garbage-collected language, so we cannot release until we - can be sure that we will not have to touch the mutex again to wake a - waiter. Another thread could acquire, decrement a reference count - and deallocate the mutex before the current thread touched the mutex - word again. */ - if (!ATM_CAS_REL (&mu->word, MU_WLOCK, 0)) { - uint32_t old_word = ATM_LOAD (&mu->word); - /* Clear MU_ALL_FALSE because the critical section we're just - leaving may have made some conditions true. */ - uint32_t new_word = (old_word - MU_WLOCK) & ~MU_ALL_FALSE; - /* Sanity check: mutex must be held in write mode, and there - must be no readers. */ - if ((new_word & (MU_RLOCK_FIELD | MU_WLOCK)) != 0) { - if ((old_word & MU_RLOCK_FIELD) != 0) { - nsync_panic_ ("attempt to nsync_mu_unlock() an nsync_mu " - "held in read mode\n"); - } else { - nsync_panic_ ("attempt to nsync_mu_unlock() an nsync_mu " - "not held in write mode\n"); - } - } else if ((old_word & (MU_WAITING|MU_DESIG_WAKER)) == MU_WAITING || - !ATM_CAS_REL (&mu->word, old_word, new_word)) { - /* There are waiters and no designated waker, or - our initial CAS attempt failed, to use slow path. */ - nsync_mu_unlock_slow_ (mu, nsync_writer_type_); - } - } - IGNORE_RACES_END (); -} - -/* Unlock *mu, which must be held in read mode, and wake waiters, if appropriate. */ -void nsync_mu_runlock (nsync_mu *mu) { - RWLOCK_RELEASE (mu, 0); - IGNORE_RACES_START (); - /* See comment in nsync_mu_unlock(). */ - if (!ATM_CAS_REL (&mu->word, MU_RLOCK, 0)) { - uint32_t old_word = ATM_LOAD (&mu->word); - /* Sanity check: mutex must not be held in write mode and - reader count must not be 0. */ - if (((old_word ^ MU_WLOCK) & (MU_WLOCK | MU_RLOCK_FIELD)) == 0) { - if ((old_word & MU_WLOCK) != 0) { - nsync_panic_ ("attempt to nsync_mu_runlock() an nsync_mu " - "held in write mode\n"); - } else { - nsync_panic_ ("attempt to nsync_mu_runlock() an nsync_mu " - "not held in read mode\n"); - } - } else if ((old_word & (MU_WAITING | MU_DESIG_WAKER)) == MU_WAITING && - (old_word & (MU_RLOCK_FIELD|MU_ALL_FALSE)) == MU_RLOCK) { - /* There are waiters and no designated waker, the last - reader is unlocking, and not all waiters have a - false condition. So we must take the slow path to - attempt to wake a waiter. */ - nsync_mu_unlock_slow_ (mu, nsync_reader_type_); - } else if (!ATM_CAS_REL (&mu->word, old_word, old_word - MU_RLOCK)) { - /* CAS attempt failed, so take slow path. */ - nsync_mu_unlock_slow_ (mu, nsync_reader_type_); - } - } - IGNORE_RACES_END (); -} - -/* Abort if *mu is not held in write mode. */ -void nsync_mu_assert_held (const nsync_mu *mu) { - IGNORE_RACES_START (); - if ((ATM_LOAD (&mu->word) & MU_WHELD_IF_NON_ZERO) == 0) { - nsync_panic_ ("nsync_mu not held in write mode\n"); - } - IGNORE_RACES_END (); -} - -/* Abort if *mu is not held in read or write mode. */ -void nsync_mu_rassert_held (const nsync_mu *mu) { - IGNORE_RACES_START (); - if ((ATM_LOAD (&mu->word) & MU_ANY_LOCK) == 0) { - nsync_panic_ ("nsync_mu not held in some mode\n"); - } - IGNORE_RACES_END (); -} - -/* Return whether *mu is held in read mode. - Requires that *mu is held in some mode. */ -int nsync_mu_is_reader (const nsync_mu *mu) { - uint32_t word; - IGNORE_RACES_START (); - word = ATM_LOAD (&mu->word); - if ((word & MU_ANY_LOCK) == 0) { - nsync_panic_ ("nsync_mu not held in some mode\n"); - } - IGNORE_RACES_END (); - return ((word & MU_WLOCK) == 0); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/mu_wait.c b/vendored/nsync/internal/mu_wait.c deleted file mode 100644 index b03e49b4..00000000 --- a/vendored/nsync/internal/mu_wait.c +++ /dev/null @@ -1,323 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "dll.h" -#include "sem.h" -#include "wait_internal.h" -#include "common.h" -#include "atomic.h" - -NSYNC_CPP_START_ - -/* Attempt to remove waiter *w from *mu's - waiter queue. If successful, leave the lock held in mode *l_type, and - return non-zero; otherwise return zero. Requires that the current thread - hold neither *mu nor its spinlock, that remove_count be the value of - w.remove_count when *w was inserted into the queue (which it will still be if - it has not been removed). - - This is a tricky part of the design. Here is the rationale. - - When a condition times out or is cancelled, we must "turn off" the - condition, making it always true, so the lock will be acquired in the normal - way. The naive approach would be to set a field atomically to tell future - waiters to ignore the condition. Unfortunately, that would violate the - same_condition list invariants, and the same_condition optimization is - probably worth keeping. - - To fixup the same_condition list, we must have mutual exclusion with the loop - in nsync_mu_unlock_slow_() that is examining waiters, evaluating their conditions, and - removing them from the queue. That loop uses both the spinlock (to allow - queue changes), and the mutex itself (to allow condition evaluation). - Therefore, to "turn off" the condition requires acquiring both the spinlock - and the mutex. This has two consequences: - - If we must acquire *mu to "turn off" the condition, we might as well give - the lock to this waiter and return from nsync_cv_wait_with_deadline() after we've - done so. It would be wasted work to put it back on the waiter queue, and - have it wake up and acquire yet again. (There are possibilities for - starvation here that we ignore, under the assumption that the client - avoids timeouts that are extremely short relative to the durations of his - section durations.) - - We can't use *w to wait for the lock to be free, because *w is already on - the waiter queue with the wrong condition; we now want to wait with no - condition. So either we must spin to acquire the lock, or we must - allocate _another_ waiter object. The latter option is feasible, but - delicate: the thread would have two waiter objects, and would have to - handle being woken by either one or both, and possibly removing one that - was not awoken. For the moment, we spin, because it's easier, and seems - not to cause problems in practice, since the spinloop backs off - aggressively. */ -static int mu_try_acquire_after_timeout_or_cancel (nsync_mu *mu, lock_type *l_type, - waiter *w, uint32_t remove_count) { - int success = 0; - unsigned spin_attempts = 0; - uint32_t old_word = ATM_LOAD (&mu->word); - /* Spin until we can acquire the spinlock and a writer lock on *mu. */ - while ((old_word&(MU_WZERO_TO_ACQUIRE|MU_SPINLOCK)) != 0 || - !ATM_CAS_ACQ (&mu->word, old_word, - (old_word+MU_WADD_TO_ACQUIRE+MU_SPINLOCK) & - ~MU_WCLEAR_ON_ACQUIRE)) { - /* Failed to acquire. If we can, set the MU_WRITER_WAITING bit - to avoid being starved by readers. */ - if ((old_word & (MU_WRITER_WAITING | MU_SPINLOCK)) == 0) { - /* If the following CAS succeeds, it effectively - acquires and releases the spinlock atomically, so - must be both an acquire and release barrier. - MU_WRITER_WAITING will be cleared via - MU_WCLEAR_ON_ACQUIRE when this loop succeeds. - An optimization; failures are ignored. */ - ATM_CAS_RELACQ (&mu->word, old_word, - old_word|MU_WRITER_WAITING); - } - spin_attempts = nsync_spin_delay_ (spin_attempts); - old_word = ATM_LOAD (&mu->word); - } - /* Check that w wasn't removed from the queue after our caller checked, - but before we acquired the spinlock. - The check of remove_count confirms that the waiter *w is still - governed by *mu's spinlock. Otherwise, some other thread may be - about to set w.waiting==0. */ - if (ATM_LOAD (&w->nw.waiting) != 0 && remove_count == ATM_LOAD (&w->remove_count)) { - /* This thread's condition is now irrelevant, and it - holds a writer lock. Remove it from the queue, - and possibly convert back to a reader lock. */ - mu->waiters = nsync_remove_from_mu_queue_ (mu->waiters, &w->nw.q); - ATM_STORE (&w->nw.waiting, 0); - - /* Release spinlock but keep desired lock type. */ - ATM_STORE_REL (&mu->word, old_word+l_type->add_to_acquire); /* release store */ - success = 1; - } else { - /* Release spinlock and *mu. */ - ATM_STORE_REL (&mu->word, old_word); /* release store */ - } - RWLOCK_TRYACQUIRE (success, mu, l_type == nsync_writer_type_); - return (success); -} - -/* Return when at least one of: the condition is true, the - deadline expires, or cancel_note is notified. It may unlock and relock *mu - while blocked waiting for one of these events, but always returns with *mu - held. It returns 0 iff the condition is true on return, and otherwise - either ETIMEDOUT or ECANCELED, depending on why the call returned early. Use - abs_deadline==nsync_time_no_deadline for no deadline, and cancel_note==NULL for no - cancellation. - - Requires that *mu be held on entry. - Requires that condition.eval() neither modify state protected by *mu, nor - return a value dependent on state not protected by *mu. To depend on time, - use the abs_deadline parameter. - (Conventional use of condition variables have the same restrictions on the - conditions tested by the while-loop.) - The implementation calls condition.eval() only with *mu held, though not - always from the calling thread, and may elect to hold only a read lock - during the call, even if the client is attempting to acquire only write - locks. - - The nsync_mu_wait() and nsync_mu_wait_with_deadline() calls can be used instead of condition - variables. In many straightforward situations they are of equivalent - performance and are somewhat easier to use, because unlike condition - variables, they do not require that the waits be placed in a loop, and they - do not require explicit wakeup calls. In the current implementation, use of - nsync_mu_wait() and nsync_mu_wait_with_deadline() can take longer if many distinct - wait conditions are used. In such cases, use an explicit condition variable - per wakeup condition for best performance. */ -int nsync_mu_wait_with_deadline (nsync_mu *mu, - int (*condition) (const void *condition_arg), - const void *condition_arg, - int (*condition_arg_eq) (const void *a, const void *b), - nsync_time abs_deadline, nsync_note cancel_note) { - lock_type *l_type; - int first_wait; - int condition_is_true; - waiter *w; - int outcome; - /* Work out in which mode the lock is held. */ - uint32_t old_word; - IGNORE_RACES_START (); - old_word = ATM_LOAD (&mu->word); - if ((old_word & MU_ANY_LOCK) == 0) { - nsync_panic_ ("nsync_mu not held in some mode when calling " - "nsync_mu_wait_with_deadline()\n"); - } - l_type = nsync_writer_type_; - if ((old_word & MU_RHELD_IF_NON_ZERO) != 0) { - l_type = nsync_reader_type_; - } - - first_wait = 1; /* first time through the loop below. */ - condition_is_true = (condition == NULL || (*condition) (condition_arg)); - - /* Loop until either the condition becomes true, or "outcome" indicates - cancellation or timeout. */ - w = NULL; - outcome = 0; - while (outcome == 0 && !condition_is_true) { - uint32_t has_condition; - uint32_t remove_count; - uint32_t add_to_acquire; - int had_waiters; - int sem_outcome; - unsigned attempts; - int have_lock; - if (w == NULL) { - w = nsync_waiter_new_ (); /* get a waiter struct if we need one. */ - } - - /* Prepare to wait. */ - w->cv_mu = NULL; /* not a condition variable wait */ - w->l_type = l_type; - w->cond.f = condition; - w->cond.v = condition_arg; - w->cond.eq = condition_arg_eq; - has_condition = 0; /* set to MU_CONDITION if condition is non-NULL */ - if (condition != NULL) { - has_condition = MU_CONDITION; - } - ATM_STORE (&w->nw.waiting, 1); - remove_count = ATM_LOAD (&w->remove_count); - - /* Acquire spinlock. */ - old_word = nsync_spin_test_and_set_ (&mu->word, MU_SPINLOCK, - MU_SPINLOCK|MU_WAITING|has_condition, MU_ALL_FALSE); - had_waiters = ((old_word & (MU_DESIG_WAKER | MU_WAITING)) == MU_WAITING); - /* Queue the waiter. */ - if (first_wait) { - nsync_maybe_merge_conditions_ (nsync_dll_last_ (mu->waiters), - &w->nw.q); - /* first wait goes to end of queue */ - mu->waiters = nsync_dll_make_last_in_list_ (mu->waiters, - &w->nw.q); - first_wait = 0; - } else { - nsync_maybe_merge_conditions_ (&w->nw.q, - nsync_dll_first_ (mu->waiters)); - /* subsequent waits go to front of queue */ - mu->waiters = nsync_dll_make_first_in_list_ (mu->waiters, - &w->nw.q); - } - /* Release spinlock and *mu. */ - RWLOCK_RELEASE (mu, l_type == nsync_writer_type_); - do { - old_word = ATM_LOAD (&mu->word); - add_to_acquire = l_type->add_to_acquire; - if (((old_word-l_type->add_to_acquire)&MU_ANY_LOCK) == 0 && had_waiters) { - add_to_acquire = 0; /* release happens in nsync_mu_unlock_slow_ */ - } - } while (!ATM_CAS_REL (&mu->word, old_word, - (old_word - add_to_acquire) & ~MU_SPINLOCK)); - if (add_to_acquire == 0) { - /* The lock will be fully released, there are waiters, and - no designated waker, so wake waiters. */ - nsync_mu_unlock_slow_ (mu, l_type); - } - - /* wait until awoken or a timeout. */ - sem_outcome = 0; - attempts = 0; - have_lock = 0; - while (ATM_LOAD_ACQ (&w->nw.waiting) != 0) { /* acquire load */ - if (sem_outcome == 0) { - sem_outcome = nsync_sem_wait_with_cancel_ (w, abs_deadline, - cancel_note); - if (sem_outcome != 0 && ATM_LOAD (&w->nw.waiting) != 0) { - /* A timeout or cancellation occurred, and no wakeup. - Acquire the spinlock and mu, and confirm. */ - have_lock = mu_try_acquire_after_timeout_or_cancel ( - mu, l_type, w, remove_count); - if (have_lock) { /* Successful acquire. */ - outcome = sem_outcome; - } - } - } - - if (ATM_LOAD (&w->nw.waiting) != 0) { - attempts = nsync_spin_delay_ (attempts); /* will ultimately yield */ - } - } - - if (!have_lock) { - /* If we didn't reacquire due to a cancellation/timeout, acquire now. */ - nsync_mu_lock_slow_ (mu, w, MU_DESIG_WAKER, l_type); - RWLOCK_TRYACQUIRE (1, mu, l_type == nsync_writer_type_); - } - condition_is_true = (condition == NULL || (*condition) (condition_arg)); - } - if (w != NULL) { - nsync_waiter_free_ (w); /* free waiter if we allocated one. */ - } - if (condition_is_true) { - outcome = 0; /* condition is true trumps other outcomes. */ - } - IGNORE_RACES_END (); - return (outcome); -} - -/* Return when the condition is true. Perhaps unlock and relock *mu - while blocked waiting for the condition to become true. It is equivalent to - a call to nsync_mu_wait_with_deadline() with abs_deadline==nsync_time_no_deadline, and - cancel_note==NULL. - - Requires that *mu be held on entry. - Calls condition.eval() only with *mu held, though not always from the - calling thread. - See wait_with_deadline() for the restrictions on condition and performance - considerations. */ -void nsync_mu_wait (nsync_mu *mu, int (*condition) (const void *condition_arg), - const void *condition_arg, - int (*condition_arg_eq) (const void *a, const void *b)) { - if (nsync_mu_wait_with_deadline (mu, condition, condition_arg, condition_arg_eq, - nsync_time_no_deadline, NULL) != 0) { - nsync_panic_ ("nsync_mu_wait woke but condition not true\n"); - } -} - -/* Unlock *mu, which must be held in write mode, and wake waiters, if - appropriate. Unlike nsync_mu_unlock(), this call is not required to wake - nsync_mu_wait/nsync_mu_wait_with_deadline calls on conditions that were - false before this thread acquired the lock. This call should be used only - at the end of critical sections for which: - - nsync_mu_wait/nsync_mu_wait_with_deadline are in use on the same mutex, - - this critical section cannot make the condition true for any of those - nsync_mu_wait/nsync_mu_wait_with_deadline waits, and - - when performance is significantly improved by doing so. */ -void nsync_mu_unlock_without_wakeup (nsync_mu *mu) { - RWLOCK_RELEASE (mu, 1); - IGNORE_RACES_START (); - /* See comment in nsync_mu_unlock(). */ - if (!ATM_CAS_REL (&mu->word, MU_WLOCK, 0)) { - uint32_t old_word = ATM_LOAD (&mu->word); - uint32_t new_word = old_word - MU_WLOCK; - if ((new_word & (MU_RLOCK_FIELD | MU_WLOCK)) != 0) { - if ((old_word & MU_RLOCK_FIELD) != 0) { - nsync_panic_ ("attempt to nsync_mu_unlock() an nsync_mu " - "held in read mode\n"); - } else { - nsync_panic_ ("attempt to nsync_mu_unlock() an nsync_mu " - "not held in write mode\n"); - } - } else if ((old_word & (MU_WAITING | MU_DESIG_WAKER | MU_ALL_FALSE)) == - MU_WAITING || !ATM_CAS_REL (&mu->word, old_word, new_word)) { - nsync_mu_unlock_slow_ (mu, nsync_writer_type_); - } - } - IGNORE_RACES_END (); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/note.c b/vendored/nsync/internal/note.c deleted file mode 100644 index 6e526a4a..00000000 --- a/vendored/nsync/internal/note.c +++ /dev/null @@ -1,302 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "dll.h" -#include "sem.h" -#include "wait_internal.h" -#include "common.h" -#include "atomic.h" - -NSYNC_CPP_START_ - -/* Locking discipline for the nsync_note implementation: - - Each nsync_note has a lock "note_mu" which protects the "parent" pointer, - "waiters" list, and "disconnecting" count. It also protects the "children" - list; thus each node's "parent_child_link", which links together the - children of a single parent, is protected by the parent's "note_mu". - - To connect a parent to a child, or to disconnect one, the parent's lock must - be held to manipulate its child list, and the child's lock must be held to - change the parent pointer, so both must be held simultaneously. - The locking order is "parent before child". - - Operations like notify and free are given a node pointer n and must - disconnect *n from its parent n->parent. The call must hold n->note_mu to - read n->parent, but need to release n->note_mu to acquire - n->parent->note_mu. The parent could be disconnected and freed while - n->note_mu is not held. The n->disconnecting count handles this; the - operation acquires n->note_mu, increments n->disconnecting, and can then - release n->note_mu, and acquire n->parent->note_mu and n->note_mu is the - correct order. n->disconnecting!=0 indicates that a thread is already in - the processes of disconnecting n from n->parent. A thread freeing or - notifying the parent should not perform the disconnection of that child, but - should instead wait for the "children" list to become empty via - WAIT_FOR_NO_CHILDREN(). WAKEUP_NO_CHILDREN() should be used whenever this - condition could become true. */ - -/* Set the expiry time in *n to t */ -static void set_expiry_time (nsync_note n, nsync_time t) { - n->expiry_time = t; - n->expiry_time_valid = 1; -} - -/* Return a pointer to the note containing nsync_dll_element_ *e. */ -#define DLL_NOTE(e) ((nsync_note)((e)->container)) - -/* Return whether n->children is empty. Assumes n->note_mu held. */ -static int no_children (const void *v) { - return (nsync_dll_is_empty_ (((nsync_note)v)->children)); -} - -#define WAIT_FOR_NO_CHILDREN(pred_, n_) nsync_mu_wait (&(n_)->note_mu, &pred_, (n_), NULL) -#define WAKEUP_NO_CHILDREN(n_) do { } while (0) - -/* -// These lines can be used in place of those above if conditional critical -// sections have been removed from the source. -#define WAIT_FOR_NO_CHILDREN(pred_, n_) do { \ - while (!pred_ (n_)) { nsync_cv_wait (&(n_)->no_children_cv, &(n_)->note_mu); } \ - } while (0) -#define WAKEUP_NO_CHILDREN(n_) nsync_cv_broadcast (&(n_)->no_children_cv) -*/ - -/* Notify *n and all its descendants that are not already disconnnecting. - n->note_mu is held. May release and reacquire n->note_mu. - parent->note_mu is held if parent != NULL. */ -static void note_notify_child (nsync_note n, nsync_note parent) { - nsync_time t; - t = NOTIFIED_TIME (n); - if (nsync_time_cmp (t, nsync_time_zero) > 0) { - nsync_dll_element_ *p; - nsync_dll_element_ *next; - ATM_STORE_REL (&n->notified, 1); - while ((p = nsync_dll_first_ (n->waiters)) != NULL) { - struct nsync_waiter_s *nw = DLL_NSYNC_WAITER (p); - n->waiters = nsync_dll_remove_ (n->waiters, p); - ATM_STORE_REL (&nw->waiting, 0); - nsync_mu_semaphore_v (nw->sem); - } - for (p = nsync_dll_first_ (n->children); p != NULL; p = next) { - nsync_note child = DLL_NOTE (p); - next = nsync_dll_next_ (n->children, p); - nsync_mu_lock (&child->note_mu); - if (child->disconnecting == 0) { - note_notify_child (child, n); - } - nsync_mu_unlock (&child->note_mu); - } - WAIT_FOR_NO_CHILDREN (no_children, n); - if (parent != NULL) { - parent->children = nsync_dll_remove_ (parent->children, - &n->parent_child_link); - WAKEUP_NO_CHILDREN (parent); - n->parent = NULL; - } - } -} - -/* Notify *n and all its descendants that are not already disconnnecting. - No locks are held. */ -static void notify (nsync_note n) { - nsync_time t; - nsync_mu_lock (&n->note_mu); - t = NOTIFIED_TIME (n); - if (nsync_time_cmp (t, nsync_time_zero) > 0) { - nsync_note parent; - n->disconnecting++; - parent = n->parent; - if (parent != NULL && !nsync_mu_trylock (&parent->note_mu)) { - nsync_mu_unlock (&n->note_mu); - nsync_mu_lock (&parent->note_mu); - nsync_mu_lock (&n->note_mu); - } - note_notify_child (n, parent); - if (parent != NULL) { - nsync_mu_unlock (&parent->note_mu); - } - n->disconnecting--; - } - nsync_mu_unlock (&n->note_mu); -} - -/* Return the deadline by which *n is certain to be notified, - setting it to zero if it already has passed that time. - Requires n->note_mu not held on entry. - - Not static; used in sem_wait.c */ -nsync_time nsync_note_notified_deadline_ (nsync_note n) { - nsync_time ntime; - if (ATM_LOAD_ACQ (&n->notified) != 0) { - ntime = nsync_time_zero; - } else { - nsync_mu_lock (&n->note_mu); - ntime = NOTIFIED_TIME (n); - nsync_mu_unlock (&n->note_mu); - if (nsync_time_cmp (ntime, nsync_time_zero) > 0) { - if (nsync_time_cmp (ntime, nsync_time_now ()) <= 0) { - notify (n); - ntime = nsync_time_zero; - } - } - } - return (ntime); -} - -int nsync_note_is_notified (nsync_note n) { - int result; - IGNORE_RACES_START (); - result = (nsync_time_cmp (nsync_note_notified_deadline_ (n), nsync_time_zero) <= 0); - IGNORE_RACES_END (); - return (result); -} - -nsync_note nsync_note_new (nsync_note parent, - nsync_time abs_deadline) { - nsync_note n = (nsync_note) malloc (sizeof (*n)); - if (n != NULL) { - memset ((void *) n, 0, sizeof (*n)); - nsync_dll_init_ (&n->parent_child_link, n); - set_expiry_time (n, abs_deadline); - if (!nsync_note_is_notified (n) && parent != NULL) { - nsync_time parent_time; - nsync_mu_lock (&parent->note_mu); - parent_time = NOTIFIED_TIME (parent); - if (nsync_time_cmp (parent_time, abs_deadline) < 0) { - set_expiry_time (n, parent_time); - } - if (nsync_time_cmp (parent_time, nsync_time_zero) > 0) { - n->parent = parent; - parent->children = nsync_dll_make_last_in_list_ (parent->children, - &n->parent_child_link); - } - nsync_mu_unlock (&parent->note_mu); - } - } - return (n); -} - -void nsync_note_free (nsync_note n) { - nsync_note parent; - nsync_dll_element_ *p; - nsync_dll_element_ *next; - nsync_mu_lock (&n->note_mu); - n->disconnecting++; - ASSERT (nsync_dll_is_empty_ (n->waiters)); - parent = n->parent; - if (parent != NULL && !nsync_mu_trylock (&parent->note_mu)) { - nsync_mu_unlock (&n->note_mu); - nsync_mu_lock (&parent->note_mu); - nsync_mu_lock (&n->note_mu); - } - for (p = nsync_dll_first_ (n->children); p != NULL; p = next) { - nsync_note child = DLL_NOTE (p); - next = nsync_dll_next_ (n->children, p); - nsync_mu_lock (&child->note_mu); - if (child->disconnecting == 0) { - n->children = nsync_dll_remove_ (n->children, - &child->parent_child_link); - if (parent != NULL) { - child->parent = parent; - parent->children = nsync_dll_make_last_in_list_ ( - parent->children, &child->parent_child_link); - } else { - child->parent = NULL; - } - } - nsync_mu_unlock (&child->note_mu); - } - WAIT_FOR_NO_CHILDREN (no_children, n); - if (parent != NULL) { - parent->children = nsync_dll_remove_ (parent->children, - &n->parent_child_link); - WAKEUP_NO_CHILDREN (parent); - n->parent = NULL; - nsync_mu_unlock (&parent->note_mu); - } - n->disconnecting--; - nsync_mu_unlock (&n->note_mu); - free (n); -} - -void nsync_note_notify (nsync_note n) { - IGNORE_RACES_START (); - if (nsync_time_cmp (nsync_note_notified_deadline_ (n), nsync_time_zero) > 0) { - notify (n); - } - IGNORE_RACES_END (); -} - -int nsync_note_wait (nsync_note n, nsync_time abs_deadline) { - struct nsync_waitable_s waitable; - struct nsync_waitable_s *pwaitable = &waitable; - waitable.v = n; - waitable.funcs = &nsync_note_waitable_funcs; - return (nsync_wait_n (NULL, NULL, NULL, abs_deadline, 1, &pwaitable) == 0); -} - -nsync_time nsync_note_expiry (nsync_note n) { - return (n->expiry_time); -} - -static nsync_time note_ready_time (void *v, struct nsync_waiter_s *nw UNUSED) { - return (nsync_note_notified_deadline_ ((nsync_note)v)); -} - -static int note_enqueue (void *v, struct nsync_waiter_s *nw) { - int waiting = 0; - nsync_note n = (nsync_note) v; - nsync_time ntime; - nsync_mu_lock (&n->note_mu); - ntime = NOTIFIED_TIME (n); - if (nsync_time_cmp (ntime, nsync_time_zero) > 0) { - n->waiters = nsync_dll_make_last_in_list_ (n->waiters, &nw->q); - ATM_STORE (&nw->waiting, 1); - waiting = 1; - } else { - ATM_STORE (&nw->waiting, 0); - waiting = 0; - } - nsync_mu_unlock (&n->note_mu); - return (waiting); -} - -static int note_dequeue (void *v, struct nsync_waiter_s *nw) { - int was_queued = 0; - nsync_note n = (nsync_note) v; - nsync_time ntime; - nsync_note_notified_deadline_ (n); - nsync_mu_lock (&n->note_mu); - ntime = NOTIFIED_TIME (n); - if (nsync_time_cmp (ntime, nsync_time_zero) > 0) { - n->waiters = nsync_dll_remove_ (n->waiters, &nw->q); - ATM_STORE (&nw->waiting, 0); - was_queued = 1; - } - nsync_mu_unlock (&n->note_mu); - return (was_queued); -} - -const struct nsync_waitable_funcs_s nsync_note_waitable_funcs = { - ¬e_ready_time, - ¬e_enqueue, - ¬e_dequeue -}; - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/once.c b/vendored/nsync/internal/once.c deleted file mode 100644 index d8c6053e..00000000 --- a/vendored/nsync/internal/once.c +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "dll.h" -#include "sem.h" -#include "wait_internal.h" -#include "common.h" -#include "atomic.h" - -NSYNC_CPP_START_ - -/* An once_sync_s struct contains a lock, and a condition variable on which - threads may wait for an nsync_once to be initialized by another thread. - - A separate struct is used only to keep nsync_once small. - - A given nsync_once can be associated with any once_sync_s struct, but cannot - be associated with more than one. nsync_once instances are mapped to - once_sync_s instances by a trivial hashing scheme implemented by - NSYNC_ONCE_SYNC_(). - - The number of once_sync_s structs in the following array is greater than one - only to reduce the probability of contention if a great many distinct - nsync_once variables are initialized concurrently. */ -static struct once_sync_s { - nsync_mu once_mu; - nsync_cv once_cv; -} once_sync[64]; - -/* Return a pointer to the once_sync_s struct associated with the nsync_once *p. */ -#define NSYNC_ONCE_SYNC_(p) &once_sync[(((uintptr_t) (p)) / sizeof (*(p))) % \ - (sizeof (once_sync) / sizeof (once_sync[0]))] - -/* Implement nsync_run_once, nsync_run_once_arg, nsync_run_once_spin, or - nsync_run_once_arg_spin, chosen as described below. - - If s!=NULL, s is required to point to the once_sync_s associated with *once, - and the semantics of nsync_run_once or nsync_run_once_arg are provided. - If s==NULL, the semantics of nsync_run_once_spin, or nsync_run_once_arg_spin - are provided. - - If f!=NULL, the semantics of nsync_run_once or nsync_run_once_spin are - provided. Otherwise, farg is required to be non-NULL, and the semantics of - nsync_run_once_arg or nsync_run_once_arg_spin are provided. */ -static void nsync_run_once_impl (nsync_once *once, struct once_sync_s *s, - void (*f) (void), void (*farg) (void *arg), void *arg) { - uint32_t o = ATM_LOAD_ACQ (once); - if (o != 2) { - unsigned attempts = 0; - if (s != NULL) { - nsync_mu_lock (&s->once_mu); - } - while (o == 0 && !ATM_CAS_ACQ (once, 0, 1)) { - o = ATM_LOAD (once); - } - if (o == 0) { - if (s != NULL) { - nsync_mu_unlock (&s->once_mu); - } - if (f != NULL) { - (*f) (); - } else { - (*farg) (arg); - } - if (s != NULL) { - nsync_mu_lock (&s->once_mu); - nsync_cv_broadcast (&s->once_cv); - } - ATM_STORE_REL (once, 2); - } - while (ATM_LOAD_ACQ (once) != 2) { - if (s != NULL) { - nsync_time deadline; - if (attempts < 50) { - attempts += 10; - } - deadline = nsync_time_add (nsync_time_now (), nsync_time_ms (attempts)); - nsync_cv_wait_with_deadline (&s->once_cv, &s->once_mu, deadline, NULL); - } else { - attempts = nsync_spin_delay_ (attempts); - } - } - if (s != NULL) { - nsync_mu_unlock (&s->once_mu); - } - } -} - -void nsync_run_once (nsync_once *once, void (*f) (void)) { - uint32_t o; - IGNORE_RACES_START (); - o = ATM_LOAD_ACQ (once); - if (o != 2) { - struct once_sync_s *s = NSYNC_ONCE_SYNC_ (once); - nsync_run_once_impl (once, s, f, NULL, NULL); - } - IGNORE_RACES_END (); -} - -void nsync_run_once_arg (nsync_once *once, void (*farg) (void *arg), void *arg) { - uint32_t o; - IGNORE_RACES_START (); - o = ATM_LOAD_ACQ (once); - if (o != 2) { - struct once_sync_s *s = NSYNC_ONCE_SYNC_ (once); - nsync_run_once_impl (once, s, NULL, farg, arg); - } - IGNORE_RACES_END (); -} - -void nsync_run_once_spin (nsync_once *once, void (*f) (void)) { - uint32_t o; - IGNORE_RACES_START (); - o = ATM_LOAD_ACQ (once); - if (o != 2) { - nsync_run_once_impl (once, NULL, f, NULL, NULL); - } - IGNORE_RACES_END (); -} - -void nsync_run_once_arg_spin (nsync_once *once, void (*farg) (void *arg), void *arg) { - uint32_t o; - IGNORE_RACES_START (); - o = ATM_LOAD_ACQ (once); - if (o != 2) { - nsync_run_once_impl (once, NULL, NULL, farg, arg); - } - IGNORE_RACES_END (); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/sem.h b/vendored/nsync/internal/sem.h deleted file mode 100644 index b58ce961..00000000 --- a/vendored/nsync/internal/sem.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_INTERNAL_SEM_H_ -#define NSYNC_INTERNAL_SEM_H_ - -/* A semaphore. - It may be counting or binary, and it need have no destructor. */ - -#include "nsync_cpp.h" - -NSYNC_CPP_START_ - -typedef struct nsync_semaphore_s_ { - void *sem_space[32]; /* space used by implementation */ -} nsync_semaphore; - -/* Initialize *s; the initial value is 0. */ -void nsync_mu_semaphore_init (nsync_semaphore *s); - -/* Wait until the count of *s exceeds 0, and decrement it. */ -void nsync_mu_semaphore_p (nsync_semaphore *s); - -/* Wait until one of: - the count of *s is non-zero, in which case decrement *s and return 0; - or abs_deadline expires, in which case return ETIMEDOUT. */ -int nsync_mu_semaphore_p_with_deadline (nsync_semaphore *s, nsync_time abs_deadline); - -/* Ensure that the count of *s is at least 1. */ -void nsync_mu_semaphore_v (nsync_semaphore *s); - -NSYNC_CPP_END_ - -#endif /*NSYNC_INTERNAL_SEM_H_*/ diff --git a/vendored/nsync/internal/sem_wait.c b/vendored/nsync/internal/sem_wait.c deleted file mode 100644 index 47b98873..00000000 --- a/vendored/nsync/internal/sem_wait.c +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "dll.h" -#include "sem.h" -#include "wait_internal.h" -#include "common.h" -#include "atomic.h" - -NSYNC_CPP_START_ - -/* Wait until one of: - w->sem is non-zero----decrement it and return 0. - abs_deadline expires---return ETIMEDOUT. - cancel_note is non-NULL and *cancel_note becomes notified---return ECANCELED. */ -int nsync_sem_wait_with_cancel_ (waiter *w, nsync_time abs_deadline, - nsync_note cancel_note) { - int sem_outcome; - if (cancel_note == NULL) { - sem_outcome = nsync_mu_semaphore_p_with_deadline (&w->sem, abs_deadline); - } else { - nsync_time cancel_time; - cancel_time = nsync_note_notified_deadline_ (cancel_note); - sem_outcome = ECANCELED; - if (nsync_time_cmp (cancel_time, nsync_time_zero) > 0) { - struct nsync_waiter_s nw; - nw.tag = NSYNC_WAITER_TAG; - nw.sem = &w->sem; - nsync_dll_init_ (&nw.q, &nw); - ATM_STORE (&nw.waiting, 1); - nw.flags = 0; - nsync_mu_lock (&cancel_note->note_mu); - cancel_time = NOTIFIED_TIME (cancel_note); - if (nsync_time_cmp (cancel_time, nsync_time_zero) > 0) { - nsync_time local_abs_deadline; - int deadline_is_nearer = 0; - cancel_note->waiters = nsync_dll_make_last_in_list_ ( - cancel_note->waiters, &nw.q); - local_abs_deadline = cancel_time; - if (nsync_time_cmp (abs_deadline, cancel_time) < 0) { - local_abs_deadline = abs_deadline; - deadline_is_nearer = 1; - } - nsync_mu_unlock (&cancel_note->note_mu); - sem_outcome = nsync_mu_semaphore_p_with_deadline (&w->sem, - local_abs_deadline); - if (sem_outcome == ETIMEDOUT && !deadline_is_nearer) { - sem_outcome = ECANCELED; - nsync_note_notify (cancel_note); - } - nsync_mu_lock (&cancel_note->note_mu); - cancel_time = NOTIFIED_TIME (cancel_note); - if (nsync_time_cmp (cancel_time, - nsync_time_zero) > 0) { - cancel_note->waiters = nsync_dll_remove_ ( - cancel_note->waiters, &nw.q); - } - } - nsync_mu_unlock (&cancel_note->note_mu); - } - } - return (sem_outcome); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/sem_wait_no_note.c b/vendored/nsync/internal/sem_wait_no_note.c deleted file mode 100644 index 5f925785..00000000 --- a/vendored/nsync/internal/sem_wait_no_note.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "dll.h" -#include "sem.h" -#include "wait_internal.h" -#include "common.h" -#include "atomic.h" - -NSYNC_CPP_START_ - -/* Wait until one of: - w->sem is non-zero----decrement it and return 0. - abs_deadline expires---return ETIMEDOUT. - Ignores cancel_note. */ -int nsync_sem_wait_with_cancel_ (waiter *w, nsync_time abs_deadline, nsync_note cancel_note UNUSED) { - return (nsync_mu_semaphore_p_with_deadline (&w->sem, abs_deadline)); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/time_internal.c b/vendored/nsync/internal/time_internal.c deleted file mode 100644 index 7328665c..00000000 --- a/vendored/nsync/internal/time_internal.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync_time.h" - -NSYNC_CPP_START_ - -nsync_time nsync_time_ms (unsigned ms) { - unsigned s = ms / 1000; - return (nsync_time_s_ns (s, 1000 * 1000 * (ms % 1000))); -} - -nsync_time nsync_time_us (unsigned us) { - unsigned s = us / (1000 * 1000); - return (nsync_time_s_ns (s, 1000 * (us % (1000 * 1000)))); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/wait.c b/vendored/nsync/internal/wait.c deleted file mode 100644 index 3cf3fd0c..00000000 --- a/vendored/nsync/internal/wait.c +++ /dev/null @@ -1,103 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync.h" -#include "sem.h" -#include "dll.h" -#include "wait_internal.h" -#include "common.h" -#include "atomic.h" - -NSYNC_CPP_START_ - -int nsync_wait_n (void *mu, void (*lock) (void *), void (*unlock) (void *), - nsync_time abs_deadline, - int count, struct nsync_waitable_s *waitable[]) { - int ready; - IGNORE_RACES_START (); - for (ready = 0; ready != count && - nsync_time_cmp ((*waitable[ready]->funcs->ready_time) ( - waitable[ready]->v, NULL), - nsync_time_zero) > 0; - ready++) { - } - if (ready == count && nsync_time_cmp (abs_deadline, nsync_time_zero) > 0) { - int i; - int unlocked = 0; - int j; - int enqueued = 1; - waiter *w = nsync_waiter_new_ (); - struct nsync_waiter_s nw_set[4]; - struct nsync_waiter_s *nw = nw_set; - if (count > (int) (sizeof (nw_set) / sizeof (nw_set[0]))) { - nw = (struct nsync_waiter_s *) malloc (count * sizeof (nw[0])); - } - for (i = 0; i != count && enqueued; i++) { - nw[i].tag = NSYNC_WAITER_TAG; - nw[i].sem = &w->sem; - nsync_dll_init_ (&nw[i].q, &nw[i]); - ATM_STORE (&nw[i].waiting, 0); - nw[i].flags = 0; - enqueued = (*waitable[i]->funcs->enqueue) (waitable[i]->v, &nw[i]); - } - - if (i == count) { - nsync_time min_ntime; - if (mu != NULL) { - (*unlock) (mu); - unlocked = 1; - } - do { - min_ntime = abs_deadline; - for (j = 0; j != count; j++) { - nsync_time ntime; - ntime = (*waitable[j]->funcs->ready_time) ( - waitable[j]->v, &nw[j]); - if (nsync_time_cmp (ntime, min_ntime) < 0) { - min_ntime = ntime; - } - } - } while (nsync_time_cmp (min_ntime, nsync_time_zero) > 0 && - nsync_mu_semaphore_p_with_deadline (&w->sem, - min_ntime) == 0); - } - - /* An attempt was made above to enqueue waitable[0..i-1]. - Dequeue any that are still enqueued, and remember the index - of the first ready (i.e., not still enqueued) object, if any. */ - for (j = 0; j != i; j++) { - int was_still_enqueued = - (*waitable[j]->funcs->dequeue) (waitable[j]->v, &nw[j]); - if (!was_still_enqueued && ready == count) { - ready = j; - } - } - - if (nw != nw_set) { - free (nw); - } - nsync_waiter_free_ (w); - if (unlocked) { - (*lock) (mu); - } - } - IGNORE_RACES_END (); - return (ready); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/internal/wait_internal.h b/vendored/nsync/internal/wait_internal.h deleted file mode 100644 index 0121c227..00000000 --- a/vendored/nsync/internal/wait_internal.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_INTERNAL_WAIT_INTERNAL_H_ -#define NSYNC_INTERNAL_WAIT_INTERNAL_H_ - -NSYNC_CPP_START_ - -/* Implementations of "struct nsync_waitable_s" must provide functions in struct - nsync_waitable_funcs_s (see public/nsync_wait.h). When nsync_wait_n() waits - on a client's object, those functions are called with v pointing to the - client's object and nw pointing to a struct nsync_waiter_s. */ -struct nsync_waiter_s { - uint32_t tag; /* used for debugging */ - nsync_dll_element_ q; /* used to link children of parent */ - nsync_atomic_uint32_ waiting; /* non-zero <=> the waiter is waiting */ - struct nsync_semaphore_s_ *sem; /* *sem will be Ved when waiter is woken */ - uint32_t flags; /* see below */ -}; - -#define NSYNC_WAITER_FLAG_MUCV 0x1 /* set if waiter is embedded in Mu/CV's internal structures */ - -NSYNC_CPP_END_ - -#endif /*NSYNC_INTERNAL_WAIT_INTERNAL_H_*/ diff --git a/vendored/nsync/platform/aarch64/cputype.h b/vendored/nsync/platform/aarch64/cputype.h deleted file mode 100644 index 58029420..00000000 --- a/vendored/nsync/platform/aarch64/cputype.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_AARCH64_CPUTYPE_H_ -#define NSYNC_PLATFORM_AARCH64_CPUTYPE_H_ - -#define ATM_LD_IS_ACQ_ST_IS_REL_ 0 - -#endif /*NSYNC_PLATFORM_AARCH64_CPUTYPE_H_*/ diff --git a/vendored/nsync/platform/aarch64/src/nsync_atm_aarch64.s b/vendored/nsync/platform/aarch64/src/nsync_atm_aarch64.s deleted file mode 100644 index 5d4cae11..00000000 --- a/vendored/nsync/platform/aarch64/src/nsync_atm_aarch64.s +++ /dev/null @@ -1,119 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -/* Helper routines for aarch64 implementation of atomic operations. */ - -/* Atomically: - int nsync_atm_cas_ (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - if (*p == old_value) { - *p = new_value; - return (some-non-zero-value); - } else { - return (0); - } - } - */ - .text - .align 3 - .global nsync_atm_cas_ - .type nsync_atm_cas_, %function -nsync_atm_cas_: -1: - ldxr w3, [x0] - cmp w3, w1 - bne 2f - stxr w4, w2, [x0] - cbnz w4, 1b -2: - cset w0, eq - ret - -/* Like nsync_atm_cas_, but with acquire barrier semantics. */ - .align 3 - .global nsync_atm_cas_acq_ - .type nsync_atm_cas_acq_, %function -nsync_atm_cas_acq_: -1: - ldaxr w3, [x0] - cmp w3, w1 - bne 2f - stxr w4, w2, [x0] - cbnz w4, 1b -2: - cset w0, eq - ret - -/* Like nsync_atm_cas_, but with release barrier semantics. */ - .align 3 - .global nsync_atm_cas_rel_ - .type nsync_atm_cas_rel_, %function -nsync_atm_cas_rel_: -1: - ldxr w3, [x0] - cmp w3, w1 - bne 2f - stlxr w4, w2, [x0] - cbnz w4, 1b -2: - cset w0, eq - ret - -/* Like nsync_atm_cas_, but with both acquire and release barrier semantics. */ - .align 3 - .global nsync_atm_cas_relacq_ - .type nsync_atm_cas_relacq_, %function -nsync_atm_cas_relacq_: -1: - ldaxr w3, [x0] - cmp w3, w1 - bne 2f - stlxr w4, w2, [x0] - cbnz w4, 1b -2: - cset w0, eq - ret - -/* Atomically: - uint32_t nsync_atm_load_ (nsync_atomic_uint32_ *p) { return (*p); } */ - .align 3 - .global nsync_atm_load_ - .type nsync_atm_load_, %function -nsync_atm_load_: - ldr w0, [x0] - ret - -/* Like nsync_atm_load_, but with acquire barrier semantics. */ - .align 3 - .global nsync_atm_load_acq_ - .type nsync_atm_load_acq_, %function -nsync_atm_load_acq_: - ldar w0, [x0] - ret - -/* Atomically: - void nsync_atm_store_ (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } */ - .align 3 - .global nsync_atm_store_ - .type nsync_atm_store_, %function -nsync_atm_store_: - str w1, [x0] - ret - -/* Like nsync_atm_store_, but with release barrier semantics. */ - .align 3 - .global nsync_atm_store_rel_ - .type nsync_atm_store_rel_, %function -nsync_atm_store_rel_: - stlr w1, [x0] - ret diff --git a/vendored/nsync/platform/arm/cputype.h b/vendored/nsync/platform/arm/cputype.h deleted file mode 100644 index 655bee28..00000000 --- a/vendored/nsync/platform/arm/cputype.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_ARM_CPUTYPE_H_ -#define NSYNC_PLATFORM_ARM_CPUTYPE_H_ - -#define ATM_LD_IS_ACQ_ST_IS_REL_ 0 - -#endif /*NSYNC_PLATFORM_ARM_CPUTYPE_H_*/ diff --git a/vendored/nsync/platform/arm/src/nsync_atm_arm.s b/vendored/nsync/platform/arm/src/nsync_atm_arm.s deleted file mode 100644 index fd072b02..00000000 --- a/vendored/nsync/platform/arm/src/nsync_atm_arm.s +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -/* Helper routines for arm implementation of atomic operations. */ - - .text - -/* Atomically: - int nsync_atm_cas_ (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - if (*p == old_value) { - *p = new_value; - return (some-non-zero-value); - } else { - return (0); - } - } - */ - .align 3 - .global nsync_atm_cas_ - .type nsync_atm_cas_, %function -nsync_atm_cas_: -1: - ldrex r3, [r0] - cmp r3, r1 - bne 2f - strex r3, r2, [r0] - teq r3, #0 - bne 1b - mov r0, #1 - bx lr -2: - mov r0, #0 - bx lr - -/* Like nsync_atm_cas_, but with acquire barrier semantics. */ - .align 3 - .global nsync_atm_cas_acq_ - .type nsync_atm_cas_acq_, %function -nsync_atm_cas_acq_: -1: - ldrex r3, [r0] - cmp r3, r1 - bne 2f - strex r3, r2, [r0] - teq r3, #0 - bne 1b - dmb sy - mov r0, #1 - bx lr -2: - mov r0, #0 - bx lr - -/* Like nsync_atm_cas_, but with release barrier semantics. */ - .align 3 - .global nsync_atm_cas_rel_ - .type nsync_atm_cas_rel_, %function -nsync_atm_cas_rel_: - dmb sy -1: - ldrex r3, [r0] - cmp r3, r1 - bne 2f - strex r3, r2, [r0] - teq r3, #0 - bne 1b - mov r0, #1 - bx lr -2: - mov r0, #0 - bx lr - -/* Like nsync_atm_cas_, but with both acquire and release barrier semantics. */ - .align 3 - .global nsync_atm_cas_relacq_ - .type nsync_atm_cas_relacq_, %function -nsync_atm_cas_relacq_: - dmb sy -1: - ldrex r3, [r0] - cmp r3, r1 - bne 2f - strex r3, r2, [r0] - teq r3, #0 - bne 1b - dmb sy - mov r0, #1 - bx lr -2: - mov r0, #0 - bx lr - -/* Atomically: - uint32_t nsync_atm_load_ (nsync_atomic_uint32_ *p) { return (*p); } */ - .align 3 - .global nsync_atm_load_ - .type nsync_atm_load_, %function -nsync_atm_load_: - ldr r0, [r0] - bx lr - -/* Like nsync_atm_load_, but with acquire barrier semantics. */ - .align 3 - .global nsync_atm_load_acq_ - .type nsync_atm_load_acq_, %function -nsync_atm_load_acq_: - ldr r0, [r0] - dmb sy - bx lr - -/* Atomically: - void nsync_atm_store_ (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } */ - .align 3 - .global nsync_atm_store_ - .type nsync_atm_store_, %function -nsync_atm_store_: - str r1, [r0] - bx lr - -/* Like nsync_atm_store_, but with release barrier semantics. */ - .align 3 - .global nsync_atm_store_rel_ - .type nsync_atm_store_rel_, %function -nsync_atm_store_rel_: - dmb sy - str r1, [r0] - bx lr diff --git a/vendored/nsync/platform/clang/atomic.h b/vendored/nsync/platform/clang/atomic.h deleted file mode 100644 index 72abba26..00000000 --- a/vendored/nsync/platform/clang/atomic.h +++ /dev/null @@ -1,18 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_CLANG_ATOMIC_H_ -#define NSYNC_PLATFORM_CLANG_ATOMIC_H_ -#include "../gcc/atomic.h" -#endif /*NSYNC_PLATFORM_CLANG_ATOMIC_H_*/ diff --git a/vendored/nsync/platform/clang/compiler.h b/vendored/nsync/platform/clang/compiler.h deleted file mode 100644 index e767e404..00000000 --- a/vendored/nsync/platform/clang/compiler.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_CLANG_COMPILER_H_ -#define NSYNC_PLATFORM_CLANG_COMPILER_H_ - -#define INLINE __inline -#define UNUSED __attribute__((unused)) -#define THREAD_LOCAL __thread -#define HAVE_THREAD_LOCAL 1 - -#endif /*NSYNC_PLATFORM_CLANG_COMPILER_H_*/ diff --git a/vendored/nsync/platform/freebsd/platform.h b/vendored/nsync/platform/freebsd/platform.h deleted file mode 100644 index 021e79f6..00000000 --- a/vendored/nsync/platform/freebsd/platform.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_FREEBSD_PLATFORM_H_ -#define NSYNC_PLATFORM_FREEBSD_PLATFORM_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#endif /*NSYNC_PLATFORM_FREEBSD_PLATFORM_H_*/ diff --git a/vendored/nsync/platform/gcc/atomic.h b/vendored/nsync/platform/gcc/atomic.h deleted file mode 100644 index 9a3cfd80..00000000 --- a/vendored/nsync/platform/gcc/atomic.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_GCC_ATOMIC_H_ -#define NSYNC_PLATFORM_GCC_ATOMIC_H_ - -/* Atomic operations on nsync_atomic_uint32_ quantities - CAS, load, and store. - - Normally, these are used only on nsync_atomic_uint32_ values, but on Linux - they may be invoked on int values, because futexes operate on int values. A - compile-time check in the futex code ensures that both int and - nsync_atomic_uint32_ are 32 bits. - - Memory barriers: - Operations with the suffixes _ACQ and _RELACQ ensure that the operation - appears to complete before other memory operations subsequently performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_ACQ and - ATM_CAS_RELACQ, this applies only if the operation returns a non-zero - value.) - - Operations with the suffixes _REL and _RELACQ ensure that the operation - appears to complete after other memory operations previously performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_REL and - ATM_CAS_RELACQ, this applies only if the operation returns a non-zero value.) - - // Atomically, - // int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - // if (*p == old_value) { - // *p = new_value; - // return (some-non-zero-value); - // } else { - // return (0); - // } - // } - // *_ACQ, *_REL, and *_RELACQ variants are available, - // with the barrier semantics described above. - int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value); - - // Atomically, - // uint32_t ATM_LOAD (nsync_atomic_uint32_ *p) { return (*p); } - // A *_ACQ variant is available, - // with the barrier semantics described above. - uint32_t ATM_LOAD (nsync_atomic_uint32_ *p); - - // Atomically, - // void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } - // A *_REL variant is available, - // with the barrier semantics described above. - void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value); - */ - -#if !defined(__GNUC__) || \ - ((__GNUC__ - 0) * 100 + (__GNUC_MINOR__ - 0)) < 407 || \ - defined(__INTEL_COMPILER) || defined(__clang__) -#include "../gcc_old/atomic.h" -#else -#include "../gcc_new/atomic.h" -#endif - -#endif /*NSYNC_PLATFORM_GCC_ATOMIC_H_*/ diff --git a/vendored/nsync/platform/gcc/compiler.h b/vendored/nsync/platform/gcc/compiler.h deleted file mode 100644 index 2f22d57e..00000000 --- a/vendored/nsync/platform/gcc/compiler.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_GCC_COMPILER_H_ -#define NSYNC_PLATFORM_GCC_COMPILER_H_ - -#define INLINE __inline -#define UNUSED __attribute__((unused)) -#define THREAD_LOCAL __thread -#define HAVE_THREAD_LOCAL 1 - -#endif /*NSYNC_PLATFORM_GCC_COMPILER_H_*/ diff --git a/vendored/nsync/platform/gcc_new/atomic.h b/vendored/nsync/platform/gcc_new/atomic.h deleted file mode 100644 index e9eecce1..00000000 --- a/vendored/nsync/platform/gcc_new/atomic.h +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_GCC_NEW_ATOMIC_H_ -#define NSYNC_PLATFORM_GCC_NEW_ATOMIC_H_ - -/* Atomic operations on nsync_atomic_uint32_ quantities - CAS, load, and store. - - Normally, these are used only on nsync_atomic_uint32_ values, but on Linux they may be - invoked on int values, because futexes operate on int values. A - compile-time check in the futex code ensures that both int and - nsync_atomic_uint32_ are 32 bits. - - Memory barriers: - Operations with the suffixes _ACQ and _RELACQ ensure that the operation - appears to complete before other memory operations subsequently performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_ACQ, - this applies only if the operation returns a non-zero value.) - - Operations with the suffixes _REL and _RELACQ ensure that the operation - appears to complete after other memory operations previously performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_REL, - this applies only if the operation returns a non-zero value.) - - // Atomically, - // int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - // if (*p == old_value) { - // *p = new_value; - // return (some-non-zero-value); - // } else { - // return (0); - // } - // } - // *_ACQ, *_REL, *_RELACQ variants are available, - // with the barrier semantics described above. - int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value); - - // Atomically, - // uint32_t ATM_LOAD (nsync_atomic_uint32_ *p) { return (*p); } - // A *_ACQ variant is available, - // with the barrier semantics described above. - uint32_t ATM_LOAD (nsync_atomic_uint32_ *p); - - // Atomically, - // void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } - // A *_REL variant is available, - // with the barrier semantics described above. - void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value); - */ - -#include "compiler.h" -#include "nsync_atomic.h" - -NSYNC_CPP_START_ - -/* GCC 4.7 or later --- has new-style atomic ops */ - -static __inline__ int atm_cas_nomb_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { - return (__atomic_compare_exchange_n (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, 0, - __ATOMIC_RELAXED, __ATOMIC_RELAXED)); -} -static __inline__ int atm_cas_acq_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { - return (__atomic_compare_exchange_n (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, 0, - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)); -} -static __inline__ int atm_cas_rel_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { - return (__atomic_compare_exchange_n (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, 0, - __ATOMIC_RELEASE, __ATOMIC_RELAXED)); -} -static __inline__ int atm_cas_relacq_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { - return (__atomic_compare_exchange_n (NSYNC_ATOMIC_UINT32_PTR_ (p), &o, n, 0, - __ATOMIC_ACQ_REL, __ATOMIC_RELAXED)); -} - -#define ATM_CAS_HELPER_(barrier, p, o, n) (atm_cas_##barrier##_u32_ ((p), (o), (n))) - -#define ATM_CAS(p,o,n) ATM_CAS_HELPER_ (nomb, (p), (o), (n)) -#define ATM_CAS_ACQ(p,o,n) ATM_CAS_HELPER_ (acq, (p), (o), (n)) -#define ATM_CAS_REL(p,o,n) ATM_CAS_HELPER_ (rel, (p), (o), (n)) -#define ATM_CAS_RELACQ(p,o,n) ATM_CAS_HELPER_ (relacq, (p), (o), (n)) - -#define ATM_LOAD(p) (__atomic_load_n (NSYNC_ATOMIC_UINT32_PTR_ (p), __ATOMIC_RELAXED)) -#define ATM_LOAD_ACQ(p) (__atomic_load_n (NSYNC_ATOMIC_UINT32_PTR_ (p), __ATOMIC_ACQUIRE)) - -#define ATM_STORE(p,v) (__atomic_store_n (NSYNC_ATOMIC_UINT32_PTR_ (p), (v), __ATOMIC_RELAXED)) -#define ATM_STORE_REL(p,v) (__atomic_store_n (NSYNC_ATOMIC_UINT32_PTR_ (p), (v), __ATOMIC_RELEASE)) - -NSYNC_CPP_END_ - -#endif /*NSYNC_PLATFORM_GCC_NEW_ATOMIC_H_*/ diff --git a/vendored/nsync/platform/gcc_old/atomic.h b/vendored/nsync/platform/gcc_old/atomic.h deleted file mode 100644 index fb7e2eaf..00000000 --- a/vendored/nsync/platform/gcc_old/atomic.h +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_GCC_OLD_ATOMIC_H_ -#define NSYNC_PLATFORM_GCC_OLD_ATOMIC_H_ - -/* Atomic operations on nsync_atomic_uint32_ quantities - CAS, load, and store. - - Normally, these are used only on nsync_atomic_uint32_ values, but on Linux they may be - invoked on int values, because futexes operate on int values. A - compile-time check in the futex code ensures that both int and - nsync_atomic_uint32_ are 32 bits. - - Memory barriers: - Operations with the suffixes _ACQ and _RELACQ ensure that the operation - appears to complete before other memory operations subsequently performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_ACQ, - this applies only if the operation returns a non-zero value.) - - Operations with the suffixes _REL and _RELACQ ensure that the operation - appears to complete after other memory operations previously performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_REL, - this applies only if the operation returns a non-zero value.) - - // Atomically, - // int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - // if (*p == old_value) { - // *p = new_value; - // return (some-non-zero-value); - // } else { - // return (0); - // } - // } - // *_ACQ, *_REL, *_RELACQ variants are available, - // with the barrier semantics described above. - int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value); - - // Atomically, - // uint32_t ATM_LOAD (nsync_atomic_uint32_ *p) { return (*p); } - // A *_ACQ variant is available, - // with the barrier semantics described above. - uint32_t ATM_LOAD (nsync_atomic_uint32_ *p); - - // Atomically, - // void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } - // A *_REL variant is available, - // with the barrier semantics described above. - void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value); - */ - -#include "compiler.h" -#include "nsync_atomic.h" - -NSYNC_CPP_START_ - -/* GCC before 4.7 or old gcc compatible --- use __sync ops. */ - -#if ATM_LD_IS_ACQ_ST_IS_REL_ -#define ATM_LD_ACQ_ ATM_CB_ -#define ATM_ST_REL_ ATM_CB_ -#else -#define ATM_LD_ACQ_ ATM_MB_ -#define ATM_ST_REL_ ATM_MB_ -#endif - -#define ATM_CB_() __asm__ __volatile__ ("" : : : "memory") /* compiler barrier */ - -#define ATM_MB_() __sync_synchronize () - -/*----*/ - -#define ATM_CAS(p,o,n) (__sync_bool_compare_and_swap (NSYNC_ATOMIC_UINT32_PTR_ (p), (o), (n))) -#define ATM_CAS_ACQ ATM_CAS -#define ATM_CAS_REL ATM_CAS -#define ATM_CAS_RELACQ ATM_CAS - -/*----*/ - -static __inline__ uint32_t atm_load_acq_u32_ (nsync_atomic_uint32_ *p) { - uint32_t result = NSYNC_ATOMIC_UINT32_LOAD_ ((volatile nsync_atomic_uint32_ *)p); - ATM_LD_ACQ_ (); - return (result); -} - -#define ATM_LOAD(p) NSYNC_ATOMIC_UINT32_LOAD_ ((volatile nsync_atomic_uint32_ *)(p)) -#define ATM_LOAD_ACQ(p) (atm_load_acq_u32_ (p)) - -/*----*/ - -#define ATM_STORE_X_(p,v,b,a) do { \ - b; \ - NSYNC_ATOMIC_UINT32_STORE_ ((volatile nsync_atomic_uint32_ *)(p), (uint32_t) (v)); \ - a; \ - } while (0) - -#define ATM_STORE(p,v) ATM_STORE_X_ ((p), (v), ; , ; ) -#define ATM_STORE_REL(p,v) ATM_STORE_X_ ((p), (v), ATM_ST_REL_ (), ; ) - -NSYNC_CPP_END_ - -#endif /*NSYNC_PLATFORM_GCC_OLD_ATOMIC_H_*/ diff --git a/vendored/nsync/platform/linux/platform.h b/vendored/nsync/platform/linux/platform.h deleted file mode 100644 index d194f120..00000000 --- a/vendored/nsync/platform/linux/platform.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_LINUX_PLATFORM_H_ -#define NSYNC_PLATFORM_LINUX_PLATFORM_H_ - -#if !defined(_GNU_SOURCE) -#define _GNU_SOURCE /* for futexes */ -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#endif /*NSYNC_PLATFORM_LINUX_PLATFORM_H_*/ diff --git a/vendored/nsync/platform/linux/src/nsync_semaphore_futex.c b/vendored/nsync/platform/linux/src/nsync_semaphore_futex.c deleted file mode 100644 index b34d1a15..00000000 --- a/vendored/nsync/platform/linux/src/nsync_semaphore_futex.c +++ /dev/null @@ -1,141 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -/* Linux uses 64-bit time when _TIME_BITS==64; only __NR_futex_time64 is - defined for some CPU types. */ -#define NSYNC_NR_FUTEX __NR_futex -#if defined(__NR_futex_time64) && (defined(_TIME_BITS) || !defined(__NR_futex)) -#if _TIME_BITS == 64 || !defined(__NR_futex) -#undef NSYNC_NR_FUTEX -#define NSYNC_NR_FUTEX __NR_futex_time64 -#endif -#endif - -static int futex (int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, - int val3) { - return (syscall (NSYNC_NR_FUTEX, uaddr, op, val, timeout, uaddr2, val3)); -} - -/* Check that atomic operations on nsync_atomic_uint32_ can be applied to int. */ -static const int assert_int_size = 1 / - (sizeof (assert_int_size) == sizeof (uint32_t) && - sizeof (nsync_atomic_uint32_) == sizeof (uint32_t)); - -#if defined(FUTEX_PRIVATE_FLAG) -#define FUTEX_PRIVATE_FLAG_ FUTEX_PRIVATE_FLAG -#else -#define FUTEX_PRIVATE_FLAG_ 0 -#endif - -#if defined(FUTEX_WAIT_BITSET) -#define FUTEX_WAIT_ (FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG_ | FUTEX_CLOCK_REALTIME) -#define FUTEX_WAIT_BITS_ FUTEX_BITSET_MATCH_ANY -#else -#define FUTEX_WAIT_ (FUTEX_WAIT | FUTEX_PRIVATE_FLAG_) -#define FUTEX_WAIT_BITS_ 0 -#endif -#define FUTEX_WAKE_ (FUTEX_WAKE | FUTEX_PRIVATE_FLAG_) -#define FUTEX_TIMEOUT_IS_ABSOLUTE (FUTEX_WAIT_BITS_ != 0) - -#define ASSERT(x) do { if (!(x)) { *(volatile int *)0 = 0; } } while (0) - -struct futex { - int i; /* lo half=count; hi half=waiter count */ -}; - -static nsync_semaphore *sem_big_enough_for_futex = (nsync_semaphore *) (uintptr_t)(1 / - (sizeof (struct futex) <= sizeof (*sem_big_enough_for_futex))); - -/* Initialize *s; the initial value is 0. */ -void nsync_mu_semaphore_init (nsync_semaphore *s) { - struct futex *f = (struct futex *) s; - f->i = 0; -} - -/* Wait until the count of *s exceeds 0, and decrement it. */ -void nsync_mu_semaphore_p (nsync_semaphore *s) { - struct futex *f = (struct futex *) s; - int i; - do { - i = ATM_LOAD ((nsync_atomic_uint32_ *) &f->i); - if (i == 0) { - int futex_result = futex (&f->i, FUTEX_WAIT_, i, NULL, - NULL, FUTEX_WAIT_BITS_); - ASSERT (futex_result == 0 || errno == EINTR || - errno == EWOULDBLOCK); - } - } while (i == 0 || !ATM_CAS_ACQ ((nsync_atomic_uint32_ *) &f->i, i, i-1)); -} - -/* Wait until one of: - the count of *s is non-zero, in which case decrement *s and return 0; - or abs_deadline expires, in which case return ETIMEDOUT. */ -int nsync_mu_semaphore_p_with_deadline (nsync_semaphore *s, nsync_time abs_deadline) { - struct futex *f = (struct futex *)s; - int i; - int result = 0; - do { - i = ATM_LOAD ((nsync_atomic_uint32_ *) &f->i); - if (i == 0) { - int futex_result; - struct timespec ts_buf; - const struct timespec *ts = NULL; - if (nsync_time_cmp (abs_deadline, nsync_time_no_deadline) != 0) { - memset (&ts_buf, 0, sizeof (ts_buf)); - if (FUTEX_TIMEOUT_IS_ABSOLUTE) { - ts_buf.tv_sec = NSYNC_TIME_SEC (abs_deadline); - ts_buf.tv_nsec = NSYNC_TIME_NSEC (abs_deadline); - } else { - nsync_time now; - now = nsync_time_now (); - if (nsync_time_cmp (now, abs_deadline) > 0) { - ts_buf.tv_sec = 0; - ts_buf.tv_nsec = 0; - } else { - nsync_time rel_deadline; - rel_deadline = nsync_time_sub (abs_deadline, now); - ts_buf.tv_sec = NSYNC_TIME_SEC (rel_deadline); - ts_buf.tv_nsec = NSYNC_TIME_NSEC (rel_deadline); - } - } - ts = &ts_buf; - } - futex_result = futex (&f->i, FUTEX_WAIT_, i, ts, NULL, FUTEX_WAIT_BITS_); - ASSERT (futex_result == 0 || errno == EINTR || errno == EWOULDBLOCK || - errno == ETIMEDOUT); - /* Some systems don't wait as long as they are told. */ - if (futex_result == -1 && errno == ETIMEDOUT && - nsync_time_cmp (abs_deadline, nsync_time_now ()) <= 0) { - result = ETIMEDOUT; - } - } - } while (result == 0 && (i == 0 || !ATM_CAS_ACQ ((nsync_atomic_uint32_ *) &f->i, i, i - 1))); - return (result); -} - -/* Ensure that the count of *s is at least 1. */ -void nsync_mu_semaphore_v (nsync_semaphore *s) { - struct futex *f = (struct futex *) s; - uint32_t old_value; - do { - old_value = ATM_LOAD ((nsync_atomic_uint32_ *) &f->i); - } while (!ATM_CAS_REL ((nsync_atomic_uint32_ *) &f->i, old_value, old_value+1)); - ASSERT (futex (&f->i, FUTEX_WAKE_, 1, NULL, NULL, 0) >= 0); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/macos/atomic.h b/vendored/nsync/platform/macos/atomic.h deleted file mode 100644 index 84352d00..00000000 --- a/vendored/nsync/platform/macos/atomic.h +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_MACOS_ATOMIC_H_ -#define NSYNC_PLATFORM_MACOS_ATOMIC_H_ - -/* Atomic operations on nsync_atomic_uint32_ quantities - CAS, load, and store. - - Normally, these are used only on nsync_atomic_uint32_ values, but on Linux they may be - invoked on int values, because futexes operate on int values. A - compile-time check in the futex code ensures that both int and - nsync_atomic_uint32_ are 32 bits. - - Memory barriers: - Operations with the suffixes _ACQ and _RELACQ ensure that the operation - appears to complete before other memory operations subsequently performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_ACQ, - this applies only if the operation returns a non-zero value.) - - Operations with the suffixes _REL and _RELACQ ensure that the operation - appears to complete after other memory operations previously performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_REL, - this applies only if the operation returns a non-zero value.) - - // Atomically, - // int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - // if (*p == old_value) { - // *p = new_value; - // return (some-non-zero-value); - // } else { - // return (0); - // } - // } - // *_ACQ, *_REL, *_RELACQ variants are available, - // with the barrier semantics described above. - int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value); - - // Atomically, - // uint32_t ATM_LOAD (nsync_atomic_uint32_ *p) { return (*p); } - // A *_ACQ variant is available, - // with the barrier semantics described above. - uint32_t ATM_LOAD (nsync_atomic_uint32_ *p); - - // Atomically, - // void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } - // A *_REL variant is available, - // with the barrier semantics described above. - void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value); - */ - -#include "compiler.h" -#include "nsync_atomic.h" -#include - -NSYNC_CPP_START_ - -#define ATM_MB_() OSMemoryBarrier () - -#if ATM_LD_IS_ACQ_ST_IS_REL_ -#define ATM_CB_() __asm__ __volatile__ ("" : : : "memory") /* compiler barrier */ -#define ATM_LD_ACQ_ ATM_CB_ -#define ATM_ST_REL_ ATM_CB_ -#else -#define ATM_LD_ACQ_ ATM_MB_ -#define ATM_ST_REL_ ATM_MB_ -#endif - -#define ATM_CAS(p,o,n) OSAtomicCompareAndSwap32 ((o), (n), (int32_t *) NSYNC_ATOMIC_UINT32_PTR_ (p)) -#define ATM_CAS_ACQ(p,o,n) OSAtomicCompareAndSwap32Barrier ((o), (n), (int32_t *) NSYNC_ATOMIC_UINT32_PTR_ (p)) -#define ATM_CAS_REL(p,o,n) OSAtomicCompareAndSwap32Barrier ((o), (n), (int32_t *) NSYNC_ATOMIC_UINT32_PTR_ (p)) -#define ATM_CAS_RELACQ(p,o,n) OSAtomicCompareAndSwap32Barrier ((o), (n), (int32_t *) NSYNC_ATOMIC_UINT32_PTR_ (p)) - -/*----*/ - -static INLINE uint32_t atm_load_acq_u32_ (nsync_atomic_uint32_ *p) { - uint32_t result = NSYNC_ATOMIC_UINT32_LOAD_ ((volatile nsync_atomic_uint32_ *)p); - ATM_LD_ACQ_ (); - return (result); -} - -#define ATM_LOAD(p) (NSYNC_ATOMIC_UINT32_LOAD_ ((volatile nsync_atomic_uint32_ *)(p))) -#define ATM_LOAD_ACQ(p) (atm_load_acq_u32_ (p)) - -/*----*/ - -#define ATM_STORE_X_(p,v,b,a) do { \ - b; \ - NSYNC_ATOMIC_UINT32_STORE_ ((volatile nsync_atomic_uint32_ *)(p), (uint32_t) (v)); \ - a; \ - } while (0) - -#define ATM_STORE(p,v) ATM_STORE_X_ ((p), (v), ; , ; ) -#define ATM_STORE_REL(p,v) ATM_STORE_X_ ((p), (v), ATM_ST_REL_ (), ; ) - -NSYNC_CPP_END_ - -#endif /*NSYNC_PLATFORM_MACOS_ATOMIC_H_*/ diff --git a/vendored/nsync/platform/macos/platform.h b/vendored/nsync/platform/macos/platform.h deleted file mode 100644 index c14c121c..00000000 --- a/vendored/nsync/platform/macos/platform.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_MACOS_PLATFORM_H_ -#define NSYNC_PLATFORM_MACOS_PLATFORM_H_ - -#define _DARWIN_C_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -/* Some versions(!) of MacOS don't implement clock_gettime(). */ -#if !defined(CLOCK_REALTIME) -#define CLOCK_REALTIME 0 -typedef int clockid_t; -int clock_gettime (clockid_t clk_id, struct timespec *tp); -#define TIMER_ABSTIME 1 -#endif /*CLOCK_REALTIME*/ - -#endif /*NSYNC_PLATFORM_MACOS_PLATFORM_H_*/ diff --git a/vendored/nsync/platform/macos/platform_c++11_os.h b/vendored/nsync/platform/macos/platform_c++11_os.h deleted file mode 100644 index 2f1e9ce8..00000000 --- a/vendored/nsync/platform/macos/platform_c++11_os.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_MACOS_PLATFORM_CPP_OS_H_ -#define NSYNC_PLATFORM_MACOS_PLATFORM_CPP_OS_H_ - -/* Some versions(!) of MacOS don't implement clock_gettime(). */ -#include -#if !defined(CLOCK_REALTIME) - -#define CLOCK_REALTIME 0 -#define TIMER_ABSTIME 1 - -NSYNC_CPP_START_ -typedef int clockid_t; -int clock_gettime (clockid_t clk_id, struct timespec *tp); -NSYNC_CPP_END_ - -#endif /*CLOCK_REALTIME*/ - -#endif /*NSYNC_PLATFORM_MACOS_PLATFORM_CPP_OS_H_*/ diff --git a/vendored/nsync/platform/macos/src/nsync_semaphore_gcd.c b/vendored/nsync/platform/macos/src/nsync_semaphore_gcd.c deleted file mode 100644 index 94f4c698..00000000 --- a/vendored/nsync/platform/macos/src/nsync_semaphore_gcd.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright 2019 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" -#pragma GCC diagnostic ignored "-Wlong-long" /* to avoid error on DISPATCH_TIME_FOREVER */ -#include - -NSYNC_CPP_START_ - -static nsync_semaphore *sem_big_enough_for_dispatch_semaphore_t = (void *) (1 / - (sizeof (dispatch_semaphore_t) <= sizeof (*sem_big_enough_for_dispatch_semaphore_t))); - -/* Initialize *s; the initial value is 0. */ -void nsync_mu_semaphore_init (nsync_semaphore *s) { - *(dispatch_semaphore_t *)s = dispatch_semaphore_create (0); -} - -/* Wait until the count of *s exceeds 0, and decrement it. */ -void nsync_mu_semaphore_p (nsync_semaphore *s) { - dispatch_semaphore_wait (*(dispatch_semaphore_t *)s, DISPATCH_TIME_FOREVER); -} - -/* Wait until one of: - the count of *s is non-zero, in which case decrement *s and return 0; - or abs_deadline expires, in which case return ETIMEDOUT. */ -int nsync_mu_semaphore_p_with_deadline (nsync_semaphore *s, - nsync_time abs_deadline) { - int result = 0; - if (nsync_time_cmp (abs_deadline, nsync_time_no_deadline) == 0) { - dispatch_semaphore_wait (*(dispatch_semaphore_t *)s, DISPATCH_TIME_FOREVER); - } else { - struct timespec ts; - memset (&ts, 0, sizeof (ts)); - ts.tv_sec = NSYNC_TIME_SEC (abs_deadline); - ts.tv_nsec = NSYNC_TIME_NSEC (abs_deadline); - if (dispatch_semaphore_wait (*(dispatch_semaphore_t *)s, - dispatch_walltime (&abs_deadline, 0)) != 0) { - result = ETIMEDOUT; - } - } - return (result); -} - -/* Ensure that the count of *s is at least 1. */ -void nsync_mu_semaphore_v (nsync_semaphore *s) { - dispatch_semaphore_signal (*(dispatch_semaphore_t *)s); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/msvc/compiler.h b/vendored/nsync/platform/msvc/compiler.h deleted file mode 100644 index 352b0f62..00000000 --- a/vendored/nsync/platform/msvc/compiler.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_MSVC_COMPILER_H_ -#define NSYNC_PLATFORM_MSVC_COMPILER_H_ - -#define INLINE __inline -#define UNUSED -#define THREAD_LOCAL __declspec(thread) -#define HAVE_THREAD_LOCAL 1 - -#endif /*NSYNC_PLATFORM_MSVC_COMPILER_H_*/ diff --git a/vendored/nsync/platform/netbsd/atomic.h b/vendored/nsync/platform/netbsd/atomic.h deleted file mode 100644 index ac7b6883..00000000 --- a/vendored/nsync/platform/netbsd/atomic.h +++ /dev/null @@ -1,117 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_NETBSD_ATOMIC_H_ -#define NSYNC_PLATFORM_NETBSD_ATOMIC_H_ - -/* Atomic operations on nsync_atomic_uint32_ quantities - CAS, load, and store. - - Normally, these are used only on nsync_atomic_uint32_ values, but on Linux they may be - invoked on int values, because futexes operate on int values. A - compile-time check in the futex code ensures that both int and - nsync_atomic_uint32_ are 32 bits. - - Memory barriers: - Operations with the suffixes _ACQ and _RELACQ ensure that the operation - appears to complete before other memory operations subsequently performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_ACQ, - this applies only if the operation returns a non-zero value.) - - Operations with the suffixes _REL and _RELACQ ensure that the operation - appears to complete after other memory operations previously performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_REL, - this applies only if the operation returns a non-zero value.) - - // Atomically, - // int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - // if (*p == old_value) { - // *p = new_value; - // return (some-non-zero-value); - // } else { - // return (0); - // } - // } - // *_ACQ, *_REL, *_RELACQ variants are available, - // with the barrier semantics described above. - int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value); - - // Atomically, - // uint32_t ATM_LOAD (nsync_atomic_uint32_ *p) { return (*p); } - // A *_ACQ variant is available, - // with the barrier semantics described above. - uint32_t ATM_LOAD (nsync_atomic_uint32_ *p); - - // Atomically, - // void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } - // A *_REL variant is available, - // with the barrier semantics described above. - void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value); - */ - -#include "compiler.h" -#include "nsync_atomic.h" -#include - -NSYNC_CPP_START_ - -#if ATM_LD_IS_ACQ_ST_IS_REL_ && defined(__GNUC__) -#define ATM_CB_() __asm__ __volatile__ ("" : : : "memory") /* compiler barrier */ -#define ATM_LD_ACQ_ ATM_CB_ -#define ATM_ST_REL_ ATM_CB_ -#else -#define ATM_LD_ACQ_ membar_sync /* not membar_enter(); it doesn't affect preceding loads */ -#define ATM_ST_REL_ membar_exit -#endif - -static INLINE int atm_cas_nomb_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { - return (atomic_cas_32 (NSYNC_ATOMIC_UINT32_PTR_ (p), o, n) == o); -} - -static INLINE int atm_cas_acq_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { - int res = (atomic_cas_32 (NSYNC_ATOMIC_UINT32_PTR_ (p), o, n) == o); - membar_enter (); - return (res); -} - -#define ATM_CAS(p,o,n) (atm_cas_nomb_u32_ ((p),(o),(n))) -#define ATM_CAS_ACQ(p,o,n) (atm_cas_acq_u32_ ((p),(o),(n))) -#define ATM_CAS_REL(p,o,n) (membar_exit (), ATM_CAS ((p), (o), (n))) -#define ATM_CAS_RELACQ(p,o,n) (membar_exit (), atm_cas_acq_u32_ ((p),(o),(n))) - -/*----*/ - -static INLINE uint32_t atm_load_acq_u32_ (nsync_atomic_uint32_ *p) { - uint32_t result = NSYNC_ATOMIC_UINT32_LOAD_ ((volatile nsync_atomic_uint32_ *)p); - ATM_LD_ACQ_ (); - return (result); -} - -#define ATM_LOAD(p) (NSYNC_ATOMIC_UINT32_LOAD_ ((volatile nsync_atomic_uint32_ *)(p))) -#define ATM_LOAD_ACQ(p) (atm_load_acq_u32_ (p)) - -/*----*/ - -#define ATM_STORE_X_(p,v,b,a) do { \ - b; \ - NSYNC_ATOMIC_UINT32_STORE_ ((volatile nsync_atomic_uint32_ *)(p), (uint32_t) (v)); \ - a; \ - } while (0) - -#define ATM_STORE(p,v) ATM_STORE_X_ ((p), (v), ; , ; ) -#define ATM_STORE_REL(p,v) ATM_STORE_X_ ((p), (v), ATM_ST_REL_ (), ; ) - -NSYNC_CPP_END_ - -#endif /*NSYNC_PLATFORM_NETBSD_ATOMIC_H_*/ diff --git a/vendored/nsync/platform/netbsd/platform.h b/vendored/nsync/platform/netbsd/platform.h deleted file mode 100644 index f173ff38..00000000 --- a/vendored/nsync/platform/netbsd/platform.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_NETBSD_PLATFORM_H_ -#define NSYNC_PLATFORM_NETBSD_PLATFORM_H_ - -#if !defined(_NETBSD_SOURCE) -#define _NETBSD_SOURCE -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#endif /*NSYNC_PLATFORM_NETBSD_PLATFORM_H_*/ diff --git a/vendored/nsync/platform/openbsd/platform.h b/vendored/nsync/platform/openbsd/platform.h deleted file mode 100644 index c9830185..00000000 --- a/vendored/nsync/platform/openbsd/platform.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_OPENBSD_PLATFORM_H_ -#define NSYNC_PLATFORM_OPENBSD_PLATFORM_H_ - -#if !defined(_BSD_SOURCE) -#define _BSD_SOURCE /* provided ECANCELED */ -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#endif /*NSYNC_PLATFORM_OPENBSD_PLATFORM_H_*/ diff --git a/vendored/nsync/platform/posix/compiler.h b/vendored/nsync/platform/posix/compiler.h deleted file mode 100644 index 4e51170d..00000000 --- a/vendored/nsync/platform/posix/compiler.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_POSIX_COMPILER_H_ -#define NSYNC_PLATFORM_POSIX_COMPILER_H_ - -#define INLINE -#define UNUSED -#define THREAD_LOCAL -#define HAVE_THREAD_LOCAL 0 - -#endif /*NSYNC_PLATFORM_POSIX_COMPILER_H_*/ diff --git a/vendored/nsync/platform/posix/cputype.h b/vendored/nsync/platform/posix/cputype.h deleted file mode 100644 index 5c3197c9..00000000 --- a/vendored/nsync/platform/posix/cputype.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_POSIX_CPUTYPE_H_ -#define NSYNC_PLATFORM_POSIX_CPUTYPE_H_ - -#define ATM_LD_IS_ACQ_ST_IS_REL_ 0 - -#endif /*NSYNC_PLATFORM_POSIX_CPUTYPE_H_*/ diff --git a/vendored/nsync/platform/posix/make.common b/vendored/nsync/platform/posix/make.common deleted file mode 100644 index 2ca20638..00000000 --- a/vendored/nsync/platform/posix/make.common +++ /dev/null @@ -1,116 +0,0 @@ -# A generic Makefile included by the most platform-specific Makefiles. -# Uses no fancy features, so can be included by many make variants, -# but is not used by nmake. - -PUBLIC=../../public -INTERNAL=../../internal -TESTING=../../testing -TOOLS=../../tools - -OPT=-O -CPPFLAGS=${PLATFORM_CPPFLAGS} -I${PUBLIC} -I${INTERNAL} -CFLAGS=${CPPFLAGS} ${OPT} ${PLATFORM_CFLAGS} -CXXFLAGS=${CPPFLAGS} ${OPT} ${PLATFORM_CXXFLAGS} -LDFLAGS=${OPT} ${PLATFORM_LDFLAGS} -PAR_SUB_COUNT=1 # subtests to run in parallel with partest -PAR_COUNT=2 # tests to run in parallel with partest -LD=${CC} - -TESTS=counter_test cv_mu_timeout_stress_test cv_test cv_wait_example_test dll_test mu_starvation_test mu_test mu_wait_example_test mu_wait_test note_test once_test pingpong_test wait_test - -TEST_OBJS=counter_test.o cv_mu_timeout_stress_test.o cv_test.o cv_wait_example_test.o dll_test.o mu_starvation_test.o mu_test.o mu_wait_example_test.o mu_wait_test.o note_test.o once_test.o pingpong_test.o wait_test.o -TEST_LIB_OBJS=array.o atm_log.o closure.o time_extra.o smprintf.o testing.o ${TEST_PLATFORM_OBJS} -LIB_OBJS=common.o counter.o cv.o debug.o dll.o mu.o mu_wait.o note.o once.o sem_wait.o time_internal.o wait.o ${PLATFORM_OBJS} -LIB=libnsync.a -LIBALTNAME=nsync.a -TEST_LIB=nsync_test.a - -all: ${LIB} ${LIBALTNAME} - -${LIB}: ${LIB_OBJS} - ${AR} cr ${LIB} $? - case "${RANLIB}" in "") ;; *) ${RANLIB} ${LIB};; esac - -# Older versions of this package exported a different library name. -${LIBALTNAME}: ${LIB} - cp ${LIB} ${LIBALTNAME} - case "${RANLIB}" in "") ;; *) ${RANLIB} ${LIBALTNAME};; esac - -${TEST_LIB}: ${TEST_LIB_OBJS} - ${AR} cr ${TEST_LIB} $? - case "${RANLIB}" in "") ;; *) ${RANLIB} ${TEST_LIB};; esac - -clean: - rm -f ${LIB} ${LIBALTNAME} ${TEST_LIB} ${TESTS} ${TEST_OBJS} ${TEST_LIB_OBJS} ${LIB_OBJS} mkdep run_tests - -tests: ${TESTS} - -test: tests run_tests - PATH="$$PATH:." ./run_tests -b ${TESTS} - -partest: tests run_tests - PATH="$$PATH:." ./run_tests -p ${PAR_COUNT} -n ${PAR_SUB_COUNT} -b ${TESTS} - -run_tests: ${TOOLS}/run_tests.c - ${CC} ${TOOLS}/run_tests.c -o run_tests - -mkdep: ${TOOLS}/mkdep.c - ${CC} ${TOOLS}/mkdep.c -o mkdep - -depend: ${MKDEP_DEPEND} - ${MKDEP} ${CPPFLAGS} ${INTERNAL}/*.c ${TESTING}/*.c ${PLATFORM_C} \ - ${PLATFORM_S} ${PLATFORM_CXX} ${TEST_PLATFORM_C} > dependfile - -${PLATFORM_OBJS}: ${PLATFORM_C} ${PLATFORM_S} ${PLATFORM_CXX} - set -x; \ - for x in ${PLATFORM_C} $$empty; do ${CC} ${CFLAGS} -c $$x || exit 1; done; \ - for x in ${PLATFORM_S} $$empty; do o=`basename $$x .s`; ${AS} ${ASFLAGS} $$x -o `basename $$o .S`.o || exit 1; done; \ - for x in ${PLATFORM_CXX} $$empty; do ${CXX} ${CXXFLAGS} -c $$x || exit 1; done -${TEST_PLATFORM_OBJS}: ${TEST_PLATFORM_C}; set -x; for x in ${TEST_PLATFORM_C}; do ${CC} ${CFLAGS} -c $$x || exit 1; done - -common.o: ${INTERNAL}/common.c; ${CC} ${CFLAGS} -c ${INTERNAL}/common.c -counter.o: ${INTERNAL}/counter.c; ${CC} ${CFLAGS} -c ${INTERNAL}/counter.c -cv.o: ${INTERNAL}/cv.c; ${CC} ${CFLAGS} -c ${INTERNAL}/cv.c -debug.o: ${INTERNAL}/debug.c; ${CC} ${CFLAGS} -c ${INTERNAL}/debug.c -dll.o: ${INTERNAL}/dll.c; ${CC} ${CFLAGS} -c ${INTERNAL}/dll.c -mu.o: ${INTERNAL}/mu.c; ${CC} ${CFLAGS} -c ${INTERNAL}/mu.c -mu_wait.o: ${INTERNAL}/mu_wait.c; ${CC} ${CFLAGS} -c ${INTERNAL}/mu_wait.c -note.o: ${INTERNAL}/note.c; ${CC} ${CFLAGS} -c ${INTERNAL}/note.c -time_internal.o: ${INTERNAL}/time_internal.c; ${CC} ${CFLAGS} -c ${INTERNAL}/time_internal.c -once.o: ${INTERNAL}/once.c; ${CC} ${CFLAGS} -c ${INTERNAL}/once.c -sem_wait.o: ${INTERNAL}/sem_wait.c; ${CC} ${CFLAGS} -c ${INTERNAL}/sem_wait.c -wait.o: ${INTERNAL}/wait.c; ${CC} ${CFLAGS} -c ${INTERNAL}/wait.c - -array.o: ${TESTING}/array.c; ${CC} ${CFLAGS} -c ${TESTING}/array.c -atm_log.o: ${TESTING}/atm_log.c; ${CC} ${CFLAGS} -c ${TESTING}/atm_log.c -closure.o: ${TESTING}/closure.c; ${CC} ${CFLAGS} -c ${TESTING}/closure.c -counter_test.o: ${TESTING}/counter_test.c; ${CC} ${CFLAGS} -c ${TESTING}/counter_test.c -cv_mu_timeout_stress_test.o: ${TESTING}/cv_mu_timeout_stress_test.c; ${CC} ${CFLAGS} -c ${TESTING}/cv_mu_timeout_stress_test.c -cv_test.o: ${TESTING}/cv_test.c; ${CC} ${CFLAGS} -c ${TESTING}/cv_test.c -cv_wait_example_test.o: ${TESTING}/cv_wait_example_test.c; ${CC} ${CFLAGS} -c ${TESTING}/cv_wait_example_test.c -dll_test.o: ${TESTING}/dll_test.c; ${CC} ${CFLAGS} -c ${TESTING}/dll_test.c -mu_starvation_test.o: ${TESTING}/mu_starvation_test.c; ${CC} ${CFLAGS} -c ${TESTING}/mu_starvation_test.c -mu_test.o: ${TESTING}/mu_test.c; ${CC} ${CFLAGS} -c ${TESTING}/mu_test.c -mu_wait_example_test.o: ${TESTING}/mu_wait_example_test.c; ${CC} ${CFLAGS} -c ${TESTING}/mu_wait_example_test.c -mu_wait_test.o: ${TESTING}/mu_wait_test.c; ${CC} ${CFLAGS} -c ${TESTING}/mu_wait_test.c -note_test.o: ${TESTING}/note_test.c; ${CC} ${CFLAGS} -c ${TESTING}/note_test.c -once_test.o: ${TESTING}/once_test.c; ${CC} ${CFLAGS} -c ${TESTING}/once_test.c -time_extra.o: ${TESTING}/time_extra.c; ${CC} ${CFLAGS} -c ${TESTING}/time_extra.c -pingpong_test.o: ${TESTING}/pingpong_test.c; ${CC} ${CFLAGS} -c ${TESTING}/pingpong_test.c -smprintf.o: ${TESTING}/smprintf.c; ${CC} ${CFLAGS} -c ${TESTING}/smprintf.c -testing.o: ${TESTING}/testing.c; ${CC} ${CFLAGS} -c ${TESTING}/testing.c -wait_test.o: ${TESTING}/wait_test.c; ${CC} ${CFLAGS} -c ${TESTING}/wait_test.c - -counter_test: counter_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -cv_mu_timeout_stress_test: cv_mu_timeout_stress_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -cv_test: cv_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -cv_wait_example_test: cv_wait_example_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -dll_test: dll_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -mu_starvation_test: mu_starvation_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -mu_test: mu_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -mu_wait_example_test: mu_wait_example_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -mu_wait_test: mu_wait_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -note_test: note_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -once_test: once_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -pingpong_test: pingpong_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} -wait_test: wait_test.o ${TEST_LIB} ${LIB}; ${LD} ${LDFLAGS} -o $@ $@.o ${TEST_LIB} ${LIB} ${PLATFORM_LIBS} diff --git a/vendored/nsync/platform/posix/nsync_time_init.h b/vendored/nsync/platform/posix/nsync_time_init.h deleted file mode 100644 index fde8b9b7..00000000 --- a/vendored/nsync/platform/posix/nsync_time_init.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_POSIX_NSYNC_TIME_INIT_H_ -#define NSYNC_PLATFORM_POSIX_NSYNC_TIME_INIT_H_ - -#define NSYNC_TIME_STATIC_INIT(t,ns) { (t), (ns) } - -#endif /*NSYNC_PLATFORM_POSIX_NSYNC_TIME_INIT_H_*/ diff --git a/vendored/nsync/platform/posix/platform.h b/vendored/nsync/platform/posix/platform.h deleted file mode 100644 index c04c646a..00000000 --- a/vendored/nsync/platform/posix/platform.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_POSIX_PLATFORM_H_ -#define NSYNC_PLATFORM_POSIX_PLATFORM_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#endif /*NSYNC_PLATFORM_POSIX_PLATFORM_H_*/ diff --git a/vendored/nsync/platform/posix/platform_c++11_os.h b/vendored/nsync/platform/posix/platform_c++11_os.h deleted file mode 100644 index dcbd0a9f..00000000 --- a/vendored/nsync/platform/posix/platform_c++11_os.h +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ diff --git a/vendored/nsync/platform/posix/src/clock_gettime.c b/vendored/nsync/platform/posix/src/clock_gettime.c deleted file mode 100644 index d20ca191..00000000 --- a/vendored/nsync/platform/posix/src/clock_gettime.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -int clock_gettime(clockid_t clk_id UNUSED, struct timespec *tp) { - struct timeval tv; - int rc = gettimeofday(&tv, NULL); - if (rc == 0) { - tp->tv_sec = tv.tv_sec; - tp->tv_nsec = tv.tv_usec * 1000; - } - return (rc); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/posix/src/nsync_panic.c b/vendored/nsync/platform/posix/src/nsync_panic.c deleted file mode 100644 index 0aa5e196..00000000 --- a/vendored/nsync/platform/posix/src/nsync_panic.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -/* Write the nul-terminated string s[] to file descriptor fd. */ -static void writestr (int fd, const char *s) { - int len = strlen (s); - int n = 0; - while (len != 0 && n >= 0) { - n = write (fd, s, len); - if (n >= 0) { - len -= n; - s += n; - } else if (n == -1 && errno == EINTR) { - n = 0; - } - } -} - -/* Abort after printing the nul-terminated string s[]. */ -void nsync_panic_ (const char *s) { - writestr (2, "panic: "); - writestr (2, s); - abort (); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/posix/src/nsync_semaphore_mutex.c b/vendored/nsync/platform/posix/src/nsync_semaphore_mutex.c deleted file mode 100644 index 81cabcc3..00000000 --- a/vendored/nsync/platform/posix/src/nsync_semaphore_mutex.c +++ /dev/null @@ -1,92 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -#define ASSERT(x) do { if (!(x)) { *(volatile int *)0 = 0; } } while (0) - -struct mutex_cond { - pthread_mutex_t mu; - pthread_cond_t cv; - uint32_t i; -}; - -static nsync_semaphore *sem_big_enough_for_mutex_cond = - (nsync_semaphore *) (1 / - (sizeof (struct mutex_cond) <= sizeof (*sem_big_enough_for_mutex_cond))); - -/* Initialize *s; the initial value is 0. */ -void nsync_mu_semaphore_init (nsync_semaphore *s) { - struct mutex_cond *mc = (struct mutex_cond *) s; - ASSERT (pthread_mutex_init (&mc->mu, NULL) == 0); - ASSERT (pthread_cond_init (&mc->cv, NULL) == 0); - mc->i = 0; -} - -/* Wait until the count of *s exceeds 0, and decrement it. */ -void nsync_mu_semaphore_p (nsync_semaphore *s) { - struct mutex_cond *mc = (struct mutex_cond *) s; - ASSERT (pthread_mutex_lock (&mc->mu) == 0); - while (mc->i == 0) { - ASSERT (pthread_cond_wait (&mc->cv, &mc->mu) == 0); - } - mc->i = 0; - ASSERT (pthread_mutex_unlock (&mc->mu) == 0); -} - -/* Wait until one of: - the count of *s is non-zero, in which case decrement *s and return 0; - or abs_deadline expires, in which case return ETIMEDOUT. */ -int nsync_mu_semaphore_p_with_deadline (nsync_semaphore *s, - nsync_time abs_deadline) { - struct mutex_cond *mc = (struct mutex_cond *)s; - int res = 0; - ASSERT (pthread_mutex_lock (&mc->mu) == 0); - if (nsync_time_cmp (abs_deadline, nsync_time_no_deadline) == 0) { - while (mc->i == 0) { - ASSERT (pthread_cond_wait (&mc->cv, &mc->mu) == 0); - } - mc->i = 0; - } else { - struct timespec ts_deadline; - memset (&ts_deadline, 0, sizeof (ts_deadline)); - ts_deadline.tv_sec = NSYNC_TIME_SEC (abs_deadline); - ts_deadline.tv_nsec = NSYNC_TIME_NSEC (abs_deadline); - while (mc->i == 0 && - ((res = pthread_cond_timedwait (&mc->cv, &mc->mu, &ts_deadline)) == 0 || - (res == ETIMEDOUT && /* Various systems wake up too early. */ - nsync_time_cmp (abs_deadline, nsync_time_now ()) > 0))) { - } - ASSERT (res == 0 || res == ETIMEDOUT); - if (mc->i != 0) { - res = 0; - mc->i = 0; - } - } - ASSERT (pthread_mutex_unlock (&mc->mu) == 0); - return (res); -} - -/* Ensure that the count of *s is at least 1. */ -void nsync_mu_semaphore_v (nsync_semaphore *s) { - struct mutex_cond *mc = (struct mutex_cond *) s; - ASSERT (pthread_mutex_lock (&mc->mu) == 0); - mc->i = 1; - ASSERT (pthread_cond_broadcast (&mc->cv) == 0); - ASSERT (pthread_mutex_unlock (&mc->mu) == 0); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/posix/src/nsync_semaphore_sem_t.c b/vendored/nsync/platform/posix/src/nsync_semaphore_sem_t.c deleted file mode 100644 index 44b8485c..00000000 --- a/vendored/nsync/platform/posix/src/nsync_semaphore_sem_t.c +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -#define ASSERT(x) do { if (!(x)) { *(volatile int *)0 = 0; } } while (0) - -static nsync_semaphore *sem_big_enough_for_sem_t = (void *) (1 / - (sizeof (sem_t) <= sizeof (*sem_big_enough_for_sem_t))); - -/* Initialize *s; the initial value is 0. */ -void nsync_mu_semaphore_init (nsync_semaphore *s) { - ASSERT (sem_init ((sem_t *)s, 0, 0) == 0); -} - -/* Wait until the count of *s exceeds 0, and decrement it. */ -void nsync_mu_semaphore_p (nsync_semaphore *s) { - while (sem_wait ((sem_t *)s) != 0 && errno == EINTR) { - } -} - -/* Wait until one of: - the count of *s is non-zero, in which case decrement *s and return 0; - or abs_deadline expires, in which case return ETIMEDOUT. */ -int nsync_mu_semaphore_p_with_deadline (nsync_semaphore *s, - nsync_time abs_deadline) { - int result = 0; - if (nsync_time_cmp (abs_deadline, nsync_time_no_deadline) == 0) { - while (sem_wait ((sem_t *)s) != 0 && errno == EINTR) { - } - } else { - int rc; - struct timespec ts; - memset (&ts, 0, sizeof (ts)); - ts.tv_sec = NSYNC_TIME_SEC (abs_deadline); - ts.tv_nsec = NSYNC_TIME_NSEC (abs_deadline); - do { - rc = sem_timedwait ((sem_t *)s, &ts); - } while (rc != 0 && - (errno == EINTR || - (errno == ETIMEDOUT && - nsync_time_cmp (abs_deadline, nsync_time_now ()) > 0))); - if (rc != 0 && errno == ETIMEDOUT) { - result = ETIMEDOUT; - } - } - return (result); -} - -/* Ensure that the count of *s is at least 1. */ -void nsync_mu_semaphore_v (nsync_semaphore *s) { - ASSERT (sem_post ((sem_t *)s) == 0); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/posix/src/per_thread_waiter.c b/vendored/nsync/platform/posix/src/per_thread_waiter.c deleted file mode 100644 index d51bed0f..00000000 --- a/vendored/nsync/platform/posix/src/per_thread_waiter.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -static pthread_key_t waiter_key; -static nsync_atomic_uint32_ pt_once; - -static void do_once (nsync_atomic_uint32_ *ponce, void (*dest) (void *)) { - uint32_t o = ATM_LOAD_ACQ (ponce); - if (o != 2) { - while (o == 0 && !ATM_CAS_ACQ (ponce, 0, 1)) { - o = ATM_LOAD (ponce); - } - if (o == 0) { - pthread_key_create (&waiter_key, dest); - ATM_STORE_REL (ponce, 2); - } - while (ATM_LOAD_ACQ (ponce) != 2) { - sched_yield (); - } - } -} - -void *nsync_per_thread_waiter_ (void (*dest) (void *)) { - do_once (&pt_once, dest); - return (pthread_getspecific (waiter_key)); -} - -void nsync_set_per_thread_waiter_ (void *v, void (*dest) (void *)) { - do_once (&pt_once, dest); - pthread_setspecific (waiter_key, v); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/posix/src/start_thread.c b/vendored/nsync/platform/posix/src/start_thread.c deleted file mode 100644 index f6f6431a..00000000 --- a/vendored/nsync/platform/posix/src/start_thread.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -struct thd_args { - void (*f) (void *); - void *arg; -}; - -static void *body (void *v) { - struct thd_args *args = (struct thd_args *) v; - (*args->f) (args->arg); - free (args); - return (NULL); -} - -void nsync_start_thread_ (void (*f) (void *), void *arg) { - struct thd_args *args = (struct thd_args *) malloc (sizeof (*args)); - pthread_t t; - args->f = f; - args->arg = arg; - pthread_create (&t, NULL, body, args); - pthread_detach (t); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/posix/src/time_rep.c b/vendored/nsync/platform/posix/src/time_rep.c deleted file mode 100644 index 73c08618..00000000 --- a/vendored/nsync/platform/posix/src/time_rep.c +++ /dev/null @@ -1,95 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync_time_init.h" -#include "nsync_time.h" - -NSYNC_CPP_START_ - -#define NSYNC_NS_IN_S_ (1000 * 1000 * 1000) - -/* Return the maximum t, assuming it's an integral - type, and the representation is not too strange. */ -#define MAX_INT_TYPE(t) (((t)~(t)0) > 1? /*is t unsigned?*/ \ - (t)~(t)0 : /*unsigned*/ \ - (t) ((((uintmax_t)1) << (sizeof (t) * CHAR_BIT - 1)) - 1)) /*signed*/ - -const nsync_time nsync_time_no_deadline = - NSYNC_TIME_STATIC_INIT (MAX_INT_TYPE (time_t), NSYNC_NS_IN_S_ - 1); - -const nsync_time nsync_time_zero = NSYNC_TIME_STATIC_INIT (0, 0); - -nsync_time nsync_time_s_ns (time_t s, unsigned ns) { - nsync_time t; - memset (&t, 0, sizeof (t)); - t.tv_sec = s; - t.tv_nsec = ns; - return (t); -} - -nsync_time nsync_time_now (void) { - struct timespec ts; - clock_gettime (CLOCK_REALTIME, &ts); - return (ts); -} - -nsync_time nsync_time_sleep (nsync_time delay) { - struct timespec ts; - struct timespec remain; - memset (&ts, 0, sizeof (ts)); - ts.tv_sec = NSYNC_TIME_SEC (delay); - ts.tv_nsec = NSYNC_TIME_NSEC (delay); - if (nanosleep (&ts, &remain) == 0) { - /* nanosleep() is not required to fill in "remain" - if it returns 0. */ - memset (&remain, 0, sizeof (remain)); - } - return (remain); -} - -nsync_time nsync_time_add (nsync_time a, nsync_time b) { - a.tv_sec += b.tv_sec; - a.tv_nsec += b.tv_nsec; - if (a.tv_nsec >= NSYNC_NS_IN_S_) { - a.tv_nsec -= NSYNC_NS_IN_S_; - a.tv_sec++; - } - return (a); -} - -nsync_time nsync_time_sub (nsync_time a, nsync_time b) { - a.tv_sec -= b.tv_sec; - if (a.tv_nsec < b.tv_nsec) { - a.tv_nsec += NSYNC_NS_IN_S_; - a.tv_sec--; - } - a.tv_nsec -= b.tv_nsec; - return (a); -} - -int nsync_time_cmp (nsync_time a, nsync_time b) { - int cmp = (NSYNC_TIME_SEC (a) > NSYNC_TIME_SEC (b)) - - (NSYNC_TIME_SEC (a) < NSYNC_TIME_SEC (b)); - if (cmp == 0) { - cmp = (NSYNC_TIME_NSEC (a) > NSYNC_TIME_NSEC (b)) - - (NSYNC_TIME_NSEC (a) < NSYNC_TIME_NSEC (b)); - } - return (cmp); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/posix/src/time_rep_debug.c b/vendored/nsync/platform/posix/src/time_rep_debug.c deleted file mode 100644 index e98559da..00000000 --- a/vendored/nsync/platform/posix/src/time_rep_debug.c +++ /dev/null @@ -1,91 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" -#include "compiler.h" -#include "cputype.h" -#include "nsync_time_init.h" -#include "nsync_time.h" - -NSYNC_CPP_START_ - -#define NSYNC_NS_IN_S_ (1000 * 1000 * 1000) - -/* Return the maximum t, assuming it's an integral - type, and the representation is not too strange. */ -#define MAX_INT_TYPE(t) (((t)~(t)0) > 1? /*is t unsigned?*/ \ - (t)~(t)0 : /*unsigned*/ \ - (t) ((((uintmax_t)1) << (sizeof (t) * CHAR_BIT - 1)) - 1)) /*signed*/ - -const nsync_time nsync_time_no_deadline = - NSYNC_TIME_STATIC_INIT (MAX_INT_TYPE (time_t), NSYNC_NS_IN_S_ - 1); - -const nsync_time nsync_time_zero = NSYNC_TIME_STATIC_INIT (0, 0); - -nsync_time nsync_time_s_ns (time_t s, unsigned ns) { - nsync_time t; - t.seconds = s; - t.nanoseconds = ns; - return (t); -} - -nsync_time nsync_time_now (void) { - struct timespec ts; - clock_gettime (CLOCK_REALTIME, &ts); - return (nsync_time_s_ns (ts.tv_sec, ts.tv_nsec)); -} - -nsync_time nsync_time_sleep (nsync_time delay) { - struct timespec ts; - struct timespec remain; - ts.tv_sec = NSYNC_TIME_SEC (delay); - ts.tv_nsec = NSYNC_TIME_NSEC (delay); - if (nanosleep (&ts, &remain) == 0) { - memset (&remain, 0, sizeof (remain)); - } - return (nsync_time_s_ns (remain.tv_sec, remain.tv_nsec)); -} - -nsync_time nsync_time_add (nsync_time a, nsync_time b) { - a.seconds += b.seconds; - a.nanoseconds += b.nanoseconds; - if (a.nanoseconds >= NSYNC_NS_IN_S_) { - a.nanoseconds -= NSYNC_NS_IN_S_; - a.seconds++; - } - return (a); -} - -nsync_time nsync_time_sub (nsync_time a, nsync_time b) { - a.seconds -= b.seconds; - if (a.nanoseconds < b.nanoseconds) { - a.nanoseconds += NSYNC_NS_IN_S_; - a.seconds--; - } - a.nanoseconds -= b.nanoseconds; - return (a); -} - -int nsync_time_cmp (nsync_time a, nsync_time b) { - int cmp = (NSYNC_TIME_SEC (a) > NSYNC_TIME_SEC (b)) - - (NSYNC_TIME_SEC (a) < NSYNC_TIME_SEC (b)); - if (cmp == 0) { - cmp = (NSYNC_TIME_NSEC (a) > NSYNC_TIME_NSEC (b)) - - (NSYNC_TIME_NSEC (a) < NSYNC_TIME_NSEC (b)); - } - return (cmp); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/posix/src/yield.c b/vendored/nsync/platform/posix/src/yield.c deleted file mode 100644 index c0618f33..00000000 --- a/vendored/nsync/platform/posix/src/yield.c +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -void nsync_yield_ (void) { - sched_yield (); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/ppc32/cputype.h b/vendored/nsync/platform/ppc32/cputype.h deleted file mode 100644 index 1be36e4e..00000000 --- a/vendored/nsync/platform/ppc32/cputype.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_PPC32_CPUTYPE_H_ -#define NSYNC_PLATFORM_PPC32_CPUTYPE_H_ - -#define ATM_LD_IS_ACQ_ST_IS_REL_ 0 - -#endif /*NSYNC_PLATFORM_PPC32_CPUTYPE_H_*/ diff --git a/vendored/nsync/platform/ppc64/cputype.h b/vendored/nsync/platform/ppc64/cputype.h deleted file mode 100644 index b3724579..00000000 --- a/vendored/nsync/platform/ppc64/cputype.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_PPC64_CPUTYPE_H_ -#define NSYNC_PLATFORM_PPC64_CPUTYPE_H_ - -#define ATM_LD_IS_ACQ_ST_IS_REL_ 0 - -#endif /*NSYNC_PLATFORM_PPC64_CPUTYPE_H_*/ diff --git a/vendored/nsync/platform/ppc64/src/nsync_atm_ppc64.s b/vendored/nsync/platform/ppc64/src/nsync_atm_ppc64.s deleted file mode 100644 index d7e9a51b..00000000 --- a/vendored/nsync/platform/ppc64/src/nsync_atm_ppc64.s +++ /dev/null @@ -1,134 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -/* Helper routines for ppc64 implementation of atomic operations. */ - - .text - -/* Atomically: - int nsync_atm_cas_ (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - if (*p == old_value) { - *p = new_value; - return (some-non-zero-value); - } else { - return (0); - } - } - */ - .align 3 - .global nsync_atm_cas_ - .type nsync_atm_cas_, %function -nsync_atm_cas_: -1: - lwarx %r6,0,%r3 - cmpw %r4,%r6 - bne 2f - stwcx. %r5,0,%r3 - bne 1b - li %r3,1 - blr -2: - li %r3,0 - blr - -/* Like nsync_atm_cas_, but with acquire barrier semantics. */ - .align 3 - .global nsync_atm_cas_acq_ - .type nsync_atm_cas_acq_, %function -nsync_atm_cas_acq_: -1: - lwarx %r6,0,%r3 - cmpw %r4,%r6 - bne 2f - stwcx. %r5,0,%r3 - bne 1b - li %r3,1 - lwsync - blr -2: - li %r3,0 - blr - -/* Like nsync_atm_cas_, but with release barrier semantics. */ - .align 3 - .global nsync_atm_cas_rel_ - .type nsync_atm_cas_rel_, %function -nsync_atm_cas_rel_: - lwsync -1: - lwarx %r6,0,%r3 - cmpw %r4,%r6 - bne 2f - stwcx. %r5,0,%r3 - bne 1b - li %r3,1 - blr -2: - li %r3,0 - blr - -/* Like nsync_atm_cas_, but with both acquire and release barrier semantics. */ - .align 3 - .global nsync_atm_cas_relacq_ - .type nsync_atm_cas_relacq_, %function -nsync_atm_cas_relacq_: - lwsync -1: - lwarx %r6,0,%r3 - cmpw %r4,%r6 - bne 2f - stwcx. %r5,0,%r3 - bne 1b - li %r3,1 - lwsync - blr -2: - li %r3,0 - blr - -/* Atomically: - uint32_t nsync_atm_load_ (nsync_atomic_uint32_ *p) { return (*p); } */ - .align 3 - .global nsync_atm_load_ - .type nsync_atm_load_, %function -nsync_atm_load_: - lwz %r3,0(%r3) - blr - -/* Like nsync_atm_load_, but with acquire barrier semantics. */ - .align 3 - .global nsync_atm_load_acq_ - .type nsync_atm_load_acq_, %function -nsync_atm_load_acq_: - lwz %r3,0(%r3) - lwsync - blr - -/* Atomically: - void nsync_atm_store_ (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } */ - .align 3 - .global nsync_atm_store_ - .type nsync_atm_store_, %function -nsync_atm_store_: - stw %r4,0(%r3) - blr - -/* Like nsync_atm_store_, but with release barrier semantics. */ - .align 3 - .global nsync_atm_store_rel_ - .type nsync_atm_store_rel_, %function -nsync_atm_store_rel_: - lwsync - stw %r4,0(%r3) - blr diff --git a/vendored/nsync/platform/win32/atomic.h b/vendored/nsync/platform/win32/atomic.h deleted file mode 100644 index c5532c85..00000000 --- a/vendored/nsync/platform/win32/atomic.h +++ /dev/null @@ -1,122 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_WIN32_ATOMIC_H_ -#define NSYNC_PLATFORM_WIN32_ATOMIC_H_ - -/* Atomic operations on nsync_atomic_uint32_ quantities - CAS, load, and store. - - Normally, these are used only on nsync_atomic_uint32_ values, but on Linux they may be - invoked on int values, because futexes operate on int values. A - compile-time check in the futex code ensures that both int and - nsync_atomic_uint32_ are 32 bits. - - Memory barriers: - Operations with the suffixes _ACQ and _RELACQ ensure that the operation - appears to complete before other memory operations subsequently performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_ACQ, - this applies only if the operation returns a non-zero value.) - - Operations with the suffixes _REL and _RELACQ ensure that the operation - appears to complete after other memory operations previously performed by - the same thread, as seen by other threads. (In the case of ATM_CAS_REL, - this applies only if the operation returns a non-zero value.) - - // Atomically, - // int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - // if (*p == old_value) { - // *p = new_value; - // return (some-non-zero-value); - // } else { - // return (0); - // } - // } - // *_ACQ, *_REL, *_RELACQ variants are available, - // with the barrier semantics described above. - int ATM_CAS (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value); - - // Atomically, - // uint32_t ATM_LOAD (nsync_atomic_uint32_ *p) { return (*p); } - // A *_ACQ variant is available, - // with the barrier semantics described above. - uint32_t ATM_LOAD (nsync_atomic_uint32_ *p); - - // Atomically, - // void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } - // A *_REL variant is available, - // with the barrier semantics described above. - void ATM_STORE (nsync_atomic_uint32_ *p, uint32_t value); - */ - -#include "compiler.h" -#include "nsync_atomic.h" -#include -#include - -NSYNC_CPP_START_ - -#define ATM_MB_() MemoryBarrier () - -#if ATM_LD_IS_ACQ_ST_IS_REL_ -#define ATM_CB_() _ReadWriteBarrier () /* compiler barrier */ -#define ATM_LD_ACQ_ ATM_CB_ -#define ATM_ST_REL_ ATM_CB_ -#else -#define ATM_LD_ACQ_ ATM_MB_ -#define ATM_ST_REL_ ATM_MB_ -#endif - -static INLINE int atm_cas_nomb_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { - /* InterlockedCompareExchangeNoFence unavailable before Windows 8 */ - return (InterlockedCompareExchange ( - (LONG volatile *) NSYNC_ATOMIC_UINT32_PTR_ (p), n, o) == o); -} - -static INLINE int atm_cas_barrier_u32_ (nsync_atomic_uint32_ *p, uint32_t o, uint32_t n) { - /* InterlockedCompareExchangeAcquire unavailable before Windows Vista */ - return (InterlockedCompareExchange ( - (LONG volatile *) NSYNC_ATOMIC_UINT32_PTR_ (p), n, o) == o); -} - -#define ATM_CAS(p,o,n) (atm_cas_nomb_u32_ ((p),(o),(n))) -#define ATM_CAS_ACQ(p,o,n) (atm_cas_barrier_u32_ ((p),(o),(n))) -#define ATM_CAS_REL(p,o,n) (atm_cas_barrier_u32_ ((p),(o),(n))) -#define ATM_CAS_RELACQ(p,o,n) (atm_cas_barrier_u32_ ((p),(o),(n))) - -/*----*/ - -static INLINE uint32_t atm_load_acq_u32_ (nsync_atomic_uint32_ *p) { - uint32_t result = NSYNC_ATOMIC_UINT32_LOAD_ ((volatile nsync_atomic_uint32_ *)p); - ATM_LD_ACQ_ (); - return (result); -} - -#define ATM_LOAD(p) (NSYNC_ATOMIC_UINT32_LOAD_ ((volatile nsync_atomic_uint32_ *)(p))) -#define ATM_LOAD_ACQ(p) (atm_load_acq_u32_ (p)) - -/*----*/ - -#define ATM_STORE_X_(p,v,b,a) do { \ - b; \ - NSYNC_ATOMIC_UINT32_STORE_ ((volatile nsync_atomic_uint32_ *)(p), (uint32_t) (v)); \ - a; \ - } while (0) - -#define ATM_STORE(p,v) ATM_STORE_X_ ((p), (v), ; , ; ) -#define ATM_STORE_REL(p,v) ATM_STORE_X_ ((p), (v), ATM_ST_REL_ (), ; ) - -NSYNC_CPP_END_ - -#endif /*NSYNC_PLATFORM_WIN32_ATOMIC_H_*/ diff --git a/vendored/nsync/platform/win32/platform.h b/vendored/nsync/platform/win32/platform.h deleted file mode 100644 index d58601ec..00000000 --- a/vendored/nsync/platform/win32/platform.h +++ /dev/null @@ -1,108 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_WIN32_PLATFORM_H_ -#define NSYNC_PLATFORM_WIN32_PLATFORM_H_ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "compiler.h" -#include "nsync_cpp.h" - -extern int write (int, const char *, size_t); - -/* Avoid deprecation/safety warning for tmpfile() */ -#define tmpfile nsync_tmpfile_wrapper -static inline FILE *nsync_tmpfile_wrapper (void) { - FILE *fp; - if (tmpfile_s (&fp) != 0) { - fp = NULL; - } - return (fp); -} - -NSYNC_C_START_ -/* Can't use TlsAlloc() because we use pthread_key_create's destructor - argument, so we implement it anew. */ -#define pthread_key_t nsync_pthread_key_t -typedef int nsync_pthread_key_t; -int nsync_pthread_key_create (nsync_pthread_key_t *pkey, void (*dest) (void *)); -int nsync_pthread_key_delete (nsync_pthread_key_t key); -void *nsync_pthread_getspecific (nsync_pthread_key_t key); -int nsync_pthread_setspecific (nsync_pthread_key_t key, void *value); -#define pthread_key_create nsync_pthread_key_create -#define pthread_key_delete nsync_pthread_key_delete -#define pthread_getspecific nsync_pthread_getspecific -#define pthread_setspecific nsync_pthread_setspecific -NSYNC_C_END_ - -NSYNC_CPP_START_ - -#define CLOCK_REALTIME 0 -#define TIMER_ABSTIME 1 -#define clockid_t nsync_clockid_t -typedef int nsync_clockid_t; -int nsync_clock_gettime (clockid_t clk_id, struct timespec *tp); -#define clock_gettime nsync_clock_gettime -int nsync_nanosleep(const struct timespec *delay, struct timespec *remaining); -#define nanosleep nsync_nanosleep - -#define pthread_mutex_t CRITICAL_SECTION -#define pthread_mutex_lock EnterCriticalSection -#define pthread_mutex_unlock LeaveCriticalSection -#define pthread_mutex_init(mu,attr) InitializeCriticalSection (mu) -#define pthread_mutex_destroy DeleteCriticalSection - -#define pthread_cond_t CONDITION_VARIABLE -#define pthread_cond_broadcast WakeAllConditionVariable -#define pthread_cond_signal WakeConditionVariable -#define pthread_cond_wait(cv, mu) SleepConditionVariableCS ((cv), (mu), INFINITE) -#define pthread_cond_timedwait nsync_pthread_cond_timedwait -#define pthread_cond_init(cv, attr) InitializeConditionVariable (cv) -#define pthread_cond_destroy(cv) /*no-op*/ -int nsync_pthread_cond_timedwait (pthread_cond_t *cv, pthread_mutex_t *mu, - const struct timespec *abstimeout); - -typedef struct { - SRWLOCK srw; - int w; -} nsync_pthread_rwlock_t; -#define pthread_rwlock_t nsync_pthread_rwlock_t -#define pthread_rwlock_wrlock(rw) do { AcquireSRWLockExclusive (&(rw)->srw); (rw)->w = 1; } while (0) -#define pthread_rwlock_rdlock(rw) AcquireSRWLockShared (&(rw)->srw) -#define pthread_rwlock_unlock(rw) do { if ((rw)->w) { (rw)->w = 0; ReleaseSRWLockExclusive (&(rw)->srw); } else { ReleaseSRWLockShared (&(rw)->srw); } } while (0) -#define pthread_rwlock_init(rw,attr) do { InitializeSRWLock (&(rw)->srw); (rw)->w = 0; } while (0) -#define pthread_rwlock_destroy(rw) /*no-op*/ - - -#define pthread_once_t INIT_ONCE -#define PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT -extern BOOL CALLBACK nsync_init_callback_ (pthread_once_t *o, void *v, void **c); -#define pthread_once(o, f) do { \ - void (*ff) = (f); \ - InitOnceExecuteOnce ((o), &nsync_init_callback_, &ff, NULL); \ - } while (0) - -#define sched_yield() Sleep(0) - -NSYNC_CPP_END_ - -#endif /*NSYNC_PLATFORM_WIN32_PLATFORM_H_*/ diff --git a/vendored/nsync/platform/win32/platform_c++11_os.h b/vendored/nsync/platform/win32/platform_c++11_os.h deleted file mode 100644 index c4991541..00000000 --- a/vendored/nsync/platform/win32/platform_c++11_os.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_WIN32_PLATFORM_CPP_OS_H_ -#define NSYNC_PLATFORM_WIN32_PLATFORM_CPP_OS_H_ - -/* Windows doesn't implement clock_gettime(). */ -#include - -#define clock_gettime nsync_clock_gettime - -#define CLOCK_REALTIME 0 -#define TIMER_ABSTIME 1 - -NSYNC_CPP_START_ -typedef int clockid_t; -int clock_gettime (clockid_t clk_id, struct timespec *tp); -NSYNC_CPP_END_ - -/* Avoid deprecation/safety warning for tmpfile(). - This is used for the C++11 build. The copy in - win32/platform.h is used for the win32 "native" build. */ -#define tmpfile nsync_tmpfile_wrapper -static inline FILE *nsync_tmpfile_wrapper (void) { - FILE *fp; - if (tmpfile_s (&fp) != 0) { - fp = NULL; - } - return (fp); -} - -/* Windows lacks pthread_key_t. */ -#include "Windows.h" -#define sched_yield() Sleep(0) -NSYNC_C_START_ -/* Can't use TlsAlloc() because we use pthread_key_create's destructor - argument, so we implement it anew. */ -#define pthread_key_t nsync_pthread_key_t -typedef int nsync_pthread_key_t; -int nsync_pthread_key_create (nsync_pthread_key_t *pkey, void (*dest) (void *)); -int nsync_pthread_key_delete (nsync_pthread_key_t key); -void *nsync_pthread_getspecific (nsync_pthread_key_t key); -int nsync_pthread_setspecific (nsync_pthread_key_t key, void *value); -#define pthread_key_create nsync_pthread_key_create -#define pthread_key_delete nsync_pthread_key_delete -#define pthread_getspecific nsync_pthread_getspecific -#define pthread_setspecific nsync_pthread_setspecific -NSYNC_C_END_ - -#endif /*NSYNC_PLATFORM_WIN32_PLATFORM_CPP_OS_H_*/ diff --git a/vendored/nsync/platform/win32/src/clock_gettime.c b/vendored/nsync/platform/win32/src/clock_gettime.c deleted file mode 100644 index 555fb327..00000000 --- a/vendored/nsync/platform/win32/src/clock_gettime.c +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -int nsync_clock_gettime (clockid_t clk_id UNUSED, struct timespec *tp) { - struct timeb tb; - ftime (&tb); - tp->tv_sec = tb.time; - tp->tv_nsec = tb.millitm * 1000 * 1000; - return (0); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/win32/src/init_callback_win32.c b/vendored/nsync/platform/win32/src/init_callback_win32.c deleted file mode 100644 index d349b4e8..00000000 --- a/vendored/nsync/platform/win32/src/init_callback_win32.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "platform.h" - -NSYNC_CPP_START_ - -typedef void (*init_once_fn_) (void); -BOOL CALLBACK nsync_init_callback_ (pthread_once_t *o, void *v, void **c) { - init_once_fn_ *f = (init_once_fn_ *) v; - (**f) (); - return (TRUE); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/win32/src/nanosleep.c b/vendored/nsync/platform/win32/src/nanosleep.c deleted file mode 100644 index 61b2a789..00000000 --- a/vendored/nsync/platform/win32/src/nanosleep.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -int nsync_nanosleep (const struct timespec *request, struct timespec *remain) { - time_t x = request->tv_sec; - while (x > 1000) { - x -= 1000; - Sleep (1000 * 1000); - } - Sleep ((unsigned) (x * 1000 + (request->tv_nsec + 999999) / (1000 * 1000))); - if (remain != NULL) { - memset (remain, 0, sizeof (*remain)); - } - return (0); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/win32/src/nsync_semaphore_win32.c b/vendored/nsync/platform/win32/src/nsync_semaphore_win32.c deleted file mode 100644 index d34faca8..00000000 --- a/vendored/nsync/platform/win32/src/nsync_semaphore_win32.c +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include -#include -#include "nsync_cpp.h" -#include "nsync_time.h" -#include "sem.h" - -NSYNC_CPP_START_ - -/* Initialize *s; the initial value is 0. */ -void nsync_mu_semaphore_init (nsync_semaphore *s) { - HANDLE *h = (HANDLE *) s; - *h = CreateSemaphore(NULL, 0, 1, NULL); - if (*h == NULL) { - abort (); - } -} - -/* Wait until the count of *s exceeds 0, and decrement it. */ -void nsync_mu_semaphore_p (nsync_semaphore *s) { - HANDLE *h = (HANDLE *) s; - WaitForSingleObject(*h, INFINITE); -} - -/* Wait until one of: - the count of *s is non-zero, in which case decrement *s and return 0; - or abs_deadline expires, in which case return ETIMEDOUT. */ -int nsync_mu_semaphore_p_with_deadline (nsync_semaphore *s, nsync_time abs_deadline) { - HANDLE *h = (HANDLE *) s; - int result; - - if (nsync_time_cmp (abs_deadline, nsync_time_no_deadline) == 0) { - result = WaitForSingleObject(*h, INFINITE); - } else { - nsync_time now; - now = nsync_time_now (); - do { - if (nsync_time_cmp (abs_deadline, now) <= 0) { - result = WaitForSingleObject (*h, 0); - } else { - nsync_time delay; - delay = nsync_time_sub (abs_deadline, now); - if (NSYNC_TIME_SEC (delay) > 1000*1000) { - result = WaitForSingleObject (*h, 1000*1000); - } else { - result = WaitForSingleObject (*h, - (unsigned) (NSYNC_TIME_SEC (delay) * 1000 + - (NSYNC_TIME_NSEC (delay) + 999999) / (1000 * 1000))); - } - } - if (result == WAIT_TIMEOUT) { - now = nsync_time_now (); - } - } while (result == WAIT_TIMEOUT && /* Windows generates early wakeups. */ - nsync_time_cmp (abs_deadline, now) > 0); - } - return (result == WAIT_TIMEOUT? ETIMEDOUT : 0); -} - -/* Ensure that the count of *s is at least 1. */ -void nsync_mu_semaphore_v (nsync_semaphore *s) { - HANDLE *h = (HANDLE *) s; - ReleaseSemaphore(*h, 1, NULL); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/win32/src/per_thread_waiter.c b/vendored/nsync/platform/win32/src/per_thread_waiter.c deleted file mode 100644 index d51bed0f..00000000 --- a/vendored/nsync/platform/win32/src/per_thread_waiter.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -static pthread_key_t waiter_key; -static nsync_atomic_uint32_ pt_once; - -static void do_once (nsync_atomic_uint32_ *ponce, void (*dest) (void *)) { - uint32_t o = ATM_LOAD_ACQ (ponce); - if (o != 2) { - while (o == 0 && !ATM_CAS_ACQ (ponce, 0, 1)) { - o = ATM_LOAD (ponce); - } - if (o == 0) { - pthread_key_create (&waiter_key, dest); - ATM_STORE_REL (ponce, 2); - } - while (ATM_LOAD_ACQ (ponce) != 2) { - sched_yield (); - } - } -} - -void *nsync_per_thread_waiter_ (void (*dest) (void *)) { - do_once (&pt_once, dest); - return (pthread_getspecific (waiter_key)); -} - -void nsync_set_per_thread_waiter_ (void *v, void (*dest) (void *)) { - do_once (&pt_once, dest); - pthread_setspecific (waiter_key, v); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/win32/src/pthread_cond_timedwait_win32.c b/vendored/nsync/platform/win32/src/pthread_cond_timedwait_win32.c deleted file mode 100644 index 1bfbac48..00000000 --- a/vendored/nsync/platform/win32/src/pthread_cond_timedwait_win32.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "nsync_cpp.h" -#include "platform.h" - -NSYNC_CPP_START_ - -int nsync_pthread_cond_timedwait (pthread_cond_t *cv, pthread_mutex_t *mu, - const struct timespec *abs_deadline) { - int result; - if (abs_deadline == NULL) { - result = SleepConditionVariableCS (cv, mu, INFINITE); - } else { - int again; - do { - struct timespec now; - again = 0; - clock_gettime (CLOCK_REALTIME, &now); - if (abs_deadline->tv_sec < now.tv_sec || - (abs_deadline->tv_sec == now.tv_sec && abs_deadline->tv_nsec <= now.tv_nsec)) { - result = SleepConditionVariableCS (cv, mu, 0); - } else { - struct timespec delay; - delay = *abs_deadline; - delay.tv_sec -= now.tv_sec; - if (delay.tv_nsec < now.tv_nsec) { - delay.tv_nsec += 1000 * 1000 * 1000; - delay.tv_sec--; - } - delay.tv_nsec -= now.tv_nsec; - if (delay.tv_sec > 1000*1000) { - result = SleepConditionVariableCS (cv, mu, 1000*1000); - again = (result == ERROR_TIMEOUT); - } else { - result = SleepConditionVariableCS (cv, mu, - (unsigned) (delay.tv_sec * 1000 + - (delay.tv_nsec + 999999) / (1000 * 1000))); - if (result == ERROR_TIMEOUT) { - /* Windows often generates early wakeups. */ - clock_gettime (CLOCK_REALTIME, &now); - again = (abs_deadline->tv_sec > now.tv_sec || - (abs_deadline->tv_sec == now.tv_sec && - abs_deadline->tv_nsec > now.tv_nsec)); - } - } - } - } while (again); - } - return (result == ERROR_TIMEOUT? ETIMEDOUT : 0); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/win32/src/pthread_key_win32.cc b/vendored/nsync/platform/win32/src/pthread_key_win32.cc deleted file mode 100644 index df00c3d1..00000000 --- a/vendored/nsync/platform/win32/src/pthread_key_win32.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -// Struct representing an element of the "dest" array, whose elements -// indicate the destructor asscoaied with the corresponding key. -namespace { -struct KeyDestructor { - bool allocated; // Whether this key is allocated. - pthread_key_t key; // Last used version of key. - void (*dest) (void *); // Destructor for the key, or nullptr. -}; -} // anonymous namespace - - -static SRWLOCK mu = SRWLOCK_INIT; // protects dest. -static const int kMaxKeyShift = 7; -static const int kMaxKeys = 1 << kMaxKeyShift; -static const int kKeyMask = kMaxKeys - 1; -static KeyDestructor dest[kMaxKeys]; // Destructors for keys. - -// Element per key per thread. -namespace { -struct KeyValue { - pthread_key_t key; // last key stored - void *value; -}; -} // anonymous namespace - -// Each thread has a class instance that represents an array of pointers -// to client-specified thread-specific data. -// The class destructor calls the key destructors when the accociated -// thread exits. -namespace { - -class PerThreadData { - public: - PerThreadData() { - } - ~PerThreadData(); - void *value(pthread_key_t key) { - void *result = 0; - int i = key & kKeyMask; - if (this->array_[i].key == key) { - result = this->array_[i].value; - } - return (result); - } - void set_value(pthread_key_t key, void *value) { - int i = key & kKeyMask; - this->array_[i].key = key; - this->array_[i].value = value; - } - private: - KeyValue array_[kMaxKeys]; -}; - -PerThreadData::~PerThreadData() { - bool again = true; - // Try a few times to clear the thread's array. - for (int attempt = 0; attempt != 4 && again; attempt++) { - again = false; - // Take a snapshot of the destructor state. - AcquireSRWLockExclusive (&mu); - KeyDestructor dest_copy[kMaxKeys]; - memcpy (dest_copy, dest, sizeof (dest_copy)); - ReleaseSRWLockExclusive(&mu); - // Iterate over the values, calling destructors - // when both destructor and value are non-nil. - for (int i = 1; i != kMaxKeys; i++) { - if (dest_copy[i].allocated) { - void (*destructor) (void *) = dest_copy[i].dest; - void *value = this->array_[i].value; - this->array_[i].value = nullptr; - if (dest_copy[i].key == this->array_[i].key && - destructor != nullptr && value != nullptr) { - again = true; // in case destructors set values. - (*destructor) (value); - } - } - } - } -} -} // anonymous namespace - -static __declspec(thread) class PerThreadData per_thread_data; - -NSYNC_C_START_ - -int nsync_pthread_key_create (pthread_key_t *pkey, void (*destructor) (void *)) { - int result = EAGAIN; - int i; - AcquireSRWLockExclusive (&mu); - // Search for an unused slot. Slot 1 is never used. - for (i = 1; i != kMaxKeys && dest[i].allocated; i++) { - } - if (i != kMaxKeys) { // found one - dest[i].allocated = true; - dest[i].dest = destructor; - dest[i].key += kMaxKeys; // High bits are version number. - dest[i].key |= i; // Low bits are slot number. - *pkey = dest[i].key; - result = 0; - } - ReleaseSRWLockExclusive(&mu); - return (result); -} - -int nsync_pthread_key_delete (pthread_key_t key) { - int result = EINVAL; - int i = key & kKeyMask; - AcquireSRWLockExclusive (&mu); - if (key > 0 && dest[i].allocated) { - dest[i].allocated = false; - dest[i].dest = nullptr; - result = 0; - } - ReleaseSRWLockExclusive(&mu); - return (result); -} - -void *nsync_pthread_getspecific (pthread_key_t key) { - return (per_thread_data.value (key)); -} - -int nsync_pthread_setspecific (pthread_key_t key, void *value) { - int result = EINVAL; - if (key > 0) { - per_thread_data.set_value (key, value); - result = 0; - } - return (result); -} - -NSYNC_C_END_ diff --git a/vendored/nsync/platform/win32/src/start_thread.c b/vendored/nsync/platform/win32/src/start_thread.c deleted file mode 100644 index e96fbcc0..00000000 --- a/vendored/nsync/platform/win32/src/start_thread.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#include "headers.h" - -NSYNC_CPP_START_ - -struct nsync_thd_args { - void (*f) (void *); - void *arg; -}; - -static DWORD WINAPI body (void *v) { - struct nsync_thd_args *args = (struct nsync_thd_args *) v; - (*args->f) (args->arg); - free (args); - return (0); -} - -void nsync_start_thread_ (void (*f) (void *), void *arg) { - struct nsync_thd_args *args = (struct nsync_thd_args *) malloc (sizeof (*args)); - HANDLE t; - args->f = f; - args->arg = arg; - t = CreateThread (NULL, 0, &body, args, 0, NULL); - CloseHandle (t); -} - -NSYNC_CPP_END_ diff --git a/vendored/nsync/platform/x86_32/cputype.h b/vendored/nsync/platform/x86_32/cputype.h deleted file mode 100644 index 191140b1..00000000 --- a/vendored/nsync/platform/x86_32/cputype.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_X86_32_CPUTYPE_H_ -#define NSYNC_PLATFORM_X86_32_CPUTYPE_H_ - -#define ATM_LD_IS_ACQ_ST_IS_REL_ 1 - -#endif /*NSYNC_PLATFORM_X86_32_CPUTYPE_H_*/ diff --git a/vendored/nsync/platform/x86_32/src/nsync_atm_x86_32.s b/vendored/nsync/platform/x86_32/src/nsync_atm_x86_32.s deleted file mode 100644 index 1dac65ad..00000000 --- a/vendored/nsync/platform/x86_32/src/nsync_atm_x86_32.s +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -/* Helper routines for x86_32 implementation of atomic operations. */ - -/* Atomically, with acquire and release barrier semantics, - int nsync_atm_cas_ (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - if (*p == old_value) { - *p = new_value; - return (some-non-zero-value); - } else { - return (0); - } - } - */ - .text - .globl nsync_atm_cas_ - .globl nsync_atm_cas_acq_ - .globl nsync_atm_cas_rel_ - .globl nsync_atm_cas_relacq_ - .type nsync_atm_cas_, @function -nsync_atm_cas_: -nsync_atm_cas_acq_: -nsync_atm_cas_rel_: -nsync_atm_cas_relacq_: - movl %esp, %eax - movl 4(%eax), %edx - movl 12(%eax), %ecx - movl 8(%eax), %eax - lock cmpxchgl %ecx, (%edx) - movl $0, %eax - sete %al - ret - -/* Atomically, with acquire barrier semantics, - uint32_t nsync_atm_load_ (nsync_atomic_uint32_ *p) { return (*p); } */ - .globl nsync_atm_load_ - .globl nsync_atm_load_acq_ - .type nsync_atm_load_, @function -nsync_atm_load_: -nsync_atm_load_acq_: - movl %esp, %eax - movl 4(%eax), %eax - movl (%eax), %eax - ret - -/* Atomically, with release barrier semantics, - void nsync_atm_store_ (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } */ - .globl nsync_atm_store_ - .globl nsync_atm_store_rel_ - .type nsync_atm_store_, @function -nsync_atm_store_: -nsync_atm_store_rel_: - movl %esp, %eax - movl 8(%eax), %edx - movl 4(%eax), %eax - movl %edx, (%eax) - ret diff --git a/vendored/nsync/platform/x86_64/cputype.h b/vendored/nsync/platform/x86_64/cputype.h deleted file mode 100644 index f654daa9..00000000 --- a/vendored/nsync/platform/x86_64/cputype.h +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PLATFORM_X86_64_CPUTYPE_H_ -#define NSYNC_PLATFORM_X86_64_CPUTYPE_H_ - -#define ATM_LD_IS_ACQ_ST_IS_REL_ 1 - -#endif /*NSYNC_PLATFORM_X86_64_CPUTYPE_H_*/ diff --git a/vendored/nsync/platform/x86_64/src/nsync_atm_x86_64.s b/vendored/nsync/platform/x86_64/src/nsync_atm_x86_64.s deleted file mode 100644 index 6c04e5c9..00000000 --- a/vendored/nsync/platform/x86_64/src/nsync_atm_x86_64.s +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -/* Helper routines for x86_64 implementation of atomic operations. */ - -/* Atomically, with acquire and release barrier semantics, - int nsync_atm_cas_ (nsync_atomic_uint32_ *p, uint32_t old_value, uint32_t new_value) { - if (*p == old_value) { - *p = new_value; - return (some-non-zero-value); - } else { - return (0); - } - } - */ - .text - .globl nsync_atm_cas_ - .globl nsync_atm_cas_acq_ - .globl nsync_atm_cas_rel_ - .globl nsync_atm_cas_relacq_ - .type nsync_atm_cas_, @function -nsync_atm_cas_: -nsync_atm_cas_acq_: -nsync_atm_cas_rel_: -nsync_atm_cas_relacq_: - movl %esi, %eax - lock cmpxchgl %edx, (%rdi) - movl $0, %eax - sete %al - ret - -/* Atomically, with acquire barrier semantics, - uint32_t nsync_atm_load_ (nsync_atomic_uint32_ *p) { return (*p); } */ - .globl nsync_atm_load_ - .globl nsync_atm_load_acq_ - .type nsync_atm_load_, @function -nsync_atm_load_: -nsync_atm_load_acq_: - movl (%rdi), %eax - ret - -/* Atomically, with release barrier semantics, - void nsync_atm_store_ (nsync_atomic_uint32_ *p, uint32_t value) { *p = value; } */ - .globl nsync_atm_store_ - .globl nsync_atm_store_rel_ - .type nsync_atm_store_, @function -nsync_atm_store_: -nsync_atm_store_rel_: - movl %esi, (%rdi) - ret diff --git a/vendored/nsync/public/nsync.h b/vendored/nsync/public/nsync.h deleted file mode 100644 index 7feb9cc8..00000000 --- a/vendored/nsync/public/nsync.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_H_ -#define NSYNC_PUBLIC_NSYNC_H_ - -#include "nsync_mu.h" -#include "nsync_mu_wait.h" -#include "nsync_cv.h" -#include "nsync_note.h" -#include "nsync_counter.h" -#include "nsync_waiter.h" -#include "nsync_once.h" -#include "nsync_debug.h" - -#endif /*NSYNC_PUBLIC_NSYNC_H_*/ diff --git a/vendored/nsync/public/nsync_atomic.h b/vendored/nsync/public/nsync_atomic.h deleted file mode 100644 index b7066231..00000000 --- a/vendored/nsync/public/nsync_atomic.h +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_ATOMIC_H_ -#define NSYNC_PUBLIC_NSYNC_ATOMIC_H_ - -#include "nsync_cpp.h" - -/* This file is not to be included directly by the client. It exists because - on some platforms, one cannot use a simple uint32_t with atomic operations. - */ -#if NSYNC_ATOMIC_TYPECHECK -#include -NSYNC_CPP_START_ -typedef struct { uint32_t value; } nsync_atomic_uint32_; -NSYNC_CPP_END_ -#define NSYNC_ATOMIC_UINT32_INIT_ { 0 } -#define NSYNC_ATOMIC_UINT32_LOAD_(p) ((p)->value) -#define NSYNC_ATOMIC_UINT32_STORE_(p,v) ((p)->value = (v)) -#define NSYNC_ATOMIC_UINT32_PTR_(p) (&(p)->value) - -#elif NSYNC_ATOMIC_C11 -#include -NSYNC_CPP_START_ -typedef atomic_uint_least32_t nsync_atomic_uint32_; -NSYNC_CPP_END_ -#define NSYNC_ATOMIC_UINT32_INIT_ 0 -#define NSYNC_ATOMIC_UINT32_LOAD_(p) (*(p)) -#define NSYNC_ATOMIC_UINT32_STORE_(p,v) (*(p) = (v)) -#define NSYNC_ATOMIC_UINT32_PTR_(p) (p) - -#elif NSYNC_ATOMIC_CPP11 -#include -NSYNC_CPP_START_ -typedef std::atomic nsync_atomic_uint32_; -NSYNC_CPP_END_ -#define NSYNC_ATOMIC_UINT32_INIT_ { 0 } -#define NSYNC_ATOMIC_UINT32_LOAD_(p) (std::atomic_load (p)) -#define NSYNC_ATOMIC_UINT32_STORE_(p,v) (std::atomic_store ((p), (uint32_t) (v))) -#define NSYNC_ATOMIC_UINT32_PTR_(p) (p) - -#else -#include -NSYNC_CPP_START_ -typedef uint32_t nsync_atomic_uint32_; -NSYNC_CPP_END_ -#define NSYNC_ATOMIC_UINT32_INIT_ 0 -#define NSYNC_ATOMIC_UINT32_LOAD_(p) (*(p)) -#define NSYNC_ATOMIC_UINT32_STORE_(p,v) (*(p) = (v)) -#define NSYNC_ATOMIC_UINT32_PTR_(p) (p) -#endif - -#endif /*NSYNC_PUBLIC_NSYNC_ATOMIC_H_*/ diff --git a/vendored/nsync/public/nsync_counter.h b/vendored/nsync/public/nsync_counter.h deleted file mode 100644 index 69f95727..00000000 --- a/vendored/nsync/public/nsync_counter.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_COUNTER_H_ -#define NSYNC_PUBLIC_NSYNC_COUNTER_H_ - -#include -#include "nsync_cpp.h" -#include "nsync_mu.h" -#include "nsync_atomic.h" -#include "nsync_time.h" - -NSYNC_CPP_START_ - -struct nsync_dll_element_s_; - -/* An nsync_counter represents an unsigned integer that can count up and down, - and wake waiters when zero. */ -typedef struct nsync_counter_s_ *nsync_counter; - -/* Return a freshly allocated nsync_counter with the specified value, - of NULL if an nsync_counter cannot be created. - - Any non-NULL returned value should be passed to nsync_counter_free() when no - longer needed. */ -nsync_counter nsync_counter_new (uint32_t value); - -/* Free resources associated with c. Requires that c was allocated by - nsync_counter_new(), and no concurrent or future operations are applied to - c. */ -void nsync_counter_free (nsync_counter c); - -/* Add delta to c, and return its new value. It is a checkable runtime error - to decrement c below 0, or to increment c (i.e., apply a delta > 0) after a - waiter has waited. */ -uint32_t nsync_counter_add (nsync_counter c, int32_t delta); - -/* Return the current value of c. */ -uint32_t nsync_counter_value (nsync_counter c); - -/* Wait until c has value 0, or until abs_deadline, then return - the value of c. It is a checkable runtime error to increment c after - a waiter may have been woken due to the counter reaching zero. - If abs_deadline==nsync_time_no_deadline, the deadline - is far in the future. */ -uint32_t nsync_counter_wait (nsync_counter c, nsync_time abs_deadline); - -NSYNC_COUNTER_CPP_OVERLOAD_ -NSYNC_CPP_END_ - -#endif /*NSYNC_PUBLIC_NSYNC_COUNTER_H_*/ diff --git a/vendored/nsync/public/nsync_cpp.h b/vendored/nsync/public/nsync_cpp.h deleted file mode 100644 index 51f67606..00000000 --- a/vendored/nsync/public/nsync_cpp.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_CPP_H_ -#define NSYNC_PUBLIC_NSYNC_CPP_H_ - -/* This header file permits compilation via a C++ compiler using the macros - NSYNC_CPP_START_, NSYNC_CPP_END_, and NSYNC_CPP_USING_. - - NSYNC_CPP_START_ and NSYNC_CPP_END_ surround C code in the public library. - They put all public symbols into the "nsync" name space. - - NSYNC_CPP_USING_ is used before C code (used for testing) that might use - public exports from this package. It makes symbols in the "nsync" - name space available without the "nsync::" prefix. - - NSYNC_C_START_ and NSYNC_C_END_ surround C code in the C++ modules. - */ - -#if defined(__cplusplus) -#define NSYNC_CPP_START_ namespace nsync { -#define NSYNC_CPP_END_ } -#define NSYNC_CPP_USING_ using namespace nsync; -#define NSYNC_C_START_ extern "C" { -#define NSYNC_C_END_ } -#else -#define NSYNC_CPP_START_ -#define NSYNC_CPP_END_ -#define NSYNC_CPP_USING_ -#define NSYNC_C_START_ -#define NSYNC_C_END_ -#endif - -#endif /*NSYNC_PUBLIC_NSYNC_CPP_H_*/ diff --git a/vendored/nsync/public/nsync_cv.h b/vendored/nsync/public/nsync_cv.h deleted file mode 100644 index d16b16d1..00000000 --- a/vendored/nsync/public/nsync_cv.h +++ /dev/null @@ -1,148 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_CV_H_ -#define NSYNC_PUBLIC_NSYNC_CV_H_ - -#include -#include "nsync_cpp.h" -#include "nsync_mu.h" -#include "nsync_atomic.h" -#include "nsync_time.h" - -NSYNC_CPP_START_ - -struct nsync_dll_element_s_; -struct nsync_note_s_; - -/* An nsync_cv is a condition variable in the style of Mesa, Java, POSIX, and Go's sync.Cond. - It allows a thread to wait for a condition on state protected by a mutex, - and to proceed with the mutex held and the condition true. - - See also nsync_mu_wait() and nsync_mu_wait_with_deadline(), which implement conditional - critical sections. In many cases, they are easier to use than condition - variables. - - Usage: - - after making the desired predicate true, call: - nsync_cv_signal (&cv); // If at most one thread can make use of the predicate becoming true. - or - nsync_cv_broadcast (&cv); // If multiple threads can make use of the predicate becoming true. - - To wait for a predicate with no deadline (assuming nsync_cv_broadcast() or - nsync_cv_signal() is called whenever the predicate becomes true): - nsync_mu_lock (μ) - while (!some_predicate_protected_by_mu) { // the while-loop is required. - nsync_cv_wait (&cv, &mu); - } - // predicate is now true - nsync_mu_unlock (&mu); - - To wait for a predicate with a deadline (assuming nsync_cv_broadcast() or - nsync_cv_signal() is called whenever the predicate becomes true): - nsync_mu_lock (&mu); - while (!some_predicate_protected_by_mu && - nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline, cancel_note) == 0) { - } - if (some_predicate_protected_by_mu) { // predicate is true - } else { // predicate is false, and deadline expired, or cancel_note was notified. - } - nsync_mu_unlock (&mu); - or, if the predicate is complex and you wish to write it just once and - inline, you could use the following instead of the for-loop above: - nsync_mu_lock (&mu); - int pred_is_true = 0; - int outcome = 0; - while (!(pred_is_true = some_predicate_protected_by_mu) && outcome == 0) { - outcome = nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline, cancel_note); - } - if (pred_is_true) { // predicate is true - } else { // predicate is false, and deadline expired, or cancel_note was notified. - } - nsync_mu_unlock (&mu); - - As the examples show, Mesa-style condition variables require that waits use - a loop that tests the predicate anew after each wait. It may be surprising - that these are preferred over the precise wakeups offered by the condition - variables in Hoare monitors. Imprecise wakeups make more efficient use of - the critical section, because threads can enter it while a woken thread is - still emerging from the scheduler, which may take thousands of cycles. - Further, they make the programme easier to read and debug by making the - predicate explicit locally at the wait, where the predicate is about to be - assumed; the reader does not have to infer the predicate by examining all - the places where wakeups may occur. */ -typedef struct nsync_cv_s_ { - nsync_atomic_uint32_ word; /* see bits below */ - struct nsync_dll_element_s_ *waiters; /* points to tail of list of waiters; under mu. */ -} nsync_cv; - -/* An nsync_cv should be zeroed to initialize, which can be accomplished by - initializing with static initializer NSYNC_CV_INIT, or by setting the entire - struct to 0, or using nsync_cv_init(). */ -#define NSYNC_CV_INIT { NSYNC_ATOMIC_UINT32_INIT_, 0 } -void nsync_cv_init (nsync_cv *cv); - -/* Wake at least one thread if any are currently blocked on *cv. If - the chosen thread is a reader on an nsync_mu, wake all readers and, if - possible, a writer. */ -void nsync_cv_signal (nsync_cv *cv); - -/* Wake all threads currently blocked on *cv. */ -void nsync_cv_broadcast (nsync_cv *cv); - -/* Atomically release "mu" (which must be held on entry) and block the caller - on *cv. Wait until awakened by a call to nsync_cv_signal() or - nsync_cv_broadcast(), or a spurious wakeup; then reacquire "mu", and return. - Equivalent to a call to nsync_mu_wait_with_deadline() with - abs_deadline==nsync_time_no_deadline, and cancel_note==NULL. Callers should use - nsync_cv_wait() in a loop, as with all standard Mesa-style condition - variables. See examples above. */ -void nsync_cv_wait (nsync_cv *cv, nsync_mu *mu); - -/* Atomically release "mu" (which must be held on entry) - and block the calling thread on *cv. It then waits until awakened by a - call to nsync_cv_signal() or nsync_cv_broadcast() (or a spurious wakeup), or by the time - reaching abs_deadline, or by cancel_note being notified. In all cases, it - reacquires "mu", and returns the reason for the call returned (0, ETIMEDOUT, - or ECANCELED). Use abs_deadline==nsync_time_no_deadline for no deadline, and - cancel_note==NULL for no cancellation. wait_with_deadline() should be used in a - loop, as with all Mesa-style condition variables. See examples above. - - There are two reasons for using an absolute deadline, rather than a relative - timeout---these are why pthread_cond_timedwait() also uses an absolute - deadline. First, condition variable waits have to be used in a loop; with - an absolute times, the deadline does not have to be recomputed on each - iteration. Second, in most real programmes, some activity (such as an RPC - to a server, or when guaranteeing response time in a UI), there is a - deadline imposed by the specification or the caller/user; relative delays - can shift arbitrarily with scheduling delays, and so after multiple waits - might extend beyond the expected deadline. Relative delays tend to be more - convenient mostly in tests and trivial examples than they are in real - programmes. */ -int nsync_cv_wait_with_deadline (nsync_cv *cv, nsync_mu *mu, - nsync_time abs_deadline, - struct nsync_note_s_ *cancel_note); - -/* Like nsync_cv_wait_with_deadline(), but allow an arbitrary lock *v to be used, - given its (*lock)(mu) and (*unlock)(mu) routines. */ -int nsync_cv_wait_with_deadline_generic (nsync_cv *cv, - void *mu, void (*lock) (void *), void (*unlock) (void *), - nsync_time abs_deadline, - struct nsync_note_s_ *cancel_note); - -NSYNC_CV_CPP_OVERLOAD_ -NSYNC_CPP_END_ - -#endif /*NSYNC_PUBLIC_NSYNC_CV_H_*/ diff --git a/vendored/nsync/public/nsync_debug.h b/vendored/nsync/public/nsync_debug.h deleted file mode 100644 index fbaab9c6..00000000 --- a/vendored/nsync/public/nsync_debug.h +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_DEBUG_H_ -#define NSYNC_PUBLIC_NSYNC_DEBUG_H_ - -/* Debugging operations for mutexes and condition variables. - - These operations should not be relied upon for normal functionality. The - implementation may be slow, output formats may change, and the - implementation is free to yield the empty string. */ - -#include "nsync_cpp.h" -#include "nsync_mu.h" -#include "nsync_cv.h" - -NSYNC_CPP_START_ - -/* Place in buf[0,..,n-1] a nul-terminated, human readable string indicative of - some of the internal state of the mutex or condition variable, and return - buf. If n>=4, buffer overflow is indicated by placing the characters "..." - at the end of the string. - - The *_and_waiters() variants attempt to output the waiter lists in addition - to the basic state. These variants may acquire internal locks and follow - internal pointers. Thus, they are riskier if invoked in an address space - whose overall health is uncertain. */ -char *nsync_mu_debug_state (nsync_mu *mu, char *buf, int n); -char *nsync_cv_debug_state (nsync_cv *cv, char *buf, int n); -char *nsync_mu_debug_state_and_waiters (nsync_mu *mu, char *buf, int n); -char *nsync_cv_debug_state_and_waiters (nsync_cv *cv, char *buf, int n); - -/* Like nsync_*_debug_state_and_waiters(), but ignoring all locking and safety - considerations, and using an internal, possibly static buffer that may be - overwritten by subsequent or concurrent calls to these routines. These - variants should be used only from an interactive debugger, when all other - threads are stopped; the debugger is expected to recover from errors. */ -char *nsync_mu_debugger (nsync_mu *mu); -char *nsync_cv_debugger (nsync_cv *cv); - -NSYNC_CPP_END_ - -#endif /*NSYNC_PUBLIC_NSYNC_DEBUG_H_*/ diff --git a/vendored/nsync/public/nsync_mu.h b/vendored/nsync/public/nsync_mu.h deleted file mode 100644 index 309aa824..00000000 --- a/vendored/nsync/public/nsync_mu.h +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_MU_H_ -#define NSYNC_PUBLIC_NSYNC_MU_H_ - -#include -#include "nsync_cpp.h" -#include "nsync_atomic.h" - -NSYNC_CPP_START_ - -struct nsync_dll_element_s_; - -/* An nsync_mu is a lock. If initialized to all zeroes, it is valid and unlocked. - - An nsync_mu can be "free", held by a single thread (aka fiber, goroutine) in - "write" (exclusive) mode, or by many threads in "read" (shared) mode. A - thread that acquires it should eventually release it. It is illegal to - acquire an nsync_mu in one thread and release it in another. It is - illegal for a thread to reacquire an nsync_mu while holding it (even a - second share of a "read" lock). - - Example usage: - static struct foo { - nsync_mu mu; // protects invariant a+b==0 on fields below. - int a; - int b; - } p = { NSYNC_MU_INIT, 0, 0 }; - .... - nsync_mu_lock (&p.mu); - // The current thread now has exclusive access to p.a and p.b; invariant assumed true. - p.a++; - p.b--; // restore invariant p.a+p.b==0 before releasing p.mu - nsync_mu_unlock (&p.mu) - - Mutexes can be used with condition variables; see nsync_cv.h. - - nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead of - condition variables. See nsync_mu_wait.h for more details. - Example use of nsync_mu_wait() to wait for p.a==0, using definition above: - int a_is_zero (const void *condition_arg) { - return (((const struct foo *)condition_arg)->a == 0); - } - ... - nsync_mu_lock (&p.mu); - nsync_mu_wait (&p.mu, &a_is_zero, &p, NULL); - // The current thread now has exclusive access to p.a and p.b, and p.a==0. - ... - nsync_mu_unlock (&p.mu); */ -typedef struct nsync_mu_s_ { - nsync_atomic_uint32_ word; /* internal use only */ - struct nsync_dll_element_s_ *waiters; /* internal use only */ -} nsync_mu; - -/* An nsync_mu should be zeroed to initialize, which can be accomplished by - initializing with static initializer NSYNC_MU_INIT, or by setting the entire - structure to all zeroes, or using nsync_mu_init(). */ -#define NSYNC_MU_INIT { NSYNC_ATOMIC_UINT32_INIT_, 0 } -void nsync_mu_init (nsync_mu *mu); - -/* Block until *mu is free and then acquire it in writer mode. - Requires that the calling thread not already hold *mu in any mode. */ -void nsync_mu_lock (nsync_mu *mu); - -/* Unlock *mu, which must have been acquired in write mode by the calling - thread, and wake waiters, if appropriate. */ -void nsync_mu_unlock (nsync_mu *mu); - -/* Attempt to acquire *mu in writer mode without blocking, and return non-zero - iff successful. Return non-zero with high probability if *mu was free - on entry. */ -int nsync_mu_trylock (nsync_mu *mu); - -/* Block until *mu can be acquired in reader mode and then acquire it. - Requires that the calling thread not already hold *mu in any mode. */ -void nsync_mu_rlock (nsync_mu *mu); - -/* Unlock *mu, which must have been acquired in read mode by the calling - thread, and wake waiters, if appropriate. */ -void nsync_mu_runlock (nsync_mu *mu); - -/* Attempt to acquire *mu in reader mode without blocking, and return non-zero - iff successful. Return non-zero with high probability if *mu was free on - entry. Perhaps fail to acquire if a writer is waiting, to avoid starvation. - */ -int nsync_mu_rtrylock (nsync_mu *mu); - -/* May abort if *mu is not held in write mode by the calling thread. */ -void nsync_mu_assert_held (const nsync_mu *mu); - -/* May abort if *mu is not held in read or write mode - by the calling thread. */ -void nsync_mu_rassert_held (const nsync_mu *mu); - -/* Return whether *mu is held in read mode. - Requires that the calling thread holds *mu in some mode. */ -int nsync_mu_is_reader (const nsync_mu *mu); - -NSYNC_CPP_END_ - -#endif /*NSYNC_PUBLIC_NSYNC_MU_H_*/ diff --git a/vendored/nsync/public/nsync_mu_wait.h b/vendored/nsync/public/nsync_mu_wait.h deleted file mode 100644 index c745e892..00000000 --- a/vendored/nsync/public/nsync_mu_wait.h +++ /dev/null @@ -1,128 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_MU_WAIT_H_ -#define NSYNC_PUBLIC_NSYNC_MU_WAIT_H_ - -/* nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead of condition - variables. In many straightforward situations they are of equivalent - performance and are somewhat easier to use, because unlike condition - variables, they do not require that the waits be placed in a loop, and they - do not require explicit wakeup calls. Example: - - Definitions: - static nsync_mu mu = NSYNC_MU_INIT; - static int i = 0; // protected by mu - // Condition for use with nsync_mu_wait(). - static int int_is_zero (const void *v) { return (*(const int *)v == 0); } - - Waiter: - nsync_mu_lock (&mu); - // Wait until i is zero. - nsync_mu_wait (&mu, &int_is_zero, &i, NULL); - // i is known to be zero here. - // ... - nsync_mu_unlock (&mu); - - - Thread potentially making i zero: - nsync_mu_lock (&mu); - i--; - // No need to signal that i may have become zero. The unlock call below - // will evaluate waiters' conditions to decide which to wake. - nsync_mu_unlock (&mu); - - It is legal to use conditional critical sections and condition variables - on the same mutex. - - -------------- - - The implementation benefits from determining whether waiters are waiting for - the same condition; it may then evaluate a condition once on behalf - of several waiters. Two waiters have equal condition if their "condition" - pointers are equal, and either: - - their "condition_arg" pointers are equal, or - - "condition_arg_eq" is non-null and - (*condition_arg_eq) (condition_arg0, condition_arg1) returns non-zero. - *condition_arg_eq will not be invoked unless the "condition" pointers - are equal, and the "condition_arg" pointers are unequal. - - If many waiters wait for distinct conditions simultaneously, condition - variables may be faster. - */ - -#include "nsync_cpp.h" -#include "nsync_mu.h" -#include "nsync_time.h" - -NSYNC_CPP_START_ - -struct nsync_note_s_; /* forward declaration for an nsync_note */ - -/* Return when (*condition) (condition_arg) is true. Perhaps unlock and relock - *mu while blocked waiting for the condition to become true. nsync_mu_wait() - is equivalent to nsync_mu_wait_with_deadline() with - abs_deadline==nsync_time_no_deadline, and cancel_note==NULL. - - Requires that *mu be held on entry. - See nsync_mu_wait_with_deadline() for more details on *condition and - *condition_arg_eq. */ -void nsync_mu_wait (nsync_mu *mu, int (*condition) (const void *condition_arg), - const void *condition_arg, - int (*condition_arg_eq) (const void *a, const void *b)); - -/* Return when at least one of: (*condition) (condition_arg) is true, the - deadline expires, or *cancel_note is notified. Perhaps unlock and relock *mu - while blocked waiting for one of these events, but always return with *mu - held. Return 0 iff the (*condition) (condition_arg) is true on return, and - otherwise either ETIMEDOUT or ECANCELED, depending on why the call returned - early. Callers should use abs_deadline==nsync_time_no_deadline for no - deadline, and cancel_note==NULL for no cancellation. - - Requires that *mu be held on entry. - - The implementation may call *condition from any thread using the mutex, and - while holding *mu in either read or write mode; it guarantees that any - thread calling *condition will hold *mu in some mode. - Requires that (*condition) (condition_arg) neither modify state protected by - *mu, nor return a value dependent on state not protected by *mu. To depend - on time, use the abs_deadline parameter. - (Conventional use of condition variables have the same restrictions on the - conditions tested by the while-loop.) - If non-null, condition_arg_eq should return whether two condition_arg - calls with the same "condition" pointer are considered equivalent; it should - have no side-effects. */ -int nsync_mu_wait_with_deadline (nsync_mu *mu, - int (*condition) (const void *condition_arg), - const void *condition_arg, - int (*condition_arg_eq) (const void *a, const void *b), - nsync_time abs_deadline, - struct nsync_note_s_ *cancel_note); - -/* Unlock *mu, which must be held in write mode, and wake waiters, if - appropriate. Unlike nsync_mu_unlock(), this call is not required to wake - nsync_mu_wait/nsync_mu_wait_with_deadline calls on conditions that were - false before this thread acquired the lock. This call should be used only - at the end of critical sections for which: - - nsync_mu_wait and/or nsync_mu_wait_with_deadline are in use on the same - mutex, - - this critical section cannot make the condition true for any of those - nsync_mu_wait/nsync_mu_wait_with_deadline waits, and - - when performance is significantly improved by using this call. */ -void nsync_mu_unlock_without_wakeup (nsync_mu *mu); - -NSYNC_MU_WAIT_CPP_OVERLOAD_ -NSYNC_CPP_END_ - -#endif /*NSYNC_PUBLIC_NSYNC_MU_WAIT_H_*/ diff --git a/vendored/nsync/public/nsync_note.h b/vendored/nsync/public/nsync_note.h deleted file mode 100644 index 05e9b791..00000000 --- a/vendored/nsync/public/nsync_note.h +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_NOTE_H_ -#define NSYNC_PUBLIC_NSYNC_NOTE_H_ - -#include "nsync_cpp.h" -#include "nsync_time.h" - -NSYNC_CPP_START_ - -/* An nsync_note represents a single bit that can transition from 0 to 1 at - most once. When 1, the note is said to be notified. There are operations - to wait for the transition, which can be triggered either by an explicit - call, or timer expiry. Notes can have parent notes; a note becomes notified - if its parent becomes notified. */ -typedef struct nsync_note_s_ *nsync_note; - -/* Return a freshly allocated nsync_note, or NULL if an nsync_note cannot be - created. - - If parent!=NULL, the allocated nsync_note's parent will be parent. The - newaly allocated note will be automatically notified at abs_deadline, and is - notified at initialization if abs_deadline==nsync_zero_time. - - nsync_notes should be passed to nsync_note_free() when no longer needed. */ -nsync_note nsync_note_new (nsync_note parent, nsync_time abs_deadline); - -/* Free resources associated with n. Requires that n was allocated by - nsync_note_new(), and no concurrent or future operations are applied to n - directly. - It is legal to call nsync_note_free() on a node even if it has a parent or - children that are in use; if n has both a parent and children, n's - parent adopts its children. */ -void nsync_note_free (nsync_note n); - -/* Notify n and all its descendants. */ -void nsync_note_notify (nsync_note n); - -/* Return whether n has been notified. */ -int nsync_note_is_notified (nsync_note n); - -/* Wait until n has been notified or abs_deadline is reached, and return - whether n has been notified. If abs_deadline==nsync_time_no_deadline, - the deadline is far in the future. */ -int nsync_note_wait (nsync_note n, nsync_time abs_deadline); - -/* Return the expiry time associated with n. - This is the minimum of the abs_deadline passed on creation and that of any - of its ancestors. */ -nsync_time nsync_note_expiry (nsync_note n); - -NSYNC_NOTE_CPP_OVERLOAD_ -NSYNC_CPP_END_ - -#endif /*NSYNC_PUBLIC_NSYNC_NOTE_H_*/ diff --git a/vendored/nsync/public/nsync_once.h b/vendored/nsync/public/nsync_once.h deleted file mode 100644 index 182c805e..00000000 --- a/vendored/nsync/public/nsync_once.h +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_ONCE_H_ -#define NSYNC_PUBLIC_NSYNC_ONCE_H_ - -#include -#include "nsync_cpp.h" -#include "nsync_atomic.h" - -NSYNC_CPP_START_ - -/* An nsync_once allows a function to be called exactly once, when first referenced. */ -typedef nsync_atomic_uint32_ nsync_once; - -/* An initializer for nsync_once; it is guaranteed to be all zeroes. */ -#define NSYNC_ONCE_INIT NSYNC_ATOMIC_UINT32_INIT_ - -/* The first time nsync_run_once() or nsync_run_once_arg() is applied to *once, - the supplied function is run (with argument, in the case of nsync_run_once_arg()). - Other callers will wait until the run of the function is complete, and then - return without running the function again. */ -void nsync_run_once (nsync_once *once, void (*f) (void)); -void nsync_run_once_arg (nsync_once *once, void (*farg) (void *arg), void *arg); - -/* Same as nsync_run_once()/nsync_run_once_arg() but uses a spinloop. - Can be used on the same nsync_once as nsync_run_once/nsync_run_once_arg(). - - These *_spin variants should be used only in contexts where normal blocking - is disallowed, such as within user-space schedulers, when the runtime is - not fully initialized, etc. They provide no significant performance benefit, - and they should be avoided in normal code. */ -void nsync_run_once_spin (nsync_once *once, void (*f) (void)); -void nsync_run_once_arg_spin (nsync_once *once, void (*farg) (void *arg), void *arg); - -NSYNC_CPP_END_ - -#endif /*NSYNC_PUBLIC_NSYNC_ONCE_H_*/ diff --git a/vendored/nsync/public/nsync_time.h b/vendored/nsync/public/nsync_time.h deleted file mode 100644 index 9a4beaed..00000000 --- a/vendored/nsync/public/nsync_time.h +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_TIME_H_ -#define NSYNC_PUBLIC_NSYNC_TIME_H_ - -#include "nsync_cpp.h" -#include "nsync_time_internal.h" - -/* The type nsync_time represents the interval elapsed between two moments in - time. Often the first such moment is an address-space-wide epoch, such as - the Unix epoch, but clients should not rely on the epoch in one address - space being the same as that in another. Intervals relative to the epoch - are known as absolute times. - - The internals of nsync_time should be treated as opaque by clients. - See nsync_time_internal.h. */ - -NSYNC_CPP_START_ - -extern const nsync_time nsync_time_no_deadline; /* A deadline infinitely far in the future. */ -extern const nsync_time nsync_time_zero; /* The zero delay, or an expired deadline. */ - -nsync_time nsync_time_now (void); /* Return the current time since the epoch. */ - -/* Sleep for the specified delay. Returns the unslept time - which may be non-zero if the call was interrupted. */ -nsync_time nsync_time_sleep (nsync_time delay); - -/* Return a+b */ -nsync_time nsync_time_add (nsync_time a, nsync_time b); - -/* Return a-b */ -nsync_time nsync_time_sub (nsync_time a, nsync_time b); - -/* Return +ve, 0, or -ve according to whether a>b, a==b, or a -NSYNC_CPP_START_ -typedef NSYNC_USE_INT_TIME nsync_time; -#define NSYNC_TIME_SEC(t) (sizeof (nsync_time) >= 8? \ - (t) / (1000 * 1000 * 1000): \ - ((t) / 1000)) -#define NSYNC_TIME_NSEC(t) (sizeof (nsync_time) >= 8? \ - (t) % (1000 * 1000 * 1000): \ - (((t) % 1000) * 1000 * 1000)) -#define NSYNC_TIME_MAX_ MAX_INT_TYPE (nsync_time) -NSYNC_CPP_END_ - -#elif defined(NSYNC_USE_FLOATING_TIME) -#include -#include -NSYNC_CPP_START_ -typedef NSYNC_USE_FLOATING_TIME nsync_time; -#define NSYNC_TIME_SEC(t) (trunc ((t) / (nsync_time) (1000 * 1000 * 1000))) -#define NSYNC_TIME_NSEC(t) ((t) - ((1000 * 1000 * 1000) * NSYNC_TIME_SEC (t))) -#define NSYNC_TIME_MAX_ DBL_MAX -NSYNC_CPP_END_ - -#elif NSYNC_USE_DEBUG_TIME -/* Check that the library can be built with a different time struct. */ -#include -NSYNC_CPP_START_ -typedef struct { - time_t seconds; - unsigned nanoseconds; -} nsync_time; -#define NSYNC_TIME_SEC(t) ((t).seconds) -#define NSYNC_TIME_NSEC(t) ((t).nanoseconds) -NSYNC_CPP_END_ - -#elif defined(__cplusplus) && \ - (NSYNC_USE_CPP11_TIMEPOINT || (__cplusplus >= 201103L) || (_MSC_VER >= 1700)) -/* The inline functions below provide function overloads that accept the most - likely C++11 time type(s). - - C++11 time types have many variations and subtleties: - - There are multiple clocks with potentially differing epochs; these clocks - are not necessarily phase-locked to the same rate, making conversion and - comparison between clocks tricky. - - Relative and absolute times are distinguished in the type system. - - Either integral or floating point counters may be used to represent time - intervals, and code valid with one may not be valid with the other - (see std::chrono::treat_as_floating_point). - - A counter increment of one can represent any rational number of seconds - (for whatever "seconds" means for this clock). - - Conversions between duration types may round or truncate at the - implementation's discretion. - - As mentioned above, common implementations of the default monotonic clock - ("steady_clock") illegally allow a thread to observe time going backwards, - especially in the face of scheduling on a different CPU, making its use - misleading, at best. - I've chosen to handle this complexity by doing a conversion to absolute - timespec at the interface layer, so all the C++ complication is here, rather - than spread throughout the library. */ - -#include -#include -NSYNC_CPP_START_ -typedef struct timespec nsync_time; -#define NSYNC_TIME_SEC(t) ((t).tv_sec) -#define NSYNC_TIME_NSEC(t) ((t).tv_nsec) - -typedef std::chrono::system_clock::time_point nsync_cpp_time_point_; -nsync_time nsync_from_time_point_ (nsync_cpp_time_point_); -nsync_cpp_time_point_ nsync_to_time_point_ (nsync_time); -#define NSYNC_COUNTER_CPP_OVERLOAD_ \ - static inline uint32_t nsync_counter_wait (nsync_counter c, \ - nsync_cpp_time_point_ abs_deadline) { \ - return (nsync_counter_wait (c, nsync_from_time_point_ (abs_deadline))); \ - } -#define NSYNC_CV_CPP_OVERLOAD_ \ - static inline int nsync_cv_wait_with_deadline (nsync_cv *cv, nsync_mu *mu, \ - nsync_cpp_time_point_ abs_deadline, struct nsync_note_s_ *cancel_note) { \ - return (nsync_cv_wait_with_deadline (cv, mu, \ - nsync_from_time_point_ (abs_deadline), \ - cancel_note)); \ - } \ - static inline int nsync_cv_wait_with_deadline_generic (nsync_cv *cv, \ - void *mu, void (*lock) (void *), void (*unlock) (void *), \ - nsync_cpp_time_point_ abs_deadline, struct nsync_note_s_ *cancel_note) { \ - return (nsync_cv_wait_with_deadline_generic (cv, mu, lock, unlock, \ - nsync_from_time_point_ (abs_deadline), \ - cancel_note)); \ - } -#define NSYNC_MU_WAIT_CPP_OVERLOAD_ \ - static inline int nsync_mu_wait_with_deadline (nsync_mu *mu, \ - int (*condition) (const void *condition_arg), const void *condition_arg, \ - int (*condition_arg_eq) (const void *a, const void *b), \ - nsync_cpp_time_point_ abs_deadline, struct nsync_note_s_ *cancel_note) { \ - return (nsync_mu_wait_with_deadline (mu, condition, condition_arg, \ - condition_arg_eq, \ - nsync_from_time_point_ (abs_deadline), \ - cancel_note)); \ - } -#define NSYNC_NOTE_CPP_OVERLOAD_ \ - static inline nsync_note nsync_note_new (nsync_note parent, \ - nsync_cpp_time_point_ abs_deadline) { \ - return (nsync_note_new (parent, nsync_from_time_point_ (abs_deadline))); \ - } \ - static inline int nsync_note_wait (nsync_note n, nsync_cpp_time_point_ abs_deadline) { \ - return (nsync_note_wait (n, nsync_from_time_point_ (abs_deadline))); \ - } \ - static inline nsync_cpp_time_point_ nsync_note_expiry_timepoint (nsync_note n) { \ - return (nsync_to_time_point_ (nsync_note_expiry (n))); \ - } -#define NSYNC_WAITER_CPP_OVERLOAD_ \ - static inline int nsync_wait_n (void *mu, void (*lock) (void *), \ - void (*unlock) (void *), \ - nsync_cpp_time_point_ abs_deadline, \ - int count, struct nsync_waitable_s *waitable[]) { \ - return (nsync_wait_n (mu, lock, unlock, \ - nsync_from_time_point_ (abs_deadline), count, waitable)); \ - } - -NSYNC_CPP_END_ - -#else -/* Default is to use timespec. */ -#include -NSYNC_CPP_START_ -typedef struct timespec nsync_time; -#define NSYNC_TIME_SEC(t) ((t).tv_sec) -#define NSYNC_TIME_NSEC(t) ((t).tv_nsec) -NSYNC_CPP_END_ - -#endif - -#if !defined(NSYNC_COUNTER_CPP_OVERLOAD_) -#define NSYNC_COUNTER_CPP_OVERLOAD_ -#define NSYNC_CV_CPP_OVERLOAD_ -#define NSYNC_MU_WAIT_CPP_OVERLOAD_ -#define NSYNC_NOTE_CPP_OVERLOAD_ -#define NSYNC_WAITER_CPP_OVERLOAD_ -#endif - -#endif /*NSYNC_PUBLIC_NSYNC_TIME_INTERNAL_H_*/ diff --git a/vendored/nsync/public/nsync_waiter.h b/vendored/nsync/public/nsync_waiter.h deleted file mode 100644 index 4501ec5c..00000000 --- a/vendored/nsync/public/nsync_waiter.h +++ /dev/null @@ -1,155 +0,0 @@ -/* Copyright 2016 Google Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -#ifndef NSYNC_PUBLIC_NSYNC_WAITER_H_ -#define NSYNC_PUBLIC_NSYNC_WAITER_H_ - -/* nsync_wait_n() allows the client to wait on multiple objects (condition - variables, nsync_notes, nsync_counters, etc.) until at least one of them - becomes ready, or a deadline expires. - - It can be thought of as rather like Unix's select() or poll(), - except the the objects being waited for are synchronization - data structures, rather than file descriptors. - - The client can construct new objects that can be waited for by implementing - three routines. - - Examples: - - To wait on two nsync_notes n0, n1, and a nsync_counter c0, - with a deadline of abs_deadline: - - // Form an array of struct nsync_waitable_s, identifying the - // objects and the corresponding descriptors. (static initialization - // syntax is used for brevity) - static struct nsync_waitable_s w[] = { - { &n0, &nsync_note_waitable_funcs }, - { &n1, &nsync_note_waitable_funcs }, - { &c0, &nsync_counter_waitable_funcs } - }; - static struct nsync_waitable_s *pw[] = { &w[0], &w[1], &w[2] }; - int n = sizeof (w) / sizeof (w[0]); - - // Wait. The mu, lock, and unlock arguments are NULL because - // no condition variables are invovled. - int i = nsync_wait_n (NULL, NULL, NULL, abs_deadline, n, pw); - if (i == n) { - // timeout - } else { - // w[i].v became ready. - } - - To wait on multiple condition variables, the mu/lock/unlock parameters are - used. Imagine cv0 and cv1 are signalled when predicates pred0() (under - lock mu0) and pred1() (under lock mu1) become true respectively. Assume - that mu0 is acquired before mu1. - static void lock2 (void *v) { // lock two mutexes in order - nsync_mu **mu = (nsync_mu **) v; - nsync_mu_lock (mu[0]); - nsync_mu_lock (mu[1]); - } - static void unlock2 (void *v) { // unlock two mutexes. - nsync_mu **mu = (nsync_mu **) v; - nsync_mu_unlock (mu[1]); - nsync_mu_unlock (mu[0]); - } - - // Describe the condition variables and the locks. - static struct nsync_waitable_s w[] = { - { &cv0, &nsync_cv_waitable_funcs }, - { &cv1, &nsync_cv_waitable_funcs } - }; - static struct nsync_waitable_s *pw[] = { &w[0], &w[1] }; - nsync_mu *lock_list[] = { &mu0, &mu1 }; - int n = sizeof (w) / sizeof (w[0]); - - lock2 (list_list); - while (!pred0 () && !pred1 ()) { - // Wait for one of the condition variables to be signalled, - // with no timeout. - nsync_wait_n (lock_list, &lock2, &unlock2, - nsync_time_no_deadline, n, pw); - } - if (pred0 ()) { ... } - if (pred1 ()) { ... } - unlock2 (list_list); - - */ - -#include -#include -#include "nsync_cpp.h" -#include "nsync_atomic.h" -#include "nsync_time.h" - -NSYNC_CPP_START_ - -struct nsync_waitable_funcs_s; /* forward declaration of struct that contains - type dependent wait operations */ - -/* Clients wait on objects by forming an array of struct nsync_waitable_s. - Each each element points to one object and its type-dependent functions. */ -struct nsync_waitable_s { - void *v; /* pointer to object */ - /* pointer to type-dependent functions. Use - &nsync_note_waitable_funcs for an nsync_note, - &nsync_counternote_waitable_funcs for an nsync_counter, - &nsync_cv_waitable_funcs for an nsync_cv. */ - const struct nsync_waitable_funcs_s *funcs; -}; - -/* Wait until at least one of *waitable[0,..,count-1] is has been notified, or - abs_deadline is reached. Return the index of the notified element of - waitable[], or count if no such element exists. - If mu!=NULL, (*unlock)(mu) is called after the thread is queued on the - various waiters, and (*lock)(mu) is called before return; mu/lock/unlock are - used to acquire and release the relevant locks whan waiting on condition - variables. */ -int nsync_wait_n (void *mu, void (*lock) (void *), void (*unlock) (void *), - nsync_time abs_deadline, int count, - struct nsync_waitable_s *waitable[]); - -/* --------------------------------------------------- */ - -/* A "struct nsync_waitable_s" implementation must implement these functions. - Clients should ignore the internals. */ -struct nsync_waiter_s; -struct nsync_waitable_funcs_s { - /* Return the time when *v will be ready (max time if - unknown), or 0 if it is already ready. The parameter nw may be - passed as NULL, in which case the result should indicate whether the - thread would block if it were to wait on *v. - All calls with the same *v must report the same result until the - object becomes ready, from which point calls must report 0. */ - nsync_time (*ready_time) (void *v, struct nsync_waiter_s *nw); - - /* If *v is ready, return zero; otherwise enqueue *nw on *v and return - non-zero. */ - int (*enqueue) (void *v, struct nsync_waiter_s *nw); - - /* If nw has been previously dequeued, return zero; otherwise dequeue - *nw from *v and return non-zero. */ - int (*dequeue) (void *v, struct nsync_waiter_s *nw); -}; - -/* The "struct nsync_waitable_s" for nsync_note, nsync_counter, and nsync_cv. */ -extern const struct nsync_waitable_funcs_s nsync_note_waitable_funcs; -extern const struct nsync_waitable_funcs_s nsync_counter_waitable_funcs; -extern const struct nsync_waitable_funcs_s nsync_cv_waitable_funcs; - -NSYNC_WAITER_CPP_OVERLOAD_ -NSYNC_CPP_END_ - -#endif /*NSYNC_PUBLIC_NSYNC_WAITER_H_*/ From 833c56afa00e4cc5b0409e2f5b1ec73fb196ee81 Mon Sep 17 00:00:00 2001 From: Brad Garagan Date: Sun, 8 Mar 2026 19:29:50 -0300 Subject: [PATCH 34/34] This and that --- CLAUDE.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index b63772e0..4baea4b4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ## Project Overview -**Ty** is a compiled, statically-typed programming language implementation written in C (C23 +**Ty** is an interpreted, gradually-typed programming language implementation written in C (C23 standard). It includes a bytecode VM, optional JIT compiler (DynASM-based), garbage collector, coroutine system, and a standard library written in Ty itself. @@ -70,8 +70,8 @@ make test # Runs: ./ty test.ty # Run a single test file ./ty --test tests/array.ty -# Filter tests by name pattern -TEST_FILTER="dict" ./ty test.ty +# Run the full test suite +./ty test.ty ``` The test runner [test.ty](test.ty) is written in Ty itself. It runs test files from @@ -99,17 +99,17 @@ Source text | `vm.c` | Bytecode interpreter, exception handling, coroutines (~11K LOC) | | `functions.c` | Built-in functions and standard library glue (~10K LOC) | | `parse.c` | Parser, AST construction (~7.5K LOC) | -| `jit.c` | JIT driver; arch-specific code in `.dasc` files (~7K LOC) | -| `gc.c` | Incremental mark-and-sweep GC with arena allocators | +| `jit.c` | JIT driver; arch-specific code in `.dasc` files (~7K LOC) | +| `gc.c` | Naive STW mark-and-sweep GC | | `ffi.c` | Foreign function interface via libffi | -| `value.c` | Core `Value` type (8-byte tagged union) | +| `value.c` | Core `Value` type (32-byte tagged union) | | `scope.c` | Symbol tables and lexical scoping | | `class.c` | Class system with inheritance and traits | ### Value Representation -All Ty values are a packed 8-byte `Value` struct (defined in [include/ty.h](include/ty.h)) with a -type byte, tag byte, and a union payload. This is the central type used throughout the VM and +All Ty values are a packed 32-byte `Value` struct (defined in [include/ty.h](include/ty.h)) with a +type byte, 16-bit tag, and a union payload. This is the central type used throughout the VM and compiler. ### Executables