├── .github ├── FUNDING.yml └── workflows │ ├── ci-mac.yaml │ └── ci-win.yaml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── Build └── .gitignore ├── CODE_OF_CONDUCT.md ├── CPPAtomic.sln ├── CPPAtomic.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── CPPAtomic.xcscmblueprint │ │ ├── IDEWorkspaceChecks.plist │ │ └── PIMPL.xcscmblueprint └── xcshareddata │ └── xcschemes │ ├── CPPAtomic-Tests.xcscheme │ └── CPPAtomic.xcscheme ├── CPPAtomic ├── include │ └── XS │ │ ├── Atomic-Functions.hpp │ │ ├── Atomic.hpp │ │ ├── IPC │ │ ├── RWLock.hpp │ │ ├── Semaphore.hpp │ │ └── SharedMemory.hpp │ │ └── RWLock.hpp └── source │ ├── Atomic-Functions │ ├── AtomicAdd32.cpp │ ├── AtomicAdd64.cpp │ ├── AtomicCompareAndSwap32.cpp │ ├── AtomicCompareAndSwap64.cpp │ ├── AtomicCompareAndSwapPointer.cpp │ ├── AtomicDecrement32.cpp │ ├── AtomicDecrement64.cpp │ ├── AtomicIncrement32.cpp │ ├── AtomicIncrement64.cpp │ └── MemoryBarrier.cpp │ ├── IPC │ ├── RWLock.cpp │ ├── Semaphore.cpp │ ├── Semaphore │ │ └── Guard.cpp │ └── SharedMemory.cpp │ └── RWLock.cpp ├── LICENSE ├── README.md ├── Scripts ├── .gitignore └── travis-after.sh ├── Test-Helper └── main.cpp ├── Unit-Tests ├── Info.plist ├── XS-Atomic-Functions.cpp ├── XS-Atomic-Non-Trivial.cpp ├── XS-Atomic-Static.cpp ├── XS-Atomic-Trivial-Bitwise.cpp ├── XS-Atomic-Trivial-Bool.cpp ├── XS-Atomic-Trivial-Double.cpp ├── XS-Atomic-Trivial-Integral.cpp ├── XS-Atomic-Trivial-Pointer.cpp ├── XS-Atomic-Trivial-Struct.cpp ├── XS-IPC-RWLock.cpp ├── XS-IPC-Semaphore-Guard.cpp ├── XS-IPC-Semaphore.cpp ├── XS-IPC-SharedMemory.cpp ├── XS-IPC-TestBase.cpp ├── XS-IPC-TestBase.hpp └── XS-RWLock.cpp └── VisualStudio ├── All.vcxproj ├── All.vcxproj.filters ├── CPPAtomic Static VC140 XP.vcxproj ├── CPPAtomic Static VC140 XP.vcxproj.filters ├── CPPAtomic Static VC141 XP.vcxproj ├── CPPAtomic Static VC141 XP.vcxproj.filters ├── CPPAtomic Static VC142.vcxproj └── CPPAtomic Static VC142.vcxproj.filters /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: macmade 2 | -------------------------------------------------------------------------------- /.github/workflows/ci-mac.yaml: -------------------------------------------------------------------------------- 1 | name: ci-mac 2 | on: [push] 3 | jobs: 4 | ci: 5 | runs-on: macos-latest 6 | strategy: 7 | matrix: 8 | run-config: 9 | - { scheme: 'CPPAtomic', configuration: 'Debug', project: 'CPPAtomic.xcodeproj', build: 1, analyze: 1, test: 1, info: 1, destination: 'platform=macOS' } 10 | - { scheme: 'CPPAtomic', configuration: 'Release', project: 'CPPAtomic.xcodeproj', build: 1, analyze: 1, test: 0, info: 1, destination: 'platform=macOS' } 11 | steps: 12 | 13 | - uses: actions/checkout@v1 14 | with: 15 | submodules: 'recursive' 16 | 17 | - uses: macmade/action-xcodebuild@v1.0.0 18 | 19 | - uses: macmade/action-slack@v1.0.0 20 | if: ${{ always() }} 21 | env: 22 | SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} 23 | with: 24 | channel: '#ci' 25 | status: ${{ job.status }} 26 | title: ${{ matrix.run-config[ 'scheme' ] }} - ${{ matrix.run-config[ 'configuration' ] }} 27 | -------------------------------------------------------------------------------- /.github/workflows/ci-win.yaml: -------------------------------------------------------------------------------- 1 | name: ci-win 2 | on: [push] 3 | jobs: 4 | ci: 5 | runs-on: windows-latest 6 | strategy: 7 | matrix: 8 | run-config: 9 | - { platform: 'x64', toolset: 'x64', configuration: 'Debug', solution: 'CPPAtomic.sln' } 10 | - { platform: 'x64', toolset: 'x64', configuration: 'Release', solution: 'CPPAtomic.sln' } 11 | - { platform: 'x86', toolset: 'x64', configuration: 'Debug', solution: 'CPPAtomic.sln' } 12 | - { platform: 'x86', toolset: 'x64', configuration: 'Release', solution: 'CPPAtomic.sln' } 13 | steps: 14 | 15 | - uses: actions/checkout@v1 16 | with: 17 | submodules: 'recursive' 18 | 19 | - uses: macmade/action-msbuild@v1.1.0 20 | 21 | - uses: macmade/action-slack@v1.0.0 22 | if: ${{ always() }} 23 | env: 24 | SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} 25 | with: 26 | channel: '#ci' 27 | status: ${{ job.status }} 28 | title: ${{ matrix.run-config[ 'solution' ] }} - ${{ matrix.run-config[ 'configuration' ] }} - ${{ matrix.run-config[ 'platform' ] }} 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac Finder 2 | .DS_Store 3 | .Trashes 4 | Icon? 5 | 6 | # Thumbnails 7 | ._* 8 | 9 | # Files that might appear on external disk 10 | .Spotlight-V100 11 | .Trashes 12 | 13 | # Windows 14 | Thumbs.db 15 | 16 | # Xcode 17 | *.pbxuser 18 | *.mode1v3 19 | *.mode2v3 20 | *.perspectivev3 21 | *.xccheckout 22 | *.profraw 23 | !default.pbxuser 24 | !default.mode1v3 25 | !default.mode2v3 26 | !default.perspectivev3 27 | xcuserdata 28 | 29 | # VisualStudio 30 | *.suo 31 | *.sdf 32 | *.opensdf 33 | *.opendb 34 | *.vcxproj.user 35 | *.csproj.user 36 | *.VC.db 37 | ipch 38 | .vs 39 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Submodules/CPPTraits"] 2 | path = Submodules/CPPTraits 3 | url = https://github.com/macmade/CPPTraits.git 4 | [submodule "Submodules/PIMPL"] 5 | path = Submodules/PIMPL 6 | url = https://github.com/macmade/PIMPL.git 7 | [submodule "Submodules/CrashGuard"] 8 | path = Submodules/CrashGuard 9 | url = https://github.com/macmade/CrashGuard.git 10 | [submodule "Submodules/xcconfig"] 11 | path = Submodules/xcconfig 12 | url = https://github.com/macmade/xcconfig.git 13 | [submodule "Submodules/XSTest"] 14 | path = Submodules/XSTest 15 | url = https://github.com/macmade/XSTest.git 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode10.2 3 | cache: 4 | directories: 5 | - $HOME/.ccache 6 | install: 7 | - gem install xcpretty 8 | - brew install ccache 9 | - PATH=$PATH:/usr/local/opt/ccache/libexec 10 | - brew install --HEAD macmade/tap/xcode-coveralls 11 | - export PYTHONUSERBASE=~/.local 12 | script: 13 | - set -o pipefail && xcodebuild -project "CPPAtomic.xcodeproj" -scheme "CPPAtomic-Tests" build test | xcpretty 14 | before_script: 15 | - ccache -s 16 | - ccache -z 17 | after_script: 18 | - ccache -s 19 | after_success: 20 | - bash Scripts/travis-after.sh 21 | notifications: 22 | slack: xs-labs:FXh1yLXNkpcVxKZhZU6icdhI 23 | -------------------------------------------------------------------------------- /Build/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | xs-labs.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CPPAtomic.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29009.5 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPPAtomic Static VC140 XP", "VisualStudio\CPPAtomic Static VC140 XP.vcxproj", "{42C37BE5-0A01-4054-9E69-76A499A1B160}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPPAtomic Static VC141 XP", "VisualStudio\CPPAtomic Static VC141 XP.vcxproj", "{A155D579-636A-40C1-AF81-DDC0F6A8623E}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "All", "VisualStudio\All.vcxproj", "{BF41470D-22A7-46C5-A73C-6AB4DB932359}" 11 | ProjectSection(ProjectDependencies) = postProject 12 | {A155D579-636A-40C1-AF81-DDC0F6A8623E} = {A155D579-636A-40C1-AF81-DDC0F6A8623E} 13 | {88FE28D1-C669-4972-9D7A-F171BA951ACB} = {88FE28D1-C669-4972-9D7A-F171BA951ACB} 14 | {42C37BE5-0A01-4054-9E69-76A499A1B160} = {42C37BE5-0A01-4054-9E69-76A499A1B160} 15 | EndProjectSection 16 | EndProject 17 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPPAtomic Static VC142", "VisualStudio\CPPAtomic Static VC142.vcxproj", "{88FE28D1-C669-4972-9D7A-F171BA951ACB}" 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|x64 = Debug|x64 22 | Debug|x86 = Debug|x86 23 | Release|x64 = Release|x64 24 | Release|x86 = Release|x86 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {42C37BE5-0A01-4054-9E69-76A499A1B160}.Debug|x64.ActiveCfg = Debug|x64 28 | {42C37BE5-0A01-4054-9E69-76A499A1B160}.Debug|x64.Build.0 = Debug|x64 29 | {42C37BE5-0A01-4054-9E69-76A499A1B160}.Debug|x86.ActiveCfg = Debug|Win32 30 | {42C37BE5-0A01-4054-9E69-76A499A1B160}.Debug|x86.Build.0 = Debug|Win32 31 | {42C37BE5-0A01-4054-9E69-76A499A1B160}.Release|x64.ActiveCfg = Release|x64 32 | {42C37BE5-0A01-4054-9E69-76A499A1B160}.Release|x64.Build.0 = Release|x64 33 | {42C37BE5-0A01-4054-9E69-76A499A1B160}.Release|x86.ActiveCfg = Release|Win32 34 | {42C37BE5-0A01-4054-9E69-76A499A1B160}.Release|x86.Build.0 = Release|Win32 35 | {A155D579-636A-40C1-AF81-DDC0F6A8623E}.Debug|x64.ActiveCfg = Debug|x64 36 | {A155D579-636A-40C1-AF81-DDC0F6A8623E}.Debug|x64.Build.0 = Debug|x64 37 | {A155D579-636A-40C1-AF81-DDC0F6A8623E}.Debug|x86.ActiveCfg = Debug|Win32 38 | {A155D579-636A-40C1-AF81-DDC0F6A8623E}.Debug|x86.Build.0 = Debug|Win32 39 | {A155D579-636A-40C1-AF81-DDC0F6A8623E}.Release|x64.ActiveCfg = Release|x64 40 | {A155D579-636A-40C1-AF81-DDC0F6A8623E}.Release|x64.Build.0 = Release|x64 41 | {A155D579-636A-40C1-AF81-DDC0F6A8623E}.Release|x86.ActiveCfg = Release|Win32 42 | {A155D579-636A-40C1-AF81-DDC0F6A8623E}.Release|x86.Build.0 = Release|Win32 43 | {BF41470D-22A7-46C5-A73C-6AB4DB932359}.Debug|x64.ActiveCfg = Debug|x64 44 | {BF41470D-22A7-46C5-A73C-6AB4DB932359}.Debug|x64.Build.0 = Debug|x64 45 | {BF41470D-22A7-46C5-A73C-6AB4DB932359}.Debug|x86.ActiveCfg = Debug|Win32 46 | {BF41470D-22A7-46C5-A73C-6AB4DB932359}.Debug|x86.Build.0 = Debug|Win32 47 | {BF41470D-22A7-46C5-A73C-6AB4DB932359}.Release|x64.ActiveCfg = Release|x64 48 | {BF41470D-22A7-46C5-A73C-6AB4DB932359}.Release|x64.Build.0 = Release|x64 49 | {BF41470D-22A7-46C5-A73C-6AB4DB932359}.Release|x86.ActiveCfg = Release|Win32 50 | {BF41470D-22A7-46C5-A73C-6AB4DB932359}.Release|x86.Build.0 = Release|Win32 51 | {88FE28D1-C669-4972-9D7A-F171BA951ACB}.Debug|x64.ActiveCfg = Debug|x64 52 | {88FE28D1-C669-4972-9D7A-F171BA951ACB}.Debug|x64.Build.0 = Debug|x64 53 | {88FE28D1-C669-4972-9D7A-F171BA951ACB}.Debug|x86.ActiveCfg = Debug|Win32 54 | {88FE28D1-C669-4972-9D7A-F171BA951ACB}.Debug|x86.Build.0 = Debug|Win32 55 | {88FE28D1-C669-4972-9D7A-F171BA951ACB}.Release|x64.ActiveCfg = Release|x64 56 | {88FE28D1-C669-4972-9D7A-F171BA951ACB}.Release|x64.Build.0 = Release|x64 57 | {88FE28D1-C669-4972-9D7A-F171BA951ACB}.Release|x86.ActiveCfg = Release|Win32 58 | {88FE28D1-C669-4972-9D7A-F171BA951ACB}.Release|x86.Build.0 = Release|Win32 59 | EndGlobalSection 60 | GlobalSection(SolutionProperties) = preSolution 61 | HideSolutionNode = FALSE 62 | EndGlobalSection 63 | GlobalSection(ExtensibilityGlobals) = postSolution 64 | SolutionGuid = {B5E75124-7872-49A9-A21F-03163D50B2CB} 65 | EndGlobalSection 66 | EndGlobal 67 | -------------------------------------------------------------------------------- /CPPAtomic.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CPPAtomic.xcodeproj/project.xcworkspace/xcshareddata/CPPAtomic.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "EA75150531006966844D38F6DEFA072DB263D143", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "4F4879F2E25D04EBC38382F7A99A1BCC9BCF718D" : 9223372036854775807, 8 | "A59B79241FF48B87B8A2D6239F13C873F14163E3" : 0, 9 | "248A62F434CE9D949AE1E3B8B5068FE0FE776794" : 9223372036854775807, 10 | "EA75150531006966844D38F6DEFA072DB263D143" : 0 11 | }, 12 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "4D24E997-0D75-44C2-BFC1-E9C20F9E1376", 13 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 14 | "4F4879F2E25D04EBC38382F7A99A1BCC9BCF718D" : "CPPAtomic\/Submodules\/CrashGuard\/", 15 | "A59B79241FF48B87B8A2D6239F13C873F14163E3" : "CPPAtomic\/Submodules\/CPPTraits\/Submodules\/gmock-xcode\/", 16 | "248A62F434CE9D949AE1E3B8B5068FE0FE776794" : "CPPAtomic\/Submodules\/CPPTraits\/", 17 | "EA75150531006966844D38F6DEFA072DB263D143" : "CPPAtomic\/" 18 | }, 19 | "DVTSourceControlWorkspaceBlueprintNameKey" : "CPPAtomic", 20 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 21 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "CPPAtomic.xcodeproj", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 23 | { 24 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/macmade\/CPPTraits.git", 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "248A62F434CE9D949AE1E3B8B5068FE0FE776794" 27 | }, 28 | { 29 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/macmade\/CrashGuard.git", 30 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 31 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "4F4879F2E25D04EBC38382F7A99A1BCC9BCF718D" 32 | }, 33 | { 34 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/macmade\/gmock-xcode.git", 35 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 36 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "A59B79241FF48B87B8A2D6239F13C873F14163E3" 37 | }, 38 | { 39 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:macmade\/CPPAtomic.git", 40 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 41 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "EA75150531006966844D38F6DEFA072DB263D143" 42 | } 43 | ] 44 | } -------------------------------------------------------------------------------- /CPPAtomic.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CPPAtomic.xcodeproj/project.xcworkspace/xcshareddata/PIMPL.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "EA75150531006966844D38F6DEFA072DB263D143", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "EA75150531006966844D38F6DEFA072DB263D143" : 0, 8 | "A59B79241FF48B87B8A2D6239F13C873F14163E3" : 0, 9 | "DC27B5DA8A3BAEC9EFF8F0DE9ED4ADFB1116243D" : 0 10 | }, 11 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "5521C9A6-96AA-455E-BEE7-6714F09EF258", 12 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 13 | "EA75150531006966844D38F6DEFA072DB263D143" : "CPPAtomic\/", 14 | "A59B79241FF48B87B8A2D6239F13C873F14163E3" : "PIMPL\/Submodules\/gmock-xcode\/", 15 | "DC27B5DA8A3BAEC9EFF8F0DE9ED4ADFB1116243D" : "PIMPL" 16 | }, 17 | "DVTSourceControlWorkspaceBlueprintNameKey" : "PIMPL", 18 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 19 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "PIMPL.xcodeproj", 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 21 | { 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/macmade\/gmock-xcode.git", 23 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 24 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "A59B79241FF48B87B8A2D6239F13C873F14163E3" 25 | }, 26 | { 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:macmade\/PIMPL.git", 28 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 29 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "DC27B5DA8A3BAEC9EFF8F0DE9ED4ADFB1116243D" 30 | }, 31 | { 32 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:macmade\/CPPAtomic.git", 33 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 34 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "EA75150531006966844D38F6DEFA072DB263D143" 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /CPPAtomic.xcodeproj/xcshareddata/xcschemes/CPPAtomic-Tests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 54 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /CPPAtomic.xcodeproj/xcshareddata/xcschemes/CPPAtomic.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 42 | 48 | 49 | 50 | 51 | 52 | 62 | 63 | 69 | 70 | 71 | 72 | 78 | 79 | 85 | 86 | 87 | 88 | 90 | 91 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /CPPAtomic/include/XS/Atomic-Functions.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #ifndef XS_ATOMIC_FUNCTIONS_HPP 31 | #define XS_ATOMIC_FUNCTIONS_HPP 32 | 33 | /* 34 | * Using stdint.h rather than cstdint as exact-width integer types are optional 35 | */ 36 | #include 37 | 38 | namespace XS 39 | { 40 | /*! 41 | * @brief Issues a memory barrier/fence 42 | * 43 | * Currently, this function is implemented for the following 44 | * architectures: 45 | * - ARMv7 46 | * - ARM64 47 | * - x86 48 | * - x86-64 49 | */ 50 | void MemoryBarrier( void ); 51 | 52 | /*! 53 | * @brief Atomically increments a 32 bits integer value 54 | * @param value The value to increment 55 | * @return The incremented value 56 | */ 57 | int32_t AtomicIncrement32( volatile int32_t * value ); 58 | 59 | /*! 60 | * @brief Atomically increments a 32 bits integer value 61 | * @param value The value to increment 62 | * @return The incremented value 63 | */ 64 | int64_t AtomicIncrement64( volatile int64_t * value ); 65 | 66 | /*! 67 | * @brief Atomically decrements a 64 bits integer value 68 | * @param value The value to decrement 69 | * @return The decremented value 70 | */ 71 | int32_t AtomicDecrement32( volatile int32_t * value ); 72 | 73 | /*! 74 | * @brief Atomically decrements a 64 bits integer value 75 | * @param value The value to decrement 76 | * @return The decremented value 77 | */ 78 | int64_t AtomicDecrement64( volatile int64_t * value ); 79 | 80 | /*! 81 | * @brief Atomically adds to a 32 bits value 82 | * @param amount The amount to add 83 | * @param value The 32 bits value to modify 84 | * @return The new value 85 | */ 86 | int32_t AtomicAdd32( int32_t amount, volatile int32_t * value ); 87 | 88 | /*! 89 | * @brief Atomically adds to a 64 bits value 90 | * @param amount The amount to add 91 | * @param value The 64 bits value to modify 92 | * @return The new value 93 | */ 94 | int64_t AtomicAdd64( int64_t amount, volatile int64_t * value ); 95 | 96 | /*! 97 | * @brief Performs an atomic compare and swap on 32 bits integer values 98 | * @param oldValue The value to compare to (old value) 99 | * @param newValue The value to swap (new value) 100 | * @param value A pointer to the 32 bits integer value to compare and swap 101 | * @return True if the comparison was equal and the swap occured, otherwise false 102 | */ 103 | bool AtomicCompareAndSwap32( int32_t oldValue, int32_t newValue, volatile int32_t * value ); 104 | 105 | /*! 106 | * @brief Performs an atomic compare and swap on 64 bits integer values 107 | * @param oldValue The value to compare to (old value) 108 | * @param newValue The value to swap (new value) 109 | * @param value A pointer to the 64 bits integer value to compare and swap 110 | * @return True if the comparison was equal and the swap occured, otherwise false 111 | */ 112 | bool AtomicCompareAndSwap64( int64_t oldValue, int64_t newValue, volatile int64_t * value ); 113 | 114 | /*! 115 | * @brief Performs an atomic compare and swap on pointer values 116 | * @param oldValue The value to compare to (old value) 117 | * @param newValue The value to swap (new value) 118 | * @param value A pointer to the pointer value to compare and swap 119 | * @return True if the comparison was equal and the swap occured, otherwise false 120 | */ 121 | bool AtomicCompareAndSwapPointer( void * oldValue, void * newValue, void * volatile * value ); 122 | } 123 | 124 | #endif /* XS_ATOMIC_FUNCTIONS_HPP */ 125 | -------------------------------------------------------------------------------- /CPPAtomic/include/XS/IPC/RWLock.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #ifndef XS_IPC_RW_LOCK_HPP 31 | #define XS_IPC_RW_LOCK_HPP 32 | 33 | #include 34 | 35 | namespace XS 36 | { 37 | namespace IPC 38 | { 39 | class RWLock: public XS::PIMPL::Object< RWLock > 40 | { 41 | public: 42 | 43 | using XS::PIMPL::Object< RWLock >::impl; 44 | 45 | RWLock( void ); 46 | 47 | RWLock( const RWLock & o ) = delete; 48 | RWLock( RWLock && o ) = delete; 49 | RWLock & operator =( RWLock o ) = delete; 50 | 51 | void LockForReading( void ); 52 | void LockForWriting( void ); 53 | void UnlockForReading( void ); 54 | void UnlockForWriting( void ); 55 | bool TryLockForReading( void ); 56 | bool TryLockForWriting( void ); 57 | }; 58 | } 59 | } 60 | 61 | #endif /* XS_IPC_RW_LOCK_HPP */ 62 | -------------------------------------------------------------------------------- /CPPAtomic/include/XS/IPC/Semaphore.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #ifndef XS_IPC_SEMAPHORE_HPP 31 | #define XS_IPC_SEMAPHORE_HPP 32 | 33 | #include 34 | #include 35 | 36 | namespace XS 37 | { 38 | namespace IPC 39 | { 40 | class Semaphore: public XS::PIMPL::Object< Semaphore > 41 | { 42 | public: 43 | 44 | using XS::PIMPL::Object< Semaphore >::impl; 45 | 46 | Semaphore( unsigned int count = 1, std::string name = "" ); 47 | 48 | Semaphore( const Semaphore & o ) = delete; 49 | Semaphore( Semaphore && o ) = delete; 50 | Semaphore & operator =( Semaphore o ) = delete; 51 | 52 | bool TryWait( void ); 53 | void Wait( void ); 54 | void Signal( void ); 55 | 56 | bool IsNamed( void ) const; 57 | std::string GetName( void ) const; 58 | 59 | class Guard: public XS::PIMPL::Object< Guard > 60 | { 61 | public: 62 | 63 | using XS::PIMPL::Object< Guard >::impl; 64 | 65 | Guard( Semaphore & semaphore ); 66 | 67 | Guard( const Guard & o ) = delete; 68 | Guard( Guard && o ) = delete; 69 | Guard & operator =( Guard o ) = delete; 70 | Guard & operator =( Guard && o ) = delete; 71 | }; 72 | }; 73 | } 74 | } 75 | 76 | #endif /* XS_IPC_SEMAPHORE_HPP */ 77 | -------------------------------------------------------------------------------- /CPPAtomic/include/XS/IPC/SharedMemory.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #ifndef XS_IPC_SHARED_MEMORY_HPP 31 | #define XS_IPC_SHARED_MEMORY_HPP 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | namespace XS 38 | { 39 | namespace IPC 40 | { 41 | class SharedMemory: public XS::PIMPL::Object< SharedMemory > 42 | { 43 | public: 44 | 45 | using XS::PIMPL::Object< SharedMemory >::impl; 46 | 47 | SharedMemory( void ); 48 | SharedMemory( int32_t key, size_t size ); 49 | 50 | bool operator ==( const SharedMemory & o ) const; 51 | bool operator !=( const SharedMemory & o ) const; 52 | 53 | void * Get( void ) const; 54 | size_t GetSize( void ) const; 55 | bool IsValid( void ) const; 56 | 57 | template< typename _T_ > 58 | _T_ Get( void ) const 59 | { 60 | return reinterpret_cast< _T_ >( this->Get() ); 61 | } 62 | }; 63 | } 64 | } 65 | 66 | #endif /* XS_IPC_SHARED_MEMORY_HPP */ 67 | -------------------------------------------------------------------------------- /CPPAtomic/include/XS/RWLock.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #ifndef XS_RW_LOCK_HPP 31 | #define XS_RW_LOCK_HPP 32 | 33 | #include 34 | 35 | namespace XS 36 | { 37 | class RWLock: public XS::PIMPL::Object< RWLock > 38 | { 39 | public: 40 | 41 | using XS::PIMPL::Object< RWLock >::impl; 42 | 43 | RWLock( void ); 44 | 45 | RWLock( const RWLock & o ) = delete; 46 | RWLock( RWLock && o ) = delete; 47 | RWLock & operator =( RWLock o ) = delete; 48 | 49 | void LockForReading( void ); 50 | void LockForWriting( void ); 51 | void UnlockForReading( void ); 52 | void UnlockForWriting( void ); 53 | bool TryLockForReading( void ); 54 | bool TryLockForWriting( void ); 55 | }; 56 | } 57 | 58 | #endif /* XS_RW_LOCK_HPP */ 59 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/AtomicAdd32.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #if defined( _WIN32 ) 33 | 34 | #include 35 | #include 36 | 37 | #elif defined( __APPLE__ ) 38 | 39 | #include 40 | 41 | #endif 42 | 43 | namespace XS 44 | { 45 | int32_t AtomicAdd32( int32_t amount, volatile int32_t * value ) 46 | { 47 | #if defined( _WIN32 ) 48 | 49 | return InterlockedExchangeAdd( reinterpret_cast< volatile LONG * >( value ), amount ) + amount; 50 | 51 | #elif defined( __APPLE__ ) 52 | 53 | return OSAtomicAdd32( amount, value ); 54 | 55 | #elif __has_builtin( __sync_add_and_fetch ) 56 | 57 | return __sync_add_and_fetch( value, amount ); 58 | 59 | #else 60 | 61 | #error "XS::Atomic::Add32 is not implemented for the current platform" 62 | 63 | #endif 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/AtomicAdd64.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #if defined( _WIN32 ) 33 | 34 | #include 35 | #include 36 | 37 | #elif defined( __APPLE__ ) 38 | 39 | #include 40 | 41 | #endif 42 | 43 | namespace XS 44 | { 45 | int64_t AtomicAdd64( int64_t amount, volatile int64_t * value ) 46 | { 47 | #if defined( _WIN32 ) 48 | 49 | return InterlockedExchangeAdd64( reinterpret_cast< volatile LONGLONG * >( value ), amount ) + amount; 50 | 51 | #elif defined( __APPLE__ ) 52 | 53 | return OSAtomicAdd64( amount, value ); 54 | 55 | #elif __has_builtin( __sync_add_and_fetch ) 56 | 57 | return __sync_add_and_fetch( value, amount ); 58 | 59 | #else 60 | 61 | #error "XS::Atomic::Add64 is not implemented for the current platform" 62 | 63 | #endif 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/AtomicCompareAndSwap32.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #if defined( _WIN32 ) 33 | 34 | #include 35 | #include 36 | 37 | #elif defined( __APPLE__ ) 38 | 39 | #include 40 | 41 | #endif 42 | 43 | namespace XS 44 | { 45 | bool AtomicCompareAndSwap32( int32_t oldValue, int32_t newValue, volatile int32_t * value ) 46 | { 47 | #if defined( _WIN32 ) 48 | 49 | return ( InterlockedCompareExchange( reinterpret_cast< volatile LONG * >( value ), newValue, oldValue ) == oldValue ) ? true : false; 50 | 51 | #elif defined( __APPLE__ ) 52 | 53 | return ( OSAtomicCompareAndSwap32( oldValue, newValue, value ) ) ? true : false; 54 | 55 | #elif __has_builtin( __sync_bool_compare_and_swap ) 56 | 57 | return __sync_bool_compare_and_swap( value, oldValue, newValue ); 58 | 59 | #else 60 | 61 | #error "XS::Atomic::CompareAndSwap32 is not implemented for the current platform" 62 | 63 | #endif 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/AtomicCompareAndSwap64.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #if defined( _WIN32 ) 33 | 34 | #include 35 | #include 36 | 37 | #elif defined( __APPLE__ ) 38 | 39 | #include 40 | 41 | #endif 42 | 43 | namespace XS 44 | { 45 | bool AtomicCompareAndSwap64( int64_t oldValue, int64_t newValue, volatile int64_t * value ) 46 | { 47 | #if defined( _WIN32 ) 48 | 49 | return ( InterlockedCompareExchange64( reinterpret_cast< volatile LONGLONG * >( value ), newValue, oldValue ) == oldValue ) ? true : false; 50 | 51 | #elif defined( __APPLE__ ) 52 | 53 | return ( OSAtomicCompareAndSwap64( oldValue, newValue, value ) ) ? true : false; 54 | 55 | #elif __has_builtin( __sync_bool_compare_and_swap ) 56 | 57 | return __sync_bool_compare_and_swap( value, oldValue, newValue ); 58 | 59 | #else 60 | 61 | #error "XS::Atomic::CompareAndSwap64 is not implemented for the current platform" 62 | 63 | #endif 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/AtomicCompareAndSwapPointer.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #if defined( _WIN32 ) 33 | 34 | #include 35 | #include 36 | 37 | #elif defined( __APPLE__ ) 38 | 39 | #include 40 | 41 | #endif 42 | 43 | namespace XS 44 | { 45 | bool AtomicCompareAndSwapPointer( void * oldValue, void * newValue, void * volatile * value ) 46 | { 47 | #if defined( _WIN32 ) 48 | 49 | return ( InterlockedCompareExchangePointer( value, newValue, oldValue ) == oldValue ) ? true : false; 50 | 51 | #elif defined( __APPLE__ ) 52 | 53 | return ( OSAtomicCompareAndSwapPtr( oldValue, newValue, value ) ) ? true : false; 54 | 55 | #elif __has_builtin( __sync_bool_compare_and_swap ) 56 | 57 | return __sync_bool_compare_and_swap( value, oldValue, newValue ); 58 | 59 | #else 60 | 61 | #error "XS::Atomic::CompareAndSwapPointer is not implemented for the current platform" 62 | 63 | #endif 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/AtomicDecrement32.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #if defined( _WIN32 ) 33 | 34 | #include 35 | #include 36 | 37 | #elif defined( __APPLE__ ) 38 | 39 | #include 40 | 41 | #endif 42 | 43 | namespace XS 44 | { 45 | int32_t AtomicDecrement32( volatile int32_t * value ) 46 | { 47 | #if defined( _WIN32 ) 48 | 49 | return InterlockedDecrement( reinterpret_cast< volatile LONG * >( value ) ); 50 | 51 | #elif defined( __APPLE__ ) 52 | 53 | return OSAtomicDecrement32( value ); 54 | 55 | #elif __has_builtin( __sync_add_and_fetch ) 56 | 57 | return __sync_add_and_fetch( value, -1 ); 58 | 59 | #else 60 | 61 | #error "XS::Atomic::Decrement32 is not implemented for the current platform" 62 | 63 | #endif 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/AtomicDecrement64.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #if defined( _WIN32 ) 33 | 34 | #include 35 | #include 36 | 37 | #elif defined( __APPLE__ ) 38 | 39 | #include 40 | 41 | #endif 42 | 43 | namespace XS 44 | { 45 | int64_t AtomicDecrement64( volatile int64_t * value ) 46 | { 47 | #if defined( _WIN32 ) 48 | 49 | return InterlockedDecrement64( reinterpret_cast< volatile LONGLONG * >( value ) ); 50 | 51 | #elif defined( __APPLE__ ) 52 | 53 | return OSAtomicDecrement64( value ); 54 | 55 | #elif __has_builtin( __sync_add_and_fetch ) 56 | 57 | return __sync_add_and_fetch( value, -1 ); 58 | 59 | #else 60 | 61 | #error "XS::Atomic::Decrement64 is not implemented for the current platform" 62 | 63 | #endif 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/AtomicIncrement32.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #if defined( _WIN32 ) 33 | 34 | #include 35 | #include 36 | 37 | #elif defined( __APPLE__ ) 38 | 39 | #include 40 | 41 | #endif 42 | 43 | namespace XS 44 | { 45 | int32_t AtomicIncrement32( volatile int32_t * value ) 46 | { 47 | #if defined( _WIN32 ) 48 | 49 | return InterlockedIncrement( reinterpret_cast< volatile LONG * >( value ) ); 50 | 51 | #elif defined( __APPLE__ ) 52 | 53 | return OSAtomicIncrement32( value ); 54 | 55 | #elif __has_builtin( __sync_add_and_fetch ) 56 | 57 | return __sync_add_and_fetch( value, 1 ); 58 | 59 | #else 60 | 61 | #error "XS::AtomicIncrement32 is not implemented for the current platform" 62 | 63 | #endif 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/AtomicIncrement64.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #if defined( _WIN32 ) 33 | 34 | #include 35 | #include 36 | 37 | #elif defined( __APPLE__ ) 38 | 39 | #include 40 | 41 | #endif 42 | 43 | namespace XS 44 | { 45 | int64_t AtomicIncrement64( volatile int64_t * value ) 46 | { 47 | #if defined( _WIN32 ) 48 | 49 | return InterlockedIncrement64( reinterpret_cast< volatile LONGLONG * >( value ) ); 50 | 51 | #elif defined( __APPLE__ ) 52 | 53 | return OSAtomicIncrement64( value ); 54 | 55 | #elif __has_builtin( __sync_add_and_fetch ) 56 | 57 | return __sync_add_and_fetch( value, 1 ); 58 | 59 | #else 60 | 61 | #error "XS::Atomic::Increment64 is not implemented for the current platform" 62 | 63 | #endif 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CPPAtomic/source/Atomic-Functions/MemoryBarrier.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #ifdef _WIN32 33 | #include 34 | #endif 35 | 36 | namespace XS 37 | { 38 | #ifdef MemoryBarrier 39 | #undef MemoryBarrier /* VisualStudio x64 */ 40 | #endif 41 | void MemoryBarrier( void ) 42 | { 43 | #if defined( _WIN64 ) && defined( _M_AMD64 ) 44 | 45 | ::__faststorefence(); 46 | 47 | #elif defined( _WIN32 ) && defined( _M_IX86 ) 48 | 49 | __asm mfence; 50 | 51 | #elif defined( _WIN32 ) && defined( _M_ARM ) 52 | 53 | __asm dmb sy; 54 | 55 | #elif defined( __ARM_ARCH ) 56 | 57 | __asm__ __volatile__ 58 | ( 59 | "dmb sy" 60 | ); 61 | 62 | #elif defined( __i386__ ) || defined( __x86_64__ ) 63 | 64 | __asm__ __volatile__ 65 | ( 66 | "mfence" 67 | ); 68 | 69 | #else 70 | 71 | #error "XS::MemoryBarrier is not implemented for the current target architecture" 72 | 73 | #endif 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /CPPAtomic/source/IPC/RWLock.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | namespace XS 35 | { 36 | template<> 37 | class XS::PIMPL::Object< IPC::RWLock >::IMPL 38 | { 39 | public: 40 | 41 | IMPL( void ); 42 | IMPL( const IMPL & o ); 43 | ~IMPL( void ); 44 | 45 | IPC::Semaphore _rsem; 46 | IPC::Semaphore _wsem; 47 | IPC::SharedMemory _r; 48 | }; 49 | } 50 | 51 | #define XS_PIMPL_CLASS XS::IPC::RWLock 52 | #include 53 | 54 | namespace XS 55 | { 56 | namespace IPC 57 | { 58 | RWLock::RWLock( void ): 59 | XS::PIMPL::Object< RWLock >() 60 | {} 61 | 62 | void RWLock::LockForReading( void ) 63 | {} 64 | 65 | void RWLock::LockForWriting( void ) 66 | {} 67 | 68 | void RWLock::UnlockForReading( void ) 69 | {} 70 | 71 | void RWLock::UnlockForWriting( void ) 72 | {} 73 | 74 | bool RWLock::TryLockForReading( void ) 75 | { 76 | return false; 77 | } 78 | 79 | bool RWLock::TryLockForWriting( void ) 80 | { 81 | return false; 82 | } 83 | } 84 | 85 | PIMPL::Object< IPC::RWLock >::IMPL::IMPL( void ) 86 | {} 87 | 88 | PIMPL::Object< IPC::RWLock >::IMPL::IMPL( const IMPL & o ) 89 | { 90 | ( void )o; 91 | } 92 | 93 | PIMPL::Object< IPC::RWLock >::IMPL::~IMPL( void ) 94 | {} 95 | } 96 | -------------------------------------------------------------------------------- /CPPAtomic/source/IPC/Semaphore.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #ifndef _WIN32 33 | #include 34 | #endif 35 | 36 | #ifdef __APPLE__ 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #else 44 | #include 45 | #include 46 | #include 47 | #endif 48 | 49 | #include 50 | #include 51 | 52 | #ifndef SEM_NAME_MAX 53 | #define SEM_NAME_MAX 32 54 | #endif 55 | 56 | static std::recursive_mutex * rmtx = nullptr; 57 | static std::vector< XS::IPC::Semaphore * > * semaphores = nullptr; 58 | 59 | namespace XS 60 | { 61 | template<> 62 | class XS::PIMPL::Object< IPC::Semaphore >::IMPL 63 | { 64 | public: 65 | 66 | IMPL( unsigned int count = 1, std::string name = "" ); 67 | IMPL( const IMPL & o ); 68 | ~IMPL( void ); 69 | 70 | void CreateSemaphore( void ); 71 | void DeleteSemaphore( void ); 72 | 73 | unsigned int _count; 74 | std::string _name; 75 | 76 | #if defined( _WIN32 ) 77 | 78 | HANDLE _semaphore; 79 | 80 | #elif defined( __APPLE__ ) 81 | 82 | sem_t * _semp; 83 | semaphore_t _semaphore; 84 | 85 | #else 86 | #error "Unsupported platform" 87 | #endif 88 | }; 89 | } 90 | 91 | #define XS_PIMPL_CLASS XS::IPC::Semaphore 92 | #include 93 | 94 | namespace XS 95 | { 96 | namespace IPC 97 | { 98 | /*************************************************************************** 99 | * Common 100 | **************************************************************************/ 101 | 102 | Semaphore::Semaphore( unsigned int count, std::string name ): 103 | XS::PIMPL::Object< Semaphore >( count, name ) 104 | {} 105 | 106 | bool Semaphore::IsNamed( void ) const 107 | { 108 | return this->impl->_name.length() > 0; 109 | } 110 | 111 | std::string Semaphore::GetName( void ) const 112 | { 113 | return this->impl->_name; 114 | } 115 | 116 | /*************************************************************************** 117 | * Windows specific 118 | **************************************************************************/ 119 | 120 | #if defined( _WIN32 ) 121 | 122 | bool Semaphore::TryWait( void ) 123 | { 124 | return ( WaitForSingleObject( this->impl->_semaphore, 0 ) == WAIT_OBJECT_0 ) ? true : false; 125 | } 126 | 127 | void Semaphore::Wait( void ) 128 | { 129 | WaitForSingleObject( this->impl->_semaphore, INFINITE ); 130 | } 131 | 132 | void Semaphore::Signal( void ) 133 | { 134 | ReleaseSemaphore( this->impl->_semaphore, 1, nullptr ); 135 | } 136 | 137 | /*************************************************************************** 138 | * Apple specific 139 | **************************************************************************/ 140 | 141 | #elif defined( __APPLE__ ) 142 | 143 | bool Semaphore::TryWait( void ) 144 | { 145 | bool ret; 146 | 147 | if( this->IsNamed() ) 148 | { 149 | ret = ( sem_trywait( this->impl->_semp ) == 0 ) ? true : false; 150 | } 151 | else 152 | { 153 | { 154 | mach_timespec_t ts; 155 | 156 | ts.tv_sec = 0; 157 | ts.tv_nsec = 0; 158 | 159 | ret = ( semaphore_timedwait( this->impl->_semaphore, ts ) == KERN_SUCCESS ) ? true : false; 160 | } 161 | } 162 | 163 | if( ret && this->impl->_name.length() > 0 ) 164 | { 165 | rmtx->lock(); 166 | semaphores->push_back( this ); 167 | rmtx->unlock(); 168 | } 169 | 170 | return ret; 171 | } 172 | 173 | void Semaphore::Wait( void ) 174 | { 175 | if( this->IsNamed() ) 176 | { 177 | sem_wait( this->impl->_semp ); 178 | } 179 | else 180 | { 181 | semaphore_wait( this->impl->_semaphore ); 182 | } 183 | 184 | if( this->impl->_name.length() > 0 ) 185 | { 186 | rmtx->lock(); 187 | semaphores->push_back( this ); 188 | rmtx->unlock(); 189 | } 190 | } 191 | 192 | void Semaphore::Signal( void ) 193 | { 194 | if( this->IsNamed() ) 195 | { 196 | sem_post( this->impl->_semp ); 197 | } 198 | else 199 | { 200 | semaphore_signal( this->impl->_semaphore ); 201 | } 202 | 203 | if( this->impl->_name.length() > 0 ) 204 | { 205 | rmtx->lock(); 206 | 207 | { 208 | auto p = std::find( semaphores->begin(), semaphores->end(), this ); 209 | 210 | if( p != semaphores->end() ) 211 | { 212 | semaphores->erase( p ); 213 | } 214 | } 215 | 216 | rmtx->unlock(); 217 | } 218 | } 219 | 220 | #endif 221 | } 222 | 223 | /*************************************************************************** 224 | * Common 225 | **************************************************************************/ 226 | 227 | PIMPL::Object< IPC::Semaphore >::IMPL::IMPL( unsigned int count, std::string name ): 228 | _count( count ), 229 | _name( name ) 230 | { 231 | #ifndef _WIN32 232 | 233 | static std::once_flag once; 234 | 235 | if( name.length() > 0 ) 236 | { 237 | std::call_once 238 | ( 239 | once, 240 | [] 241 | { 242 | rmtx = new std::recursive_mutex(); 243 | semaphores = new std::vector< XS::IPC::Semaphore * >(); 244 | 245 | XS::CrashGuard::InstallHandler 246 | ( 247 | [] 248 | { 249 | for( auto s: *( semaphores ) ) 250 | { 251 | s->Signal(); 252 | } 253 | 254 | semaphores->clear(); 255 | } 256 | ); 257 | } 258 | ); 259 | } 260 | 261 | #endif 262 | 263 | this->CreateSemaphore(); 264 | } 265 | 266 | PIMPL::Object< IPC::Semaphore >::IMPL::IMPL( const IMPL & o ): 267 | _count( o._count ), 268 | _name( o._name ) 269 | { 270 | this->CreateSemaphore(); 271 | } 272 | 273 | PIMPL::Object< IPC::Semaphore >::IMPL::~IMPL( void ) 274 | { 275 | this->DeleteSemaphore(); 276 | } 277 | 278 | /*************************************************************************** 279 | * Windows specific 280 | **************************************************************************/ 281 | 282 | #ifdef _WIN32 283 | 284 | void PIMPL::Object< IPC::Semaphore >::IMPL::CreateSemaphore( void ) 285 | { 286 | if( this->_count == 0 ) 287 | { 288 | throw std::runtime_error( "Cannot initialize a semaphore with zero as count" ); 289 | } 290 | 291 | if( this->_name.length() > 0 ) 292 | { 293 | { 294 | std::wstring name; 295 | std::wstring_convert< std::codecvt_utf8_utf16< wchar_t > > converter; 296 | 297 | name = converter.from_bytes( this->_name ); 298 | this->_semaphore = ::CreateSemaphore( nullptr, static_cast< LONG >( this->_count ), static_cast< LONG >( this->_count ), name.c_str() ); 299 | } 300 | } 301 | else 302 | { 303 | this->_semaphore = ::CreateSemaphore( nullptr, static_cast< LONG >( this->_count ), static_cast< LONG >( this->_count ), nullptr ); 304 | } 305 | 306 | if( this->_semaphore == nullptr ) 307 | { 308 | throw std::runtime_error( "Error initializing the semaphore object" ); 309 | } 310 | } 311 | 312 | void PIMPL::Object< IPC::Semaphore >::IMPL::DeleteSemaphore( void ) 313 | { 314 | CloseHandle( this->_semaphore ); 315 | } 316 | 317 | /*************************************************************************** 318 | * Apple specific 319 | **************************************************************************/ 320 | 321 | #elif defined( __APPLE__ ) 322 | 323 | void PIMPL::Object< IPC::Semaphore >::IMPL::CreateSemaphore( void ) 324 | { 325 | if( this->_name.length() > 0 && this->_name[ 0 ] != '/' ) 326 | { 327 | this->_name = std::string( "/" ) + this->_name; 328 | } 329 | 330 | if( this->_name.length() > SEM_NAME_MAX ) 331 | { 332 | throw std::runtime_error( std::string( "Cannot initialize a semaphore with a name longer than " + std::to_string( SEM_NAME_MAX ) ) + " characters" ); 333 | } 334 | 335 | if( this->_count == 0 ) 336 | { 337 | throw std::runtime_error( "Cannot initialize a semaphore with zero as count" ); 338 | } 339 | 340 | if( this->_name.length() > 0 ) 341 | { 342 | this->_semp = sem_open( this->_name.c_str(), O_CREAT, S_IRUSR | S_IWUSR, this->_count ); 343 | 344 | if( this->_semp == nullptr || this->_semp == SEM_FAILED ) 345 | { 346 | throw std::runtime_error( "Error initializing the semaphore object" ); 347 | } 348 | } 349 | else if( semaphore_create( mach_task_self(), &( this->_semaphore ), SYNC_POLICY_FIFO, static_cast< int >( this->_count ) ) != KERN_SUCCESS ) 350 | { 351 | throw std::runtime_error( "Error initializing the semaphore object" ); 352 | } 353 | } 354 | 355 | void PIMPL::Object< IPC::Semaphore >::IMPL::DeleteSemaphore( void ) 356 | { 357 | if( this->_name.length() > 0 ) 358 | { 359 | sem_close( this->_semp ); 360 | } 361 | else 362 | { 363 | semaphore_destroy( mach_task_self(), this->_semaphore ); 364 | } 365 | } 366 | 367 | #endif 368 | } 369 | -------------------------------------------------------------------------------- /CPPAtomic/source/IPC/Semaphore/Guard.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | namespace XS 33 | { 34 | template<> 35 | class XS::PIMPL::Object< IPC::Semaphore::Guard >::IMPL 36 | { 37 | public: 38 | 39 | IMPL( void ); 40 | IMPL( const IMPL & o ); 41 | ~IMPL( void ); 42 | 43 | IPC::Semaphore * _sem; 44 | }; 45 | } 46 | 47 | #define XS_PIMPL_CLASS XS::IPC::Semaphore::Guard 48 | #include 49 | 50 | namespace XS 51 | { 52 | namespace IPC 53 | { 54 | Semaphore::Guard::Guard( Semaphore & semaphore ) 55 | { 56 | this->impl->_sem = &semaphore; 57 | 58 | this->impl->_sem->Wait(); 59 | } 60 | } 61 | 62 | IPC::Semaphore::Guard::IMPL::IMPL( void ): 63 | _sem( nullptr ) 64 | {} 65 | 66 | IPC::Semaphore::Guard::IMPL::IMPL( const IMPL & o ): 67 | _sem( nullptr ) 68 | { 69 | ( void )o; 70 | } 71 | 72 | IPC::Semaphore::Guard::IMPL::~IMPL( void ) 73 | { 74 | if( this->_sem != nullptr ) 75 | { 76 | this->_sem->Signal(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /CPPAtomic/source/IPC/SharedMemory.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #ifndef _WIN32 33 | #include 34 | #endif 35 | 36 | #ifdef _WIN32 37 | #include 38 | #else 39 | #include 40 | #include 41 | #include 42 | #endif 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | static std::recursive_mutex * rmtx = nullptr; 49 | static std::vector< XS::IPC::SharedMemory * > * memoryAreas = nullptr; 50 | 51 | namespace XS 52 | { 53 | template<> 54 | class XS::PIMPL::Object< IPC::SharedMemory >::IMPL 55 | { 56 | public: 57 | 58 | IMPL( void ); 59 | IMPL( int32_t key, size_t size ); 60 | IMPL( const IMPL & o ); 61 | ~IMPL( void ); 62 | 63 | void AcquireMemory( void ); 64 | void ReleaseMemory( void ); 65 | 66 | void * _p; 67 | size_t _size; 68 | 69 | #ifdef _WIN32 70 | 71 | 72 | 73 | #else 74 | 75 | key_t _key; 76 | 77 | #endif 78 | }; 79 | } 80 | 81 | #define XS_PIMPL_CLASS XS::IPC::SharedMemory 82 | #include 83 | 84 | namespace XS 85 | { 86 | namespace IPC 87 | { 88 | SharedMemory::SharedMemory( void ): 89 | XS::PIMPL::Object< SharedMemory >() 90 | {} 91 | 92 | SharedMemory::SharedMemory( int32_t key, size_t size ): 93 | XS::PIMPL::Object< SharedMemory >( key, size ) 94 | {} 95 | 96 | bool SharedMemory::operator ==( const SharedMemory & o ) const 97 | { 98 | if( this->impl->_p == nullptr || o.impl->_p == nullptr ) 99 | { 100 | return false; 101 | } 102 | 103 | if( this->impl->_size != o.impl->_size ) 104 | { 105 | return false; 106 | } 107 | 108 | #ifdef _WIN32 109 | 110 | 111 | 112 | #else 113 | 114 | if( this->impl->_key != o.impl->_key ) 115 | { 116 | return false; 117 | } 118 | 119 | #endif 120 | 121 | return true; 122 | } 123 | 124 | bool SharedMemory::operator !=( const SharedMemory & o ) const 125 | { 126 | return !operator ==( o ); 127 | } 128 | 129 | void * SharedMemory::Get( void ) const 130 | { 131 | return this->impl->_p; 132 | } 133 | 134 | size_t SharedMemory::GetSize( void ) const 135 | { 136 | return this->impl->_size; 137 | } 138 | 139 | bool SharedMemory::IsValid( void ) const 140 | { 141 | return this->impl->_p != nullptr; 142 | } 143 | } 144 | 145 | #ifdef _WIN32 146 | 147 | PIMPL::Object< IPC::SharedMemory >::IMPL::IMPL( void ): 148 | _p( nullptr ), 149 | _size( 0 ) 150 | {} 151 | 152 | PIMPL::Object< IPC::SharedMemory >::IMPL::IMPL( int32_t key, size_t size ): 153 | _p( nullptr ), 154 | _size( size ) 155 | { 156 | ( void )key; 157 | } 158 | 159 | PIMPL::Object< IPC::SharedMemory >::IMPL::IMPL( const IMPL & o ): 160 | _p( nullptr ), 161 | _size( o._size ) 162 | { 163 | this->AcquireMemory(); 164 | } 165 | 166 | PIMPL::Object< IPC::SharedMemory >::IMPL::~IMPL( void ) 167 | { 168 | this->ReleaseMemory(); 169 | } 170 | 171 | void PIMPL::Object< IPC::SharedMemory >::IMPL::AcquireMemory( void ) 172 | {} 173 | 174 | void PIMPL::Object< IPC::SharedMemory >::IMPL::ReleaseMemory( void ) 175 | {} 176 | 177 | #else 178 | 179 | PIMPL::Object< IPC::SharedMemory >::IMPL::IMPL( void ): 180 | _p( nullptr ), 181 | _size( 0 ), 182 | _key( 0 ) 183 | {} 184 | 185 | PIMPL::Object< IPC::SharedMemory >::IMPL::IMPL( int32_t key, size_t size ): 186 | _p( nullptr ), 187 | _size( size ), 188 | _key( key ) 189 | { 190 | static std::once_flag once; 191 | 192 | std::call_once 193 | ( 194 | once, 195 | [] 196 | { 197 | rmtx = new std::recursive_mutex(); 198 | memoryAreas = new std::vector< XS::IPC::SharedMemory * >(); 199 | 200 | XS::CrashGuard::InstallHandler 201 | ( 202 | [] 203 | { 204 | for( auto m: *( memoryAreas ) ) 205 | { 206 | m->impl->ReleaseMemory(); 207 | } 208 | 209 | memoryAreas->clear(); 210 | } 211 | ); 212 | } 213 | ); 214 | 215 | this->AcquireMemory(); 216 | } 217 | 218 | PIMPL::Object< IPC::SharedMemory >::IMPL::IMPL( const IMPL & o ): 219 | _p( nullptr ), 220 | _size( o._size ), 221 | _key( o._key ) 222 | { 223 | this->AcquireMemory(); 224 | } 225 | 226 | PIMPL::Object< IPC::SharedMemory >::IMPL::~IMPL( void ) 227 | { 228 | this->ReleaseMemory(); 229 | } 230 | 231 | void PIMPL::Object< IPC::SharedMemory >::IMPL::AcquireMemory( void ) 232 | { 233 | int id; 234 | void * p; 235 | 236 | id = shmget( this->_key, this->_size, IPC_CREAT | 0666 ); 237 | 238 | if( id < 0 ) 239 | { 240 | return; 241 | } 242 | 243 | p = shmat( id, nullptr, 0 ); 244 | 245 | if( p == reinterpret_cast< char * >( -1 ) ) 246 | { 247 | return; 248 | } 249 | 250 | this->_p = p; 251 | } 252 | 253 | void PIMPL::Object< IPC::SharedMemory >::IMPL::ReleaseMemory( void ) 254 | { 255 | if( this->_p == nullptr ) 256 | { 257 | return; 258 | } 259 | 260 | if( shmdt( this->_p ) == -1 ) 261 | { 262 | return; 263 | } 264 | 265 | shmctl( this->_key, IPC_RMID, nullptr ); 266 | } 267 | 268 | #endif 269 | } 270 | -------------------------------------------------------------------------------- /CPPAtomic/source/RWLock.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | namespace XS 35 | { 36 | template<> 37 | class XS::PIMPL::Object< RWLock >::IMPL 38 | { 39 | public: 40 | 41 | IMPL( void ); 42 | IMPL( const IMPL & o ); 43 | ~IMPL( void ); 44 | 45 | std::recursive_mutex _rrmtx; 46 | std::recursive_mutex _wrmtx; 47 | int64_t _r; 48 | }; 49 | } 50 | 51 | #define XS_PIMPL_CLASS XS::RWLock 52 | #include 53 | 54 | namespace XS 55 | { 56 | RWLock::RWLock( void ): 57 | XS::PIMPL::Object< RWLock >() 58 | {} 59 | 60 | void RWLock::LockForReading( void ) 61 | { 62 | std::lock_guard< std::recursive_mutex > l( this->impl->_rrmtx ); 63 | 64 | if( this->impl->_r == 0 ) 65 | { 66 | this->impl->_wrmtx.lock(); 67 | } 68 | 69 | this->impl->_r++; 70 | } 71 | 72 | void RWLock::LockForWriting( void ) 73 | { 74 | this->impl->_wrmtx.lock(); 75 | } 76 | 77 | void RWLock::UnlockForReading( void ) 78 | { 79 | std::lock_guard< std::recursive_mutex > l( this->impl->_rrmtx ); 80 | 81 | this->impl->_r--; 82 | 83 | if( this->impl->_r == 0 ) 84 | { 85 | this->impl->_wrmtx.unlock(); 86 | } 87 | else if( this->impl->_r < 0 ) 88 | { 89 | throw std::runtime_error( "Invalid read unlock - Read lock was not acquired" ); 90 | } 91 | } 92 | 93 | void RWLock::UnlockForWriting( void ) 94 | { 95 | this->impl->_wrmtx.unlock(); 96 | } 97 | 98 | bool RWLock::TryLockForReading( void ) 99 | { 100 | std::lock_guard< std::recursive_mutex > l( this->impl->_rrmtx ); 101 | bool r; 102 | 103 | if( this->impl->_r == 0 ) 104 | { 105 | r = this->impl->_wrmtx.try_lock(); 106 | } 107 | else 108 | { 109 | r = true; 110 | } 111 | 112 | if( r ) 113 | { 114 | this->impl->_r++; 115 | } 116 | 117 | return r; 118 | } 119 | 120 | bool RWLock::TryLockForWriting( void ) 121 | { 122 | return this->impl->_wrmtx.try_lock();; 123 | } 124 | 125 | PIMPL::Object< RWLock >::IMPL::IMPL( void ): 126 | _r( 0 ) 127 | {} 128 | 129 | PIMPL::Object< RWLock >::IMPL::IMPL( const IMPL & o ): 130 | _r( 0 ) 131 | { 132 | ( void )o; 133 | } 134 | 135 | PIMPL::Object< RWLock >::IMPL::~IMPL( void ) 136 | {} 137 | } 138 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CPPAtomic 2 | ========= 3 | 4 | [![Build Status](https://img.shields.io/github/actions/workflow/status/macmade/CPPAtomic/ci-mac.yaml?label=macOS&logo=apple)](https://github.com/macmade/CPPAtomic/actions/workflows/ci-mac.yaml) 5 | [![Build Status](https://img.shields.io/github/actions/workflow/status/macmade/CPPAtomic/ci-win.yaml?label=Windows&logo=windows)](https://github.com/macmade/CPPAtomic/actions/workflows/ci-win.yaml) 6 | [![Issues](http://img.shields.io/github/issues/macmade/CPPAtomic.svg?logo=github)](https://github.com/macmade/CPPAtomic/issues) 7 | ![Status](https://img.shields.io/badge/status-active-brightgreen.svg?logo=git) 8 | ![License](https://img.shields.io/badge/license-mit-brightgreen.svg?logo=open-source-initiative) 9 | [![Contact](https://img.shields.io/badge/follow-@macmade-blue.svg?logo=twitter&style=social)](https://twitter.com/macmade) 10 | [![Sponsor](https://img.shields.io/badge/sponsor-macmade-pink.svg?logo=github-sponsors&style=social)](https://github.com/sponsors/macmade) 11 | 12 | About 13 | ----- 14 | 15 | Replacement of `std::atomic` supporting **non trivially-copyable** types. 16 | 17 | ### Rationale 18 | 19 | C++11 introduced the awesome [`std::atomic`](http://en.cppreference.com/w/cpp/atomic/atomic) template. 20 | Unfortunately, it can only be used with [**non trivially-copyable**](http://en.cppreference.com/w/cpp/concept/TriviallyCopyable) types. 21 | 22 | This restricts its usage to primitive types and [POD](http://en.cppreference.com/w/cpp/concept/PODType) types, meaning you can't use `std::atomic` with most C++ classes (user-defined or STL). 23 | 24 | **CPPAtomic addresses this issue by providing a new template that can be used with non trivially-copyable types as well ass trivially-copyable types.** 25 | 26 | As an example, assuming the following declarations: 27 | 28 | struct s 29 | { 30 | int x; 31 | }; 32 | 33 | class A 34 | {}; 35 | 36 | class B 37 | { 38 | public: 39 | 40 | B( void ); 41 | B( const B & rhs ); 42 | }; 43 | 44 | Here's what will happen with `std::atomic`: 45 | 46 | std::atomic< struct s > s; /* OK - POD type */ 47 | std::atomic< A > a; /* OK - POD type */ 48 | std::atomic< B > b; /* Error - Class B is not trivially-copyable */ 49 | std::atomic< std::string > str; /* Error - std::string is not trivially-copyable */ 50 | 51 | In that example, class `B` is not trivially-copyable due to its copy constructor, so it cannot be used with `std::atomic`. 52 | 53 | Using `XS::Atomic` instead, everything will compile and be fine: 54 | 55 | XS::Atomic< struct s > s; /* OK */ 56 | XS::Atomic< A > a; /* OK */ 57 | XS::Atomic< B > b; /* OK */ 58 | XA::Atomic< std::string > str; /* OK */ 59 | 60 | ### Operators 61 | 62 | `XS::Atomic` overloads all operators, but uses type traits to enable specific overloads, depending on the type. 63 | 64 | For instance, the following is valid, and atomic: 65 | 66 | XS::Atomic< int > i{ 42 }; 67 | XS::Atomic< unsigned int > u{ 42 }; 68 | 69 | i++; 70 | u &= 0xFF; 71 | 72 | The following is not (compilation error): 73 | 74 | XS::Atomic< double > d{ 42 }; 75 | 76 | d &= 0xFF; 77 | 78 | Bitwise operations make no sense with floating point value, so such overloads are disabled when using a floating point type. 79 | 80 | When using classes, usual operators are also detected using type traits, and available if they are implemented: 81 | 82 | class Foo 83 | {}; 84 | 85 | class Bar 86 | { 87 | public: 88 | 89 | Bar & operator +=( const Bar & rhs ); 90 | }; 91 | 92 | XS::Atomic< Foo > f; 93 | XS::Atomic< Bar > b; 94 | 95 | f += Foo(); /* Compiler error - Foo has no such operator */ 96 | b += Bar(); /* Bar::operator+= will be used, atomically */ 97 | 98 | ### Initialisation 99 | 100 | All `XS::Atomic` objects initialise their values to a default one, using C++11 value initialisation (`{}`).. 101 | 102 | As an example, an `XS::Atomic< int >` will default to `0`. 103 | Structure types are zero-initialised as well. 104 | For classes, the default constructor will be used. 105 | 106 | ### Implementation details 107 | 108 | `XS::Atomic` internally ensures locking for all types. 109 | It will use a `std::recursive_mutex`, along with `std::lock_guard` and `std::lock`. 110 | 111 | This is necessary in order to allow operations on non trivially-copyable types, as well as operations not implemented by `std::atomic` on primitive types (see section about operators). 112 | 113 | You might still prefer `std::atomic` for primitive types, if you're concerned about potential performance issues and if your implementation provides lock-free atomicity. 114 | 115 | License 116 | ------- 117 | 118 | CPPAtomic is released under the terms of the MIT license. 119 | 120 | Repository Infos 121 | ---------------- 122 | 123 | Owner: Jean-David Gadina - XS-Labs 124 | Web: www.xs-labs.com 125 | Blog: www.noxeos.com 126 | Twitter: @macmade 127 | GitHub: github.com/macmade 128 | LinkedIn: ch.linkedin.com/in/macmade/ 129 | StackOverflow: stackoverflow.com/users/182676/macmade 130 | -------------------------------------------------------------------------------- /Scripts/.gitignore: -------------------------------------------------------------------------------- 1 | xcenv-lib.sh 2 | xcenv-tests.sh 3 | 4 | -------------------------------------------------------------------------------- /Scripts/travis-after.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Reports code coverage to coveralls.io 4 | source Scripts/xcenv-lib.sh 5 | declare -r DIR_BUILD_LIB="${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}/" 6 | source Scripts/xcenv-tests.sh 7 | declare -r DIR_BUILD_TESTS="${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}/" 8 | xcode-coveralls --include CPPAtomic --project CPPAtomic.xcodeproj "${DIR_BUILD_LIB}" "${DIR_BUILD_TESTS}" 9 | -------------------------------------------------------------------------------- /Test-Helper/main.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | int main( int argc, const char * argv[] ) 37 | { 38 | int i; 39 | std::string arg; 40 | 41 | std::cout << "Test-Helper: starting" << std::endl; 42 | 43 | for( i = 1; i < argc; i++ ) 44 | { 45 | arg = argv[ i ]; 46 | 47 | if( arg == "sleep" ) 48 | { 49 | { 50 | unsigned int sec; 51 | 52 | if( i >= argc - 1 ) 53 | { 54 | std::cout << "Test-Helper: not enough arguments provided for " << arg << std::endl; 55 | 56 | return -1; 57 | } 58 | 59 | sec = static_cast< unsigned int >( std::stoi( argv[ ++i ] ) ); 60 | 61 | std::cout << "Test-Helper: sleeping for " << sec << " seconds" << std::endl; 62 | 63 | sleep( sec ); 64 | } 65 | } 66 | else if( arg == "sem-wait" || arg == "sem-signal" ) 67 | { 68 | { 69 | unsigned int count; 70 | std::string name; 71 | 72 | if( i >= argc - 2 ) 73 | { 74 | std::cout << "Test-Helper: not enough arguments provided for " << arg << std::endl; 75 | 76 | return -1; 77 | } 78 | 79 | count = static_cast< unsigned int >( std::stoi( argv[ ++i ] ) ); 80 | name = argv[ ++i ]; 81 | 82 | { 83 | XS::IPC::Semaphore sem( count, name ); 84 | 85 | if( arg == "sem-wait" ) 86 | { 87 | std::cout << "Test-Helper: wait on " << name << " (" << count << ")" << std::endl; 88 | 89 | sem.Wait(); 90 | } 91 | else 92 | { 93 | std::cout << "Test-Helper: signal on " << name << " (" << count << ")" << std::endl; 94 | 95 | sem.Signal(); 96 | } 97 | } 98 | } 99 | } 100 | else if( arg == "crash" ) 101 | { 102 | { 103 | volatile char * p( nullptr ); 104 | 105 | std::cout << "Test-Helper: crashing..." << std::endl; 106 | 107 | *( p ) = 0; 108 | } 109 | } 110 | else if( arg == "mem-write" ) 111 | { 112 | { 113 | int id; 114 | unsigned int size; 115 | std::string str; 116 | 117 | if( i >= argc - 3 ) 118 | { 119 | std::cout << "Test-Helper: not enough arguments provided for " << arg << std::endl; 120 | 121 | return -1; 122 | } 123 | 124 | id = std::stoi( argv[ ++i ] ); 125 | size = static_cast< unsigned int >( std::stoi( argv[ ++i ] ) ); 126 | str = argv[ ++i ]; 127 | 128 | { 129 | XS::IPC::SharedMemory mem( id, size ); 130 | 131 | if( mem.IsValid() ) 132 | { 133 | std::cout << "Test-Helper: writing \"" << str << "\" in shared memory " << id << "(" << size << ")" << std::endl; 134 | 135 | strcat( mem.Get< char * >(), str.c_str() ); 136 | } 137 | } 138 | } 139 | } 140 | } 141 | 142 | std::cout << "Test-Helper: exiting" << std::endl; 143 | 144 | return 0; 145 | } 146 | -------------------------------------------------------------------------------- /Unit-Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Unit-Tests/XS-Atomic-Functions.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #define XSTEST_GTEST_COMPAT 33 | #include 34 | 35 | TEST( XS_Atomic_Functions, AtomicIncrement32 ) 36 | { 37 | int32_t i = 0; 38 | 39 | ASSERT_EQ( XS::AtomicIncrement32( &i ), 1 ); 40 | ASSERT_EQ( i, 1 ); 41 | } 42 | 43 | TEST( XS_Atomic_Functions, AtomicIncrement64 ) 44 | { 45 | int64_t i = 0; 46 | 47 | ASSERT_EQ( XS::AtomicIncrement64( &i ), 1 ); 48 | ASSERT_EQ( i, 1 ); 49 | } 50 | 51 | TEST( XS_Atomic_Functions, AtomicDecrement32 ) 52 | { 53 | int32_t i = 0; 54 | 55 | ASSERT_EQ( XS::AtomicDecrement32( &i ), -1 ); 56 | ASSERT_EQ( i, -1 ); 57 | } 58 | 59 | TEST( XS_Atomic_Functions, AtomicDecrement64 ) 60 | { 61 | int64_t i = 0; 62 | 63 | ASSERT_EQ( XS::AtomicDecrement64( &i ), -1 ); 64 | ASSERT_EQ( i, -1 ); 65 | } 66 | 67 | TEST( XS_Atomic_Functions, AtomicAdd32 ) 68 | { 69 | int32_t i = 0; 70 | 71 | ASSERT_EQ( XS::AtomicAdd32( 2, &i ), 2 ); 72 | ASSERT_EQ( i, 2 ); 73 | } 74 | 75 | TEST( XS_Atomic_Functions, AtomicAdd64 ) 76 | { 77 | int64_t i = 0; 78 | 79 | ASSERT_EQ( XS::AtomicAdd64( 2, &i ), 2 ); 80 | ASSERT_EQ( i, 2 ); 81 | } 82 | 83 | TEST( XS_Atomic_Functions, AtomicCompareAndSwap32 ) 84 | { 85 | int32_t i = 0; 86 | 87 | ASSERT_FALSE( XS::AtomicCompareAndSwap32( 1, 2, &i ) ); 88 | ASSERT_TRUE( XS::AtomicCompareAndSwap32( 0, 2, &i ) ); 89 | ASSERT_EQ( i, 2 ); 90 | } 91 | 92 | TEST( XS_Atomic_Functions, AtomicCompareAndSwap64 ) 93 | { 94 | int64_t i = 0; 95 | 96 | ASSERT_FALSE( XS::AtomicCompareAndSwap64( 1, 2, &i ) ); 97 | ASSERT_TRUE( XS::AtomicCompareAndSwap64( 0, 2, &i ) ); 98 | ASSERT_EQ( i, 2 ); 99 | } 100 | 101 | TEST( XS_Atomic_Functions, AtomicCompareAndSwapPointer ) 102 | { 103 | void * p = nullptr; 104 | 105 | ASSERT_FALSE( XS::AtomicCompareAndSwapPointer( reinterpret_cast< void * >( 1 ), reinterpret_cast< void * >( 2 ), reinterpret_cast< void * volatile * >( &p ) ) ); 106 | ASSERT_TRUE( XS::AtomicCompareAndSwapPointer( reinterpret_cast< void * >( 0 ), reinterpret_cast< void * >( 2 ), reinterpret_cast< void * volatile * >( &p ) ) ); 107 | ASSERT_EQ( p, reinterpret_cast< void * >( 2 ) ); 108 | } 109 | 110 | TEST( XS_Atomic_Functions, MemoryBarrier ) 111 | { 112 | XS::MemoryBarrier(); 113 | } 114 | -------------------------------------------------------------------------------- /Unit-Tests/XS-Atomic-Static.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | 32 | #define XSTEST_GTEST_COMPAT 33 | #include 34 | 35 | TEST( XS_Atomic_Static, Increment ) 36 | { 37 | int32_t i32 = 0; 38 | uint32_t u32 = 0; 39 | int64_t i64 = 0; 40 | uint64_t u64 = 0; 41 | 42 | ASSERT_EQ( XS::Atomic< int32_t >::Increment( &i32 ), static_cast< int32_t >( 1 ) ); 43 | ASSERT_EQ( XS::Atomic< uint32_t >::Increment( &u32 ), static_cast< uint32_t >( 1 ) ); 44 | ASSERT_EQ( XS::Atomic< int64_t >::Increment( &i64 ), static_cast< int64_t >( 1 ) ); 45 | ASSERT_EQ( XS::Atomic< uint64_t >::Increment( &u64 ), static_cast< uint64_t >( 1 ) ); 46 | 47 | ASSERT_EQ( i32, static_cast< int32_t >( 1 ) ); 48 | ASSERT_EQ( u32, static_cast< uint32_t >( 1 ) ); 49 | ASSERT_EQ( i64, static_cast< int64_t >( 1 ) ); 50 | ASSERT_EQ( u64, static_cast< uint64_t >( 1 ) ); 51 | } 52 | 53 | TEST( XS_Atomic_Static, Decrement ) 54 | { 55 | int32_t i32 = 0; 56 | uint32_t u32 = 0; 57 | int64_t i64 = 0; 58 | uint64_t u64 = 0; 59 | 60 | ASSERT_EQ( XS::Atomic< int32_t >::Decrement( &i32 ), static_cast< int32_t >( -1 ) ); 61 | ASSERT_EQ( XS::Atomic< uint32_t >::Decrement( &u32 ), static_cast< uint32_t >( -1 ) ); 62 | ASSERT_EQ( XS::Atomic< int64_t >::Decrement( &i64 ), static_cast< int64_t >( -1 ) ); 63 | ASSERT_EQ( XS::Atomic< uint64_t >::Decrement( &u64 ), static_cast< uint64_t >( -1 ) ); 64 | 65 | ASSERT_EQ( i32, static_cast< int32_t >( -1 ) ); 66 | ASSERT_EQ( u32, static_cast< uint32_t >( -1 ) ); 67 | ASSERT_EQ( i64, static_cast< int64_t >( -1 ) ); 68 | ASSERT_EQ( u64, static_cast< uint64_t >( -1 ) ); 69 | } 70 | 71 | TEST( XS_Atomic_Static, Add ) 72 | { 73 | int32_t i32 = 0; 74 | uint32_t u32 = 0; 75 | int64_t i64 = 0; 76 | uint64_t u64 = 0; 77 | 78 | ASSERT_EQ( XS::Atomic< int32_t >::Add( 2, &i32 ), static_cast< int32_t >( 2 ) ); 79 | ASSERT_EQ( XS::Atomic< uint32_t >::Add( 2, &u32 ), static_cast< uint32_t >( 2 ) ); 80 | ASSERT_EQ( XS::Atomic< int64_t >::Add( 2, &i64 ), static_cast< int64_t >( 2 ) ); 81 | ASSERT_EQ( XS::Atomic< uint64_t >::Add( 2, &u64 ), static_cast< uint64_t >( 2 ) ); 82 | 83 | ASSERT_EQ( i32, static_cast< int32_t >( 2 ) ); 84 | ASSERT_EQ( u32, static_cast< uint32_t >( 2 ) ); 85 | ASSERT_EQ( i64, static_cast< int64_t >( 2 ) ); 86 | ASSERT_EQ( u64, static_cast< uint64_t >( 2 ) ); 87 | } 88 | 89 | TEST( XS_Atomic_Static, CompareAndSwap ) 90 | { 91 | int32_t i32 = 0; 92 | uint32_t u32 = 0; 93 | int64_t i64 = 0; 94 | uint64_t u64 = 0; 95 | void * p = nullptr; 96 | 97 | ASSERT_FALSE( XS::Atomic< int32_t >::CompareAndSwap( 1, 2, &i32 ) ); 98 | ASSERT_FALSE( XS::Atomic< uint32_t >::CompareAndSwap( 1, 2, &u32 ) ); 99 | ASSERT_FALSE( XS::Atomic< int64_t >::CompareAndSwap( 1, 2, &i64 ) ); 100 | ASSERT_FALSE( XS::Atomic< uint64_t >::CompareAndSwap( 1, 2, &u64 ) ); 101 | ASSERT_FALSE( XS::Atomic< void * >::CompareAndSwap( reinterpret_cast< void * >( 1 ), reinterpret_cast< void * >( 2 ), reinterpret_cast< void * volatile * >( &p ) ) ); 102 | 103 | ASSERT_TRUE( XS::Atomic< int32_t >::CompareAndSwap( 0, 2, &i32 ) ); 104 | ASSERT_TRUE( XS::Atomic< uint32_t >::CompareAndSwap( 0, 2, &u32 ) ); 105 | ASSERT_TRUE( XS::Atomic< int64_t >::CompareAndSwap( 0, 2, &i64 ) ); 106 | ASSERT_TRUE( XS::Atomic< uint64_t >::CompareAndSwap( 0, 2, &u64 ) ); 107 | ASSERT_TRUE( XS::Atomic< void * >::CompareAndSwap( reinterpret_cast< void * >( 0 ), reinterpret_cast< void * >( 2 ), reinterpret_cast< void * volatile * >( &p ) ) ); 108 | 109 | ASSERT_EQ( i32, static_cast< int32_t >( 2 ) ); 110 | ASSERT_EQ( u32, static_cast< uint32_t >( 2 ) ); 111 | ASSERT_EQ( i64, static_cast< int64_t >( 2 ) ); 112 | ASSERT_EQ( u64, static_cast< uint64_t >( 2 ) ); 113 | ASSERT_EQ( p, reinterpret_cast< void * >( 2 ) ); 114 | } 115 | -------------------------------------------------------------------------------- /Unit-Tests/XS-Atomic-Trivial-Bool.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief Test case XS::Atomic 28 | */ 29 | 30 | #include 31 | 32 | #define XSTEST_GTEST_COMPAT 33 | #include 34 | 35 | #ifdef __clang__ 36 | #pragma clang diagnostic ignored "-Wself-assign-overloaded" 37 | #endif 38 | 39 | /******************************************************************************* 40 | * Common definitions 41 | ******************************************************************************/ 42 | 43 | TEST( XS_Atomic_Trivial_Bool, CTOR ) 44 | { 45 | XS::Atomic< bool > a; 46 | 47 | ASSERT_TRUE( a == false ); 48 | } 49 | 50 | TEST( XS_Atomic_Trivial_Bool, CTOR_V ) 51 | { 52 | XS::Atomic< bool > a1{ true }; 53 | XS::Atomic< bool > a2{ false }; 54 | 55 | ASSERT_TRUE( a1 == true ); 56 | ASSERT_TRUE( a2 == false ); 57 | } 58 | 59 | TEST( XS_Atomic_Trivial_Bool, CCTOR ) 60 | { 61 | XS::Atomic< bool > a1{ true }; 62 | XS::Atomic< bool > a2{ a1 }; 63 | 64 | ASSERT_TRUE( a1 == true ); 65 | ASSERT_TRUE( a2 == true ); 66 | } 67 | 68 | TEST( XS_Atomic_Trivial_Bool, OperatorAssign ) 69 | { 70 | XS::Atomic< bool > a1{ true }; 71 | XS::Atomic< bool > a2; 72 | 73 | a2 = a1; 74 | 75 | ASSERT_TRUE( a1 == true ); 76 | ASSERT_TRUE( a2 == true ); 77 | 78 | a1 = a1; 79 | 80 | ASSERT_TRUE( a1 == true ); 81 | } 82 | 83 | TEST( XS_Atomic_Trivial_Bool, OperatorAssign_V ) 84 | { 85 | XS::Atomic< bool > a; 86 | 87 | a = true; 88 | 89 | ASSERT_TRUE( a == true ); 90 | } 91 | 92 | TEST( XS_Atomic_Trivial_Bool, OperatorCast ) 93 | { 94 | XS::Atomic< bool > a1{ true }; 95 | XS::Atomic< bool > a2{ false }; 96 | 97 | ASSERT_TRUE( static_cast< bool >( a1 ) == true ); 98 | ASSERT_TRUE( static_cast< bool >( a2 ) == false ); 99 | } 100 | 101 | TEST( XS_Atomic_Trivial_Bool, Load ) 102 | { 103 | XS::Atomic< bool > a1{ true }; 104 | XS::Atomic< bool > a2{ false }; 105 | 106 | ASSERT_TRUE( a1.Load() == true ); 107 | ASSERT_TRUE( a2.Load() == false ); 108 | } 109 | 110 | TEST( XS_Atomic_Trivial_Bool, Store ) 111 | { 112 | XS::Atomic< bool > a; 113 | 114 | a.Store( true ); 115 | 116 | ASSERT_TRUE( a == true ); 117 | } 118 | 119 | TEST( XS_Atomic_Trivial_Bool, Swap ) 120 | { 121 | XS::Atomic< bool > a1{ true }; 122 | XS::Atomic< bool > a2{ false }; 123 | 124 | ASSERT_TRUE( a1 == true ); 125 | ASSERT_TRUE( a2 == false ); 126 | 127 | swap( a1, a2 ); 128 | 129 | ASSERT_TRUE( a1 == false ); 130 | ASSERT_TRUE( a2 == true ); 131 | 132 | swap( a1, a1 ); 133 | 134 | ASSERT_TRUE( a1 == false ); 135 | } 136 | 137 | /******************************************************************************* 138 | * Type specific 139 | ******************************************************************************/ 140 | 141 | TEST( XS_Atomic_Trivial_Bool, NegationOperator ) 142 | { 143 | XS::Atomic< bool > a1{ false }; 144 | XS::Atomic< bool > a2{ true }; 145 | 146 | ASSERT_TRUE( !a1 ); 147 | ASSERT_FALSE( !a2 ); 148 | } 149 | 150 | TEST( XS_Atomic_Trivial_Bool, ANDOperator ) 151 | { 152 | XS::Atomic< bool > a1{ false }; 153 | XS::Atomic< bool > a2{ false }; 154 | XS::Atomic< bool > a3{ true }; 155 | XS::Atomic< bool > a4{ true }; 156 | 157 | ASSERT_FALSE( a1 && a2 ); 158 | ASSERT_FALSE( a1 && a3 ); 159 | ASSERT_TRUE( a3 && a4 ); 160 | ASSERT_FALSE( a3 && a1 ); 161 | } 162 | 163 | TEST( XS_Atomic_Trivial_Bool, ANDOperator_V ) 164 | { 165 | XS::Atomic< bool > a1{ false }; 166 | XS::Atomic< bool > a2{ true }; 167 | 168 | ASSERT_FALSE( a1 && false ); 169 | ASSERT_FALSE( a1 && true ); 170 | ASSERT_TRUE( a2 && true ); 171 | ASSERT_FALSE( a2 && false ); 172 | } 173 | 174 | TEST( XS_Atomic_Trivial_Bool, InclusiveOROperator ) 175 | { 176 | XS::Atomic< bool > a1{ false }; 177 | XS::Atomic< bool > a2{ false }; 178 | XS::Atomic< bool > a3{ true }; 179 | XS::Atomic< bool > a4{ true }; 180 | 181 | ASSERT_FALSE( a1 || a2 ); 182 | ASSERT_TRUE( a1 || a3 ); 183 | ASSERT_TRUE( a3 || a4 ); 184 | ASSERT_TRUE( a3 || a1 ); 185 | } 186 | 187 | TEST( XS_Atomic_Trivial_Bool, InclusiveOROperator_V ) 188 | { 189 | XS::Atomic< bool > a1{ false }; 190 | XS::Atomic< bool > a2{ true }; 191 | 192 | ASSERT_FALSE( a1 || false ); 193 | ASSERT_TRUE( a1 || true ); 194 | ASSERT_TRUE( a2 || true ); 195 | ASSERT_TRUE( a2 || false ); 196 | } 197 | 198 | TEST( XS_Atomic_Trivial_Bool, EqualToOperator ) 199 | { 200 | XS::Atomic< bool > a1{ false }; 201 | XS::Atomic< bool > a2{ false }; 202 | XS::Atomic< bool > a3{ true }; 203 | XS::Atomic< bool > a4{ true }; 204 | 205 | ASSERT_TRUE( a1 == a2 ); 206 | ASSERT_FALSE( a1 == a3 ); 207 | ASSERT_TRUE( a3 == a4 ); 208 | ASSERT_FALSE( a3 == a1 ); 209 | } 210 | 211 | TEST( XS_Atomic_Trivial_Bool, EqualToOperator_V ) 212 | { 213 | XS::Atomic< bool > a1{ false }; 214 | XS::Atomic< bool > a2{ true }; 215 | 216 | ASSERT_TRUE( a1 == false ); 217 | ASSERT_FALSE( a1 == true ); 218 | ASSERT_TRUE( a2 == true ); 219 | ASSERT_FALSE( a2 == false ); 220 | } 221 | 222 | TEST( XS_Atomic_Trivial_Bool, NotEqualToOperator ) 223 | { 224 | XS::Atomic< bool > a1{ false }; 225 | XS::Atomic< bool > a2{ false }; 226 | XS::Atomic< bool > a3{ true }; 227 | XS::Atomic< bool > a4{ true }; 228 | 229 | ASSERT_FALSE( a1 != a2 ); 230 | ASSERT_TRUE( a1 != a3 ); 231 | ASSERT_FALSE( a3 != a4 ); 232 | ASSERT_TRUE( a3 != a1 ); 233 | } 234 | 235 | TEST( XS_Atomic_Trivial_Bool, NotEqualToOperator_V ) 236 | { 237 | XS::Atomic< bool > a1{ false }; 238 | XS::Atomic< bool > a2{ true }; 239 | 240 | ASSERT_FALSE( a1 != false ); 241 | ASSERT_TRUE( a1 != true ); 242 | ASSERT_FALSE( a2 != true ); 243 | ASSERT_TRUE( a2 != false ); 244 | } 245 | -------------------------------------------------------------------------------- /Unit-Tests/XS-Atomic-Trivial-Struct.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief Test case XS::Atomic 28 | */ 29 | 30 | #include 31 | 32 | /* SDK version 10.11 solves issues when using a struct with std::atomic */ 33 | #if !defined( __APPLE__ ) || defined( MAC_OS_X_VERSION_10_11 ) 34 | 35 | #define XSTEST_GTEST_COMPAT 36 | #include 37 | 38 | typedef struct 39 | { 40 | int x; 41 | int y; 42 | } 43 | P; 44 | 45 | static bool IsP( P p, int x, int y ); 46 | static bool IsP( P p, int x, int y ) 47 | { 48 | return p.x == x && p.y == y; 49 | } 50 | 51 | /******************************************************************************* 52 | * Common definitions 53 | ******************************************************************************/ 54 | 55 | TEST( XS_Atomic_Trivial_Struct, CTOR ) 56 | { 57 | XS::Atomic< P > a; 58 | 59 | ASSERT_TRUE( IsP( a, 0, 0 ) ); 60 | } 61 | 62 | TEST( XS_Atomic_Trivial_Struct, CTOR_V ) 63 | { 64 | XS::Atomic< P > a{ { 42, 43 } }; 65 | 66 | ASSERT_TRUE( IsP( a, 42, 43 ) ); 67 | } 68 | 69 | TEST( XS_Atomic_Trivial_Struct, CCTOR ) 70 | { 71 | XS::Atomic< P > a1{ { 42, 43 } }; 72 | XS::Atomic< P > a2{ a1 }; 73 | 74 | ASSERT_TRUE( IsP( a1, 42, 43 ) ); 75 | ASSERT_TRUE( IsP( a2, 42, 43 ) ); 76 | } 77 | 78 | TEST( XS_Atomic_Trivial_Struct, OperatorAssign ) 79 | { 80 | XS::Atomic< P > a1{ { 42, 43 } }; 81 | XS::Atomic< P > a2; 82 | 83 | a2 = a1; 84 | 85 | ASSERT_TRUE( IsP( a1, 42, 43 ) ); 86 | ASSERT_TRUE( IsP( a2, 42, 43 ) ); 87 | 88 | #ifdef __clang__ 89 | #pragma clang diagnostic push 90 | #pragma clang diagnostic ignored "-Wself-assign-overloaded" 91 | #endif 92 | a1 = a1; 93 | #ifdef __clang__ 94 | #pragma clang diagnostic pop 95 | #endif 96 | 97 | ASSERT_TRUE( IsP( a1, 42, 43 ) ); 98 | } 99 | 100 | TEST( XS_Atomic_Trivial_Struct, OperatorAssign_V ) 101 | { 102 | XS::Atomic< P > a; 103 | 104 | a = { 42, 43 }; 105 | 106 | ASSERT_TRUE( IsP( a, 42, 43 ) ); 107 | } 108 | 109 | TEST( XS_Atomic_Trivial_Struct, OperatorCast ) 110 | { 111 | XS::Atomic< P > a{ { 42, 43 } }; 112 | 113 | ASSERT_TRUE( IsP( static_cast< P >( a ), 42, 43 ) ); 114 | } 115 | 116 | TEST( XS_Atomic_Trivial_Struct, Load ) 117 | { 118 | XS::Atomic< P > a{ { 42, 43 } }; 119 | 120 | ASSERT_TRUE( IsP( a, 42, 43 ) ); 121 | } 122 | 123 | TEST( XS_Atomic_Trivial_Struct, Store ) 124 | { 125 | XS::Atomic< P > a; 126 | 127 | a.Store( { 42, 43 } ); 128 | 129 | ASSERT_TRUE( IsP( a, 42, 43 ) ); 130 | } 131 | 132 | TEST( XS_Atomic_Trivial_Struct, Swap ) 133 | { 134 | XS::Atomic< P > a1{ { 42, 43 } }; 135 | XS::Atomic< P > a2{ { 44, 45 } }; 136 | 137 | ASSERT_TRUE( IsP( a1, 42, 43 ) ); 138 | ASSERT_TRUE( IsP( a2, 44, 45 ) ); 139 | 140 | swap( a1, a2 ); 141 | 142 | ASSERT_TRUE( IsP( a1, 44, 45 ) ); 143 | ASSERT_TRUE( IsP( a2, 42, 43 ) ); 144 | 145 | swap( a1, a1 ); 146 | 147 | ASSERT_TRUE( IsP( a1, 44, 45 ) ); 148 | } 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /Unit-Tests/XS-IPC-RWLock.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define XSTEST_GTEST_COMPAT 35 | #include 36 | 37 | /* 38 | TEST( XS_IPC_RWLock, SingleReader ) 39 | { 40 | XS::IPC::RWLock l; 41 | 42 | ASSERT_TRUE( l.TryLockForReading() ); 43 | 44 | l.UnlockForReading(); 45 | } 46 | 47 | TEST( XS_IPC_RWLock, SingleWriter ) 48 | { 49 | XS::IPC::RWLock l; 50 | 51 | ASSERT_TRUE( l.TryLockForWriting() ); 52 | 53 | l.UnlockForWriting(); 54 | } 55 | 56 | TEST( XS_IPC_RWLock, MultipleReaders_SameThread ) 57 | { 58 | XS::IPC::RWLock l; 59 | 60 | ASSERT_TRUE( l.TryLockForReading() ); 61 | ASSERT_TRUE( l.TryLockForReading() ); 62 | 63 | l.UnlockForReading(); 64 | l.UnlockForReading(); 65 | } 66 | 67 | TEST( XS_IPC_RWLock, MultipleWriters_SameThread ) 68 | { 69 | XS::IPC::RWLock l; 70 | 71 | ASSERT_TRUE( l.TryLockForWriting() ); 72 | ASSERT_TRUE( l.TryLockForWriting() ); 73 | 74 | l.UnlockForWriting(); 75 | l.UnlockForWriting(); 76 | } 77 | 78 | TEST( XS_IPC_RWLock, MultipleReaders_DifferentThreads ) 79 | { 80 | XS::IPC::RWLock l; 81 | std::atomic< bool > b( false ); 82 | 83 | l.LockForReading(); 84 | 85 | std::thread 86 | ( 87 | [ & ] 88 | { 89 | b = l.TryLockForReading(); 90 | 91 | l.UnlockForReading(); 92 | } 93 | ) 94 | .join(); 95 | 96 | ASSERT_TRUE( b ); 97 | 98 | l.UnlockForReading(); 99 | } 100 | 101 | TEST( XS_IPC_RWLock, MultipleWriters_DifferentThreads ) 102 | { 103 | XS::IPC::RWLock l; 104 | std::atomic< bool > b( false ); 105 | 106 | l.LockForWriting(); 107 | 108 | std::thread 109 | ( 110 | [ & ] 111 | { 112 | b = l.TryLockForWriting(); 113 | } 114 | ) 115 | .join(); 116 | 117 | ASSERT_FALSE( b ); 118 | 119 | l.UnlockForWriting(); 120 | 121 | std::thread 122 | ( 123 | [ & ] 124 | { 125 | b = l.TryLockForWriting(); 126 | 127 | l.UnlockForWriting(); 128 | } 129 | ) 130 | .join(); 131 | 132 | ASSERT_TRUE( b ); 133 | } 134 | 135 | TEST( XS_IPC_RWLock, ReadWrite ) 136 | { 137 | XS::IPC::RWLock l; 138 | std::atomic< bool > b( false ); 139 | 140 | l.LockForReading(); 141 | 142 | std::thread 143 | ( 144 | [ & ] 145 | { 146 | b = l.TryLockForWriting(); 147 | } 148 | ) 149 | .join(); 150 | 151 | ASSERT_FALSE( b ); 152 | 153 | l.UnlockForReading(); 154 | 155 | std::thread 156 | ( 157 | [ & ] 158 | { 159 | b = l.TryLockForWriting(); 160 | 161 | l.UnlockForWriting(); 162 | } 163 | ) 164 | .join(); 165 | 166 | ASSERT_TRUE( b ); 167 | } 168 | 169 | TEST( XS_IPC_RWLock, WriteRead ) 170 | { 171 | XS::IPC::RWLock l; 172 | std::atomic< bool > b( false ); 173 | 174 | l.LockForWriting(); 175 | 176 | std::thread 177 | ( 178 | [ & ] 179 | { 180 | b = l.TryLockForReading(); 181 | } 182 | ) 183 | .join(); 184 | 185 | ASSERT_FALSE( b ); 186 | 187 | l.UnlockForWriting(); 188 | 189 | std::thread 190 | ( 191 | [ & ] 192 | { 193 | b = l.TryLockForReading(); 194 | 195 | l.UnlockForReading(); 196 | } 197 | ) 198 | .join(); 199 | 200 | ASSERT_TRUE( b ); 201 | } 202 | 203 | TEST( XS_IPC_RWLock, ThrowOnUnownedReadUnlock ) 204 | { 205 | XS::IPC::RWLock l; 206 | 207 | ASSERT_THROW( l.UnlockForReading(), std::runtime_error ); 208 | } 209 | */ 210 | -------------------------------------------------------------------------------- /Unit-Tests/XS-IPC-Semaphore-Guard.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief 28 | */ 29 | 30 | #include 31 | 32 | #define XSTEST_GTEST_COMPAT 33 | #include 34 | 35 | TEST( XS_IPC_Semaphore_Guard, Test ) 36 | { 37 | XS::IPC::Semaphore sem( 1 ); 38 | 39 | ASSERT_TRUE( sem.TryWait() ); 40 | sem.Signal(); 41 | 42 | { 43 | XS::IPC::Semaphore::Guard g( sem ); 44 | 45 | ASSERT_FALSE( sem.TryWait() ); 46 | } 47 | 48 | ASSERT_TRUE( sem.TryWait() ); 49 | sem.Signal(); 50 | } 51 | -------------------------------------------------------------------------------- /Unit-Tests/XS-IPC-Semaphore.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include "XS-IPC-TestBase.hpp" 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | class XS_IPC_Semaphore: public XS_IPC_TestBase 37 | { 38 | public: 39 | 40 | virtual ~XS_IPC_Semaphore( void ) = default; 41 | }; 42 | 43 | TEST_F( XS_IPC_Semaphore, UnnamedBinaryTryWait ) 44 | { 45 | XS::IPC::Semaphore sem; 46 | 47 | ASSERT_TRUE( sem.TryWait() ); 48 | ASSERT_FALSE( sem.TryWait() ); 49 | 50 | sem.Signal(); 51 | } 52 | 53 | TEST_F( XS_IPC_Semaphore, NamedBinaryTryWait ) 54 | { 55 | XS::IPC::Semaphore sem1( 1, "XS-Test-Semaphore-1" ); 56 | XS::IPC::Semaphore sem2( 1, "XS-Test-Semaphore-1" ); 57 | 58 | ASSERT_TRUE( sem1.TryWait() ); 59 | ASSERT_FALSE( sem1.TryWait() ); 60 | ASSERT_FALSE( sem2.TryWait() ); 61 | 62 | sem1.Signal(); 63 | 64 | ASSERT_TRUE( sem2.TryWait() ); 65 | ASSERT_FALSE( sem2.TryWait() ); 66 | ASSERT_FALSE( sem1.TryWait() ); 67 | 68 | sem2.Signal(); 69 | } 70 | 71 | TEST_F( XS_IPC_Semaphore, UnnamedTryWait ) 72 | { 73 | XS::IPC::Semaphore sem( 2 ); 74 | 75 | ASSERT_TRUE( sem.TryWait() ); 76 | ASSERT_TRUE( sem.TryWait() ); 77 | ASSERT_FALSE( sem.TryWait() ); 78 | 79 | sem.Signal(); 80 | sem.Signal(); 81 | } 82 | 83 | TEST_F( XS_IPC_Semaphore, NamedTryWait ) 84 | { 85 | XS::IPC::Semaphore sem1( 2, "XS-Test-Semaphore-2" ); 86 | XS::IPC::Semaphore sem2( 2, "XS-Test-Semaphore-2" ); 87 | 88 | ASSERT_TRUE( sem1.TryWait() ); 89 | ASSERT_TRUE( sem1.TryWait() ); 90 | ASSERT_FALSE( sem1.TryWait() ); 91 | ASSERT_FALSE( sem2.TryWait() ); 92 | 93 | sem1.Signal(); 94 | 95 | ASSERT_TRUE( sem2.TryWait() ); 96 | ASSERT_FALSE( sem1.TryWait() ); 97 | 98 | sem1.Signal(); 99 | sem2.Signal(); 100 | } 101 | 102 | TEST_F( XS_IPC_Semaphore, UnnamedWaitSignal ) 103 | { 104 | XS::IPC::Semaphore sem( 1 ); 105 | 106 | sem.Wait(); 107 | 108 | ASSERT_FALSE( sem.TryWait() ); 109 | 110 | sem.Signal(); 111 | 112 | ASSERT_TRUE( sem.TryWait() ); 113 | 114 | sem.Signal(); 115 | } 116 | 117 | TEST_F( XS_IPC_Semaphore, NamedWaitSignal ) 118 | { 119 | XS::IPC::Semaphore sem1( 1, "XS-Test-Semaphore-1" ); 120 | XS::IPC::Semaphore sem2( 1, "XS-Test-Semaphore-1" ); 121 | 122 | sem1.Wait(); 123 | 124 | ASSERT_FALSE( sem1.TryWait() ); 125 | ASSERT_FALSE( sem2.TryWait() ); 126 | 127 | sem1.Signal(); 128 | 129 | ASSERT_TRUE( sem2.TryWait() ); 130 | ASSERT_FALSE( sem1.TryWait() ); 131 | 132 | sem2.Signal(); 133 | } 134 | 135 | TEST_F( XS_IPC_Semaphore, UnnamedThrowOnInvalidCount ) 136 | { 137 | ASSERT_THROW( XS::IPC::Semaphore( 0 ), std::runtime_error ); 138 | } 139 | 140 | TEST_F( XS_IPC_Semaphore, NamedThrowOnInvalidCount ) 141 | { 142 | ASSERT_THROW( XS::IPC::Semaphore( 0, "XS-Test-Semaphore-0" ), std::runtime_error ); 143 | } 144 | 145 | TEST_F( XS_IPC_Semaphore, NamedThrowOnInvalidName ) 146 | { 147 | std::string name( "XS-Test-Semaphore-" ); 148 | int i; 149 | 150 | for( i = 0; i < 256; i++ ) 151 | { 152 | name += "X"; 153 | } 154 | 155 | ASSERT_THROW( XS::IPC::Semaphore( 1, name ), std::runtime_error ); 156 | } 157 | 158 | TEST_F( XS_IPC_Semaphore, IsNamed ) 159 | { 160 | XS::IPC::Semaphore sem1( 1, "XS-Test-Semaphore-1" ); 161 | XS::IPC::Semaphore sem2; 162 | 163 | ASSERT_TRUE( sem1.IsNamed() ); 164 | ASSERT_FALSE( sem2.IsNamed() ); 165 | } 166 | 167 | TEST_F( XS_IPC_Semaphore, GetName ) 168 | { 169 | XS::IPC::Semaphore sem1( 1, "XS-Test-Semaphore-1" ); 170 | XS::IPC::Semaphore sem2; 171 | 172 | ASSERT_EQ( sem1.GetName(), "/XS-Test-Semaphore-1" ); 173 | ASSERT_EQ( sem2.GetName(), "" ); 174 | } 175 | 176 | TEST_F( XS_IPC_Semaphore, CrossProcess ) 177 | { 178 | XS::IPC::Semaphore sem( 1, "XS-Test-Semaphore-1" ); 179 | 180 | this->RunHelper( "sem-wait", { "1", sem.GetName() } ); 181 | ASSERT_FALSE( sem.TryWait() ); 182 | 183 | this->RunHelper( "sem-signal", { "1", sem.GetName() } ); 184 | ASSERT_TRUE( sem.TryWait() ); 185 | 186 | { 187 | std::atomic< bool > started( false ); 188 | std::atomic< bool > exited( false ); 189 | std::thread t 190 | ( 191 | [ & ] 192 | { 193 | started = true; 194 | 195 | this->RunHelper( "sem-wait", { "1", sem.GetName() } ); 196 | 197 | exited = true; 198 | } 199 | ); 200 | 201 | sleep( 1 ); 202 | ASSERT_TRUE( started ); 203 | sleep( 1 ); 204 | ASSERT_FALSE( exited ); 205 | sem.Signal(); 206 | t.join(); 207 | ASSERT_TRUE( exited ); 208 | } 209 | 210 | sem.Signal(); 211 | 212 | this->RunHelper( { { "sem-wait", { "1", sem.GetName() } }, { "crash", {} } } ); 213 | ASSERT_TRUE( sem.TryWait() ); 214 | sem.Signal(); 215 | } 216 | -------------------------------------------------------------------------------- /Unit-Tests/XS-IPC-SharedMemory.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include "XS-IPC-TestBase.hpp" 31 | #include 32 | 33 | class XS_IPC_SharedMemory: public XS_IPC_TestBase 34 | { 35 | public: 36 | 37 | virtual ~XS_IPC_SharedMemory( void ) = default; 38 | }; 39 | 40 | TEST_F( XS_IPC_SharedMemory, CTOR ) 41 | { 42 | XS::IPC::SharedMemory mem1; 43 | 44 | ASSERT_FALSE( mem1.IsValid() ); 45 | ASSERT_TRUE( mem1.GetSize() == 0 ); 46 | ASSERT_EQ( mem1.Get(), nullptr ); 47 | } 48 | 49 | TEST_F( XS_IPC_SharedMemory, CCTOR ) 50 | { 51 | XS::IPC::SharedMemory mem1( 666, 1024 ); 52 | XS::IPC::SharedMemory mem2( mem1 ); 53 | 54 | ASSERT_TRUE( mem1.IsValid() ); 55 | ASSERT_TRUE( mem2.IsValid() ); 56 | ASSERT_EQ( mem1.GetSize(), mem2.GetSize() ); 57 | ASSERT_NE( mem1.Get(), mem2.Get() ); 58 | } 59 | 60 | TEST_F( XS_IPC_SharedMemory, OperatorEqual ) 61 | { 62 | XS::IPC::SharedMemory mem1; 63 | XS::IPC::SharedMemory mem2; 64 | XS::IPC::SharedMemory mem3( 666, 1024 ); 65 | XS::IPC::SharedMemory mem4( 666, 1024 ); 66 | XS::IPC::SharedMemory mem5( 667, 1024 ); 67 | XS::IPC::SharedMemory mem6( 668, 2048 ); 68 | 69 | ASSERT_FALSE( mem1 == mem2 ); 70 | ASSERT_FALSE( mem1 == mem3 ); 71 | ASSERT_TRUE( mem3 == mem4 ); 72 | ASSERT_FALSE( mem4 == mem5 ); 73 | ASSERT_FALSE( mem4 == mem6 ); 74 | } 75 | 76 | TEST_F( XS_IPC_SharedMemory, OperatorNotEqual ) 77 | { 78 | XS::IPC::SharedMemory mem1; 79 | XS::IPC::SharedMemory mem2; 80 | XS::IPC::SharedMemory mem3( 666, 1024 ); 81 | XS::IPC::SharedMemory mem4( 666, 1024 ); 82 | 83 | ASSERT_TRUE( mem1 != mem2 ); 84 | ASSERT_TRUE( mem1 != mem3 ); 85 | ASSERT_FALSE( mem3 != mem4 ); 86 | } 87 | 88 | TEST_F( XS_IPC_SharedMemory, Get ) 89 | { 90 | void * p; 91 | XS::IPC::SharedMemory mem( 666, 1024 ); 92 | 93 | p = mem.Get(); 94 | 95 | ASSERT_NE( p, nullptr ); 96 | ASSERT_EQ( p, mem.Get< char * >() ); 97 | } 98 | 99 | TEST_F( XS_IPC_SharedMemory, GetSize ) 100 | { 101 | XS::IPC::SharedMemory mem( 666, 1024 ); 102 | 103 | ASSERT_TRUE( mem.GetSize() == 1024 ); 104 | } 105 | 106 | TEST_F( XS_IPC_SharedMemory, IsValid ) 107 | { 108 | XS::IPC::SharedMemory mem( 666, 1024 ); 109 | 110 | ASSERT_TRUE( mem.IsValid() ); 111 | } 112 | 113 | TEST_F( XS_IPC_SharedMemory, CrossProcess ) 114 | { 115 | XS::IPC::SharedMemory mem( 666, 1024 ); 116 | 117 | ASSERT_TRUE( mem.IsValid() ); 118 | 119 | memset( mem.Get(), 0, mem.GetSize() ); 120 | 121 | ASSERT_TRUE( strlen( mem.Get< char * >() ) == 0 ); 122 | 123 | this->RunHelper( "mem-write", { "666", "1024", "\"hello, world\"" } ); 124 | 125 | ASSERT_TRUE( strcmp( mem.Get< char * >(), "hello, world" ) == 0 ); 126 | 127 | this->RunHelper( { { "mem-write", { "666", "1024", "\"hello, world\"" } }, { "crash", {} } } ); 128 | 129 | ASSERT_TRUE( strcmp( mem.Get< char * >(), "hello, world" ) == 0 ); 130 | } 131 | -------------------------------------------------------------------------------- /Unit-Tests/XS-IPC-TestBase.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include "XS-IPC-TestBase.hpp" 31 | #include 32 | #include 33 | 34 | void XS_IPC_TestBase::SetUp( void ) 35 | { 36 | CFBundleRef bundle; 37 | CFURLRef url; 38 | CFStringRef str; 39 | const char * s; 40 | std::string path; 41 | 42 | bundle = CFBundleGetBundleWithIdentifier( CFSTR( "com.xs-labs.CPPAtomic-Tests" ) ); 43 | 44 | if( bundle == nullptr ) 45 | { 46 | throw std::runtime_error( "Error getting Test-Helper path in bundle" ); 47 | } 48 | 49 | url = CFBundleCopyBundleURL( bundle ); 50 | 51 | if( url == nullptr ) 52 | { 53 | throw std::runtime_error( "Error getting Test-Helper path in bundle" ); 54 | } 55 | 56 | str = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle ); 57 | 58 | if( str == nullptr ) 59 | { 60 | throw std::runtime_error( "Error getting Test-Helper path in bundle" ); 61 | } 62 | 63 | s = CFStringGetCStringPtr( str, kCFStringEncodingUTF8 ); 64 | 65 | if( s == nullptr ) 66 | { 67 | throw std::runtime_error( "Error getting Test-Helper path in bundle" ); 68 | } 69 | 70 | path = s; 71 | path += "/Contents/MacOS/Test-Helper"; 72 | 73 | CFRelease( str ); 74 | CFRelease( url ); 75 | 76 | this->_helperPath = path; 77 | } 78 | 79 | void XS_IPC_TestBase::TearDown( void ) 80 | {} 81 | 82 | void XS_IPC_TestBase::RunHelper( const std::string & command, const std::vector< std::string > & args ) const 83 | { 84 | this->RunHelper( { { command, args } } ); 85 | } 86 | 87 | void XS_IPC_TestBase::RunHelper( const std::map< std::string, std::vector< std::string > > & commands ) const 88 | { 89 | std::string invoke; 90 | 91 | invoke = this->_helperPath; 92 | 93 | for( const auto & p: commands ) 94 | { 95 | invoke += " "; 96 | invoke += p.first; 97 | 98 | for( const auto & a: p.second ) 99 | { 100 | invoke += " "; 101 | invoke += a; 102 | } 103 | } 104 | 105 | system( invoke.c_str() ); 106 | } 107 | -------------------------------------------------------------------------------- /Unit-Tests/XS-IPC-TestBase.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief ... 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define XSTEST_GTEST_COMPAT 35 | #include 36 | 37 | class XS_IPC_TestBase: public XS::Test::Case 38 | { 39 | private: 40 | 41 | std::string _helperPath; 42 | 43 | public: 44 | 45 | virtual ~XS_IPC_TestBase( void ) = default; 46 | 47 | virtual void SetUp( void ); 48 | virtual void TearDown( void ); 49 | 50 | void RunHelper( const std::string & command, const std::vector< std::string > & args ) const; 51 | void RunHelper( const std::map< std::string, std::vector< std::string > > & commands ) const; 52 | }; 53 | -------------------------------------------------------------------------------- /Unit-Tests/XS-RWLock.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ******************************************************************************/ 24 | 25 | /*! 26 | * @copyright (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net 27 | * @brief 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define XSTEST_GTEST_COMPAT 35 | #include 36 | 37 | TEST( XS_RWLock, SingleReader ) 38 | { 39 | XS::RWLock l; 40 | 41 | ASSERT_TRUE( l.TryLockForReading() ); 42 | 43 | l.UnlockForReading(); 44 | } 45 | 46 | TEST( XS_RWLock, SingleWriter ) 47 | { 48 | XS::RWLock l; 49 | 50 | ASSERT_TRUE( l.TryLockForWriting() ); 51 | 52 | l.UnlockForWriting(); 53 | } 54 | 55 | TEST( XS_RWLock, MultipleReaders_SameThread ) 56 | { 57 | XS::RWLock l; 58 | 59 | ASSERT_TRUE( l.TryLockForReading() ); 60 | ASSERT_TRUE( l.TryLockForReading() ); 61 | 62 | l.UnlockForReading(); 63 | l.UnlockForReading(); 64 | } 65 | 66 | TEST( XS_RWLock, MultipleWriters_SameThread ) 67 | { 68 | XS::RWLock l; 69 | 70 | ASSERT_TRUE( l.TryLockForWriting() ); 71 | ASSERT_TRUE( l.TryLockForWriting() ); 72 | 73 | l.UnlockForWriting(); 74 | l.UnlockForWriting(); 75 | } 76 | 77 | TEST( XS_RWLock, ReadWrite_SameThread ) 78 | { 79 | XS::RWLock l; 80 | 81 | ASSERT_TRUE( l.TryLockForReading() ); 82 | ASSERT_TRUE( l.TryLockForWriting() ); 83 | 84 | l.UnlockForReading(); 85 | l.UnlockForWriting(); 86 | } 87 | 88 | TEST( XS_RWLock, WriteRead_SameThread ) 89 | { 90 | XS::RWLock l; 91 | 92 | ASSERT_TRUE( l.TryLockForWriting() ); 93 | ASSERT_TRUE( l.TryLockForReading() ); 94 | 95 | l.UnlockForWriting(); 96 | l.UnlockForReading(); 97 | } 98 | 99 | TEST( XS_RWLock, MultipleReaders_DifferentThreads ) 100 | { 101 | XS::RWLock l; 102 | std::atomic< bool > b( false ); 103 | 104 | l.LockForReading(); 105 | 106 | std::thread 107 | ( 108 | [ & ] 109 | { 110 | b = l.TryLockForReading(); 111 | 112 | l.UnlockForReading(); 113 | } 114 | ) 115 | .join(); 116 | 117 | ASSERT_TRUE( b ); 118 | 119 | l.UnlockForReading(); 120 | } 121 | 122 | TEST( XS_RWLock, MultipleWriters_DifferentThreads ) 123 | { 124 | XS::RWLock l; 125 | std::atomic< bool > b( false ); 126 | 127 | l.LockForWriting(); 128 | 129 | std::thread 130 | ( 131 | [ & ] 132 | { 133 | b = l.TryLockForWriting(); 134 | } 135 | ) 136 | .join(); 137 | 138 | ASSERT_FALSE( b ); 139 | 140 | l.UnlockForWriting(); 141 | 142 | std::thread 143 | ( 144 | [ & ] 145 | { 146 | b = l.TryLockForWriting(); 147 | 148 | l.UnlockForWriting(); 149 | } 150 | ) 151 | .join(); 152 | 153 | ASSERT_TRUE( b ); 154 | } 155 | 156 | TEST( XS_RWLock, ReadWrite_DifferentThreads ) 157 | { 158 | XS::RWLock l; 159 | std::atomic< bool > b( false ); 160 | 161 | l.LockForReading(); 162 | 163 | std::thread 164 | ( 165 | [ & ] 166 | { 167 | b = l.TryLockForWriting(); 168 | } 169 | ) 170 | .join(); 171 | 172 | ASSERT_FALSE( b ); 173 | 174 | l.UnlockForReading(); 175 | 176 | std::thread 177 | ( 178 | [ & ] 179 | { 180 | b = l.TryLockForWriting(); 181 | 182 | l.UnlockForWriting(); 183 | } 184 | ) 185 | .join(); 186 | 187 | ASSERT_TRUE( b ); 188 | } 189 | 190 | TEST( XS_RWLock, WriteRead_DifferentThreads ) 191 | { 192 | XS::RWLock l; 193 | std::atomic< bool > b( false ); 194 | 195 | l.LockForWriting(); 196 | 197 | std::thread 198 | ( 199 | [ & ] 200 | { 201 | b = l.TryLockForReading(); 202 | } 203 | ) 204 | .join(); 205 | 206 | ASSERT_FALSE( b ); 207 | 208 | l.UnlockForWriting(); 209 | 210 | std::thread 211 | ( 212 | [ & ] 213 | { 214 | b = l.TryLockForReading(); 215 | 216 | l.UnlockForReading(); 217 | } 218 | ) 219 | .join(); 220 | 221 | ASSERT_TRUE( b ); 222 | } 223 | 224 | TEST( XS_RWLock, ThrowOnUnownedReadUnlock ) 225 | { 226 | XS::RWLock l; 227 | 228 | ASSERT_THROW( l.UnlockForReading(), std::runtime_error ); 229 | } 230 | -------------------------------------------------------------------------------- /VisualStudio/All.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {BF41470D-22A7-46C5-A73C-6AB4DB932359} 24 | All 25 | 10.0.16299.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v141 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v141 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v141 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v141 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | $(SolutionDir)Build\64\$(Configuration)\ 74 | $(SolutionDir)Build\64\$(Configuration)\Temp\$(ProjectName)\ 75 | 76 | 77 | $(SolutionDir)Build\64\$(Configuration)\ 78 | $(SolutionDir)Build\64\$(Configuration)\Temp\$(ProjectName)\ 79 | 80 | 81 | $(SolutionDir)Build\32\$(Configuration)\ 82 | $(SolutionDir)Build\32\$(Configuration)\Temp\$(ProjectName)\ 83 | 84 | 85 | $(SolutionDir)Build\32\$(Configuration)\ 86 | $(SolutionDir)Build\32\$(Configuration)\Temp\$(ProjectName)\ 87 | 88 | 89 | 90 | Level3 91 | Disabled 92 | true 93 | 94 | 95 | 96 | 97 | Level3 98 | Disabled 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | MaxSpeed 106 | true 107 | true 108 | true 109 | 110 | 111 | true 112 | true 113 | 114 | 115 | 116 | 117 | Level3 118 | MaxSpeed 119 | true 120 | true 121 | true 122 | 123 | 124 | true 125 | true 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /VisualStudio/All.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | -------------------------------------------------------------------------------- /VisualStudio/CPPAtomic Static VC140 XP.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | {42C37BE5-0A01-4054-9E69-76A499A1B160} 46 | Win32Proj 47 | CF 48 | 8.1 49 | CPPAtomic Static VC140 XP 50 | 51 | 52 | 53 | StaticLibrary 54 | true 55 | v140_xp 56 | Unicode 57 | 58 | 59 | StaticLibrary 60 | true 61 | v140_xp 62 | Unicode 63 | 64 | 65 | StaticLibrary 66 | false 67 | v140_xp 68 | true 69 | Unicode 70 | 71 | 72 | StaticLibrary 73 | false 74 | v140_xp 75 | true 76 | Unicode 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | $(SolutionDir)Build\32\$(Configuration)\Temp\$(ProjectName)\ 96 | $(SolutionDir)Build\32\$(Configuration)\ 97 | CPPAtomic_Static_V140XP 98 | 99 | 100 | $(SolutionDir)Build\64\$(Configuration)\ 101 | $(SolutionDir)Build\64\$(Configuration)\Temp\$(ProjectName)\ 102 | CPPAtomic_Static_V140XP 103 | 104 | 105 | $(SolutionDir)Build\32\$(Configuration)\Temp\$(ProjectName)\ 106 | $(SolutionDir)Build\32\$(Configuration)\ 107 | CPPAtomic_Static_V140XP 108 | 109 | 110 | $(SolutionDir)Build\64\$(Configuration)\ 111 | $(SolutionDir)Build\64\$(Configuration)\Temp\$(ProjectName)\ 112 | CPPAtomic_Static_V140XP 113 | 114 | 115 | 116 | NotUsing 117 | Level3 118 | Disabled 119 | WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 120 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 121 | 122 | 123 | Windows 124 | true 125 | 126 | 127 | 128 | 129 | NotUsing 130 | Level3 131 | Disabled 132 | WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 133 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 134 | 135 | 136 | Windows 137 | true 138 | 139 | 140 | 141 | 142 | Level3 143 | NotUsing 144 | MaxSpeed 145 | true 146 | true 147 | WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 148 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 149 | true 150 | false 151 | 152 | 153 | Windows 154 | true 155 | true 156 | true 157 | 158 | 159 | false 160 | 161 | 162 | 163 | 164 | Level3 165 | NotUsing 166 | MaxSpeed 167 | true 168 | true 169 | WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 170 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 171 | true 172 | false 173 | 174 | 175 | Windows 176 | true 177 | true 178 | true 179 | 180 | 181 | false 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /VisualStudio/CPPAtomic Static VC140 XP.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Header Files 16 | 17 | 18 | Header Files 19 | 20 | 21 | Header Files 22 | 23 | 24 | Header Files 25 | 26 | 27 | Header Files 28 | 29 | 30 | 31 | 32 | Source Files 33 | 34 | 35 | Source Files 36 | 37 | 38 | Source Files 39 | 40 | 41 | Source Files 42 | 43 | 44 | Source Files 45 | 46 | 47 | Source Files 48 | 49 | 50 | Source Files 51 | 52 | 53 | Source Files 54 | 55 | 56 | Source Files 57 | 58 | 59 | Source Files 60 | 61 | 62 | Source Files 63 | 64 | 65 | Source Files 66 | 67 | 68 | Source Files 69 | 70 | 71 | Source Files 72 | 73 | 74 | -------------------------------------------------------------------------------- /VisualStudio/CPPAtomic Static VC141 XP.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | {A155D579-636A-40C1-AF81-DDC0F6A8623E} 46 | Win32Proj 47 | CF 48 | 8.1 49 | CPPAtomic Static VC141 XP 50 | 51 | 52 | 53 | StaticLibrary 54 | true 55 | v141_xp 56 | Unicode 57 | 58 | 59 | StaticLibrary 60 | true 61 | v141_xp 62 | Unicode 63 | 64 | 65 | StaticLibrary 66 | false 67 | v141_xp 68 | true 69 | Unicode 70 | 71 | 72 | StaticLibrary 73 | false 74 | v141_xp 75 | true 76 | Unicode 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | $(SolutionDir)Build\32\$(Configuration)\Temp\$(ProjectName)\ 96 | $(SolutionDir)Build\32\$(Configuration)\ 97 | CPPAtomic_Static_V141XP 98 | 99 | 100 | $(SolutionDir)Build\64\$(Configuration)\ 101 | $(SolutionDir)Build\64\$(Configuration)\Temp\$(ProjectName)\ 102 | CPPAtomic_Static_V141XP 103 | 104 | 105 | $(SolutionDir)Build\32\$(Configuration)\Temp\$(ProjectName)\ 106 | $(SolutionDir)Build\32\$(Configuration)\ 107 | CPPAtomic_Static_V141XP 108 | 109 | 110 | $(SolutionDir)Build\64\$(Configuration)\ 111 | $(SolutionDir)Build\64\$(Configuration)\Temp\$(ProjectName)\ 112 | CPPAtomic_Static_V141XP 113 | 114 | 115 | 116 | NotUsing 117 | Level3 118 | Disabled 119 | WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 120 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 121 | 122 | 123 | Windows 124 | true 125 | 126 | 127 | 128 | 129 | NotUsing 130 | Level3 131 | Disabled 132 | WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 133 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 134 | 135 | 136 | Windows 137 | true 138 | 139 | 140 | 141 | 142 | Level3 143 | NotUsing 144 | MaxSpeed 145 | true 146 | true 147 | WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 148 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 149 | true 150 | false 151 | 152 | 153 | Windows 154 | true 155 | true 156 | true 157 | 158 | 159 | false 160 | 161 | 162 | 163 | 164 | Level3 165 | NotUsing 166 | MaxSpeed 167 | true 168 | true 169 | WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 170 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 171 | true 172 | false 173 | 174 | 175 | Windows 176 | true 177 | true 178 | true 179 | 180 | 181 | false 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /VisualStudio/CPPAtomic Static VC141 XP.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Header Files 16 | 17 | 18 | Header Files 19 | 20 | 21 | Header Files 22 | 23 | 24 | Header Files 25 | 26 | 27 | Header Files 28 | 29 | 30 | 31 | 32 | Source Files 33 | 34 | 35 | Source Files 36 | 37 | 38 | Source Files 39 | 40 | 41 | Source Files 42 | 43 | 44 | Source Files 45 | 46 | 47 | Source Files 48 | 49 | 50 | Source Files 51 | 52 | 53 | Source Files 54 | 55 | 56 | Source Files 57 | 58 | 59 | Source Files 60 | 61 | 62 | Source Files 63 | 64 | 65 | Source Files 66 | 67 | 68 | Source Files 69 | 70 | 71 | Source Files 72 | 73 | 74 | -------------------------------------------------------------------------------- /VisualStudio/CPPAtomic Static VC142.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | {88FE28D1-C669-4972-9D7A-F171BA951ACB} 46 | Win32Proj 47 | CF 48 | 10.0 49 | CPPAtomic Static VC142 50 | 51 | 52 | 53 | StaticLibrary 54 | true 55 | v142 56 | Unicode 57 | 58 | 59 | StaticLibrary 60 | true 61 | v142 62 | Unicode 63 | 64 | 65 | StaticLibrary 66 | false 67 | v142 68 | true 69 | Unicode 70 | 71 | 72 | StaticLibrary 73 | false 74 | v142 75 | true 76 | Unicode 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | $(SolutionDir)Build\32\$(Configuration)\Temp\$(ProjectName)\ 96 | $(SolutionDir)Build\32\$(Configuration)\ 97 | CPPAtomic_Static_V142 98 | 99 | 100 | $(SolutionDir)Build\64\$(Configuration)\ 101 | $(SolutionDir)Build\64\$(Configuration)\Temp\$(ProjectName)\ 102 | CPPAtomic_Static_V142 103 | 104 | 105 | $(SolutionDir)Build\32\$(Configuration)\Temp\$(ProjectName)\ 106 | $(SolutionDir)Build\32\$(Configuration)\ 107 | CPPAtomic_Static_V142 108 | 109 | 110 | $(SolutionDir)Build\64\$(Configuration)\ 111 | $(SolutionDir)Build\64\$(Configuration)\Temp\$(ProjectName)\ 112 | CPPAtomic_Static_V142 113 | 114 | 115 | 116 | NotUsing 117 | Level3 118 | Disabled 119 | WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 120 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 121 | 122 | 123 | Windows 124 | true 125 | 126 | 127 | 128 | 129 | NotUsing 130 | Level3 131 | Disabled 132 | WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 133 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 134 | 135 | 136 | Windows 137 | true 138 | 139 | 140 | 141 | 142 | Level3 143 | NotUsing 144 | MaxSpeed 145 | true 146 | true 147 | WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 148 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 149 | true 150 | false 151 | 152 | 153 | Windows 154 | true 155 | true 156 | true 157 | 158 | 159 | false 160 | 161 | 162 | 163 | 164 | Level3 165 | NotUsing 166 | MaxSpeed 167 | true 168 | true 169 | WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_LIB;XS_PIMPL_EXPORTS;OBJCXX_DLL_BUILD;%(PreprocessorDefinitions) 170 | .;..\CPPAtomic\include;..\Submodules\PIMPL\PIMPL\include;..\Submodules\CPPTraits\CPPTraits\include;%(AdditionalIncludeDirectories) 171 | true 172 | false 173 | 174 | 175 | Windows 176 | true 177 | true 178 | true 179 | 180 | 181 | false 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /VisualStudio/CPPAtomic Static VC142.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Header Files 16 | 17 | 18 | Header Files 19 | 20 | 21 | Header Files 22 | 23 | 24 | Header Files 25 | 26 | 27 | Header Files 28 | 29 | 30 | 31 | 32 | Source Files 33 | 34 | 35 | Source Files 36 | 37 | 38 | Source Files 39 | 40 | 41 | Source Files 42 | 43 | 44 | Source Files 45 | 46 | 47 | Source Files 48 | 49 | 50 | Source Files 51 | 52 | 53 | Source Files 54 | 55 | 56 | Source Files 57 | 58 | 59 | Source Files 60 | 61 | 62 | Source Files 63 | 64 | 65 | Source Files 66 | 67 | 68 | Source Files 69 | 70 | 71 | Source Files 72 | 73 | 74 | --------------------------------------------------------------------------------