Add ReaderWriterQueue and update ConcurrentQueue

This commit is contained in:
Paul Hollinsky
2020-03-09 13:38:14 -04:00
parent 9ac3fd56bd
commit 42780dc610
1629 changed files with 306008 additions and 868 deletions
@@ -0,0 +1,258 @@
#include "stdafx.h"
#include "../../relacy/relacy_java.hpp"
class stack
{
public:
stack()
: head_(0)
{
}
void push(int data)
{
rl::var<node*> n = new node ();
VAR(n)->VAR(data_) = data;
node* next = head_.load(rl::memory_order_relaxed);
for (;;)
{
VAR(n)->next_.store(next, rl::memory_order_relaxed);
if (head_.compare_exchange_weak(next, VAR(n), rl::memory_order_release))
break;
}
}
int pop()
{
node* n = head_.load(rl::memory_order_acquire);
for (;;)
{
if (0 == n)
break;
node* next = n->next_.load(rl::memory_order_relaxed);
if (head_.compare_exchange_weak(n, next, rl::memory_order_acquire))
break;
}
if (n)
{
int data = n->VAR(data_);
return data;
}
else
{
return 0;
}
}
private:
struct node
{
rl::atomic<node*> next_;
rl::var<int> data_;
};
rl::atomic<node*> head_;
stack(stack const&);
stack& operator = (stack const&);
};
struct stack_test : rl::test_suite<stack_test, 4>
{
stack s_;
int produced_count_;
int consumed_count_;
void before()
{
produced_count_ = 0;
consumed_count_ = 0;
}
void after()
{
typedef rl::test_suite<stack_test, 4> base_t;
RL_ASSERT(base_t::params::thread_count == produced_count_);
RL_ASSERT(base_t::params::thread_count == consumed_count_);
}
void thread(unsigned /*index*/)
{
s_.push(rand() + 1);
produced_count_ += 1;
int data = s_.pop();
RL_ASSERT(data);
consumed_count_ += 1;
}
};
struct test_api : rl::test_suite<test_api, 1>
{
void thread(unsigned)
{
rl::jvolatile<int> jv1;
rl::jvolatile<int> jv2 (2);
rl::jvolatile<int> jv3 (jv2($));
rl::jvolatile<int> jv4 (jv1);
jv1($) = jv3($);
jv1($) = 2;
(int)jv1($);
jv1($) += 1;
jv1($) -= 1;
int x = jv1($)++;
x = jv1($)--;
x = --jv1($);
x = ++jv1($);
rl::AtomicInteger ai, ai2(1), ai3(x), ai4(ai($)), ai5(ai);
x = ai($).get();
ai($).set(1);
x = ai($).addAndGet(2);
bool b = ai($).compareAndSet(1, 2);
(void)b;
x = ai($).addAndGet(2);
x = ai($).getAndSet(2);
}
};
struct test_seq_cst_volatiles : rl::test_suite<test_seq_cst_volatiles, 2>
{
rl::jvolatile<int> flag0;
rl::jvolatile<int> flag1;
rl::jvolatile<int> turn;
rl::var<int> data;
void thread(unsigned index)
{
if (0 == index)
{
flag0($) = 1;
turn($) = 1;
while (flag1($) && 1 == turn($))
rl::yield(1, $);
data($) = 1;
flag0($) = 0;
}
else
{
flag1($) = 1;
turn($) = 0;
while (flag0($) && 0 == turn($))
rl::yield(1, $);
data($) = 2;
flag1($) = 0;
}
}
};
struct test_seq_cst_volatiles2 : rl::test_suite<test_seq_cst_volatiles2, 4>
{
rl::jvolatile<int> x;
rl::jvolatile<int> y;
int r1, r2, r3, r4;
void before()
{
r1 = r2 = r3 = r4 = 0;
}
void thread(unsigned index)
{
if (0 == index)
{
x($) = 0;
}
else if (1 == index)
{
y($) = 0;
}
else if (2 == index)
{
r1 = x($);
r2 = y($);
}
else if (3 == index)
{
r3 = y($);
r4 = x($);
}
}
void after()
{
RL_ASSERT(false == (r1 && !r2 && r3 && !r4));
}
};
template<int expected>
struct test_unitialized_var : rl::test_suite<test_unitialized_var<expected>, 2, rl::test_result_until_condition_hit>
{
rl::jvar<rl::jvar<int>*> www;
void thread(unsigned index)
{
if (0 == index)
{
www($) = new rl::jvar<int> (1);
}
else
{
while (0 == www($))
rl::yield(1, $);
int x = (*www($))($);
RL_UNTIL(x == expected);
}
}
};
int main()
{
rl::simulate_f tests[] =
{
//!!! broken &rl::simulate<test_unitialized_var<0> >,
&rl::simulate<test_unitialized_var<1> >,
&rl::simulate<test_seq_cst_volatiles>,
&rl::simulate<test_seq_cst_volatiles2>,
&rl::simulate<test_api>,
&rl::simulate<stack_test>,
};
for (size_t i = 0; i != sizeof(tests)/sizeof(*tests); ++i)
{
rl::ostringstream stream;
rl::test_params params;
params.iteration_count = 10000;
params.output_stream = &stream;
params.progress_stream = &stream;
params.context_bound = 2;
params.execution_depth_limit = 500;
if (false == tests[i](params))
{
std::cout << std::endl;
std::cout << "FAILED" << std::endl;
std::cout << stream.str();
return 1;
}
else
{
std::cout << params.test_name << "...OK" << std::endl;
}
}
std::cout << std::endl << "SUCCESS" << std::endl;
}
@@ -0,0 +1,43 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jtest", "jtest.vcproj", "{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rrd", "..\..\test\msvc8\rrd.vcproj", "{D4F501D0-382D-4CBC-86F4-56181F383444}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Debug64|Win32 = Debug64|Win32
Debug64|x64 = Debug64|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug|Win32.ActiveCfg = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug|Win32.Build.0 = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug|x64.ActiveCfg = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug64|Win32.ActiveCfg = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug64|Win32.Build.0 = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug64|x64.ActiveCfg = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Release|Win32.ActiveCfg = Release|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Release|Win32.Build.0 = Release|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Release|x64.ActiveCfg = Release|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug|Win32.ActiveCfg = Debug|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug|Win32.Build.0 = Debug|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug|x64.ActiveCfg = Debug|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug|x64.Build.0 = Debug|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug64|Win32.ActiveCfg = Debug64|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug64|Win32.Build.0 = Debug64|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug64|x64.ActiveCfg = Debug64|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug64|x64.Build.0 = Debug64|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Release|Win32.ActiveCfg = Release|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Release|Win32.Build.0 = Release|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Release|x64.ActiveCfg = Release|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,205 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="jtest"
ProjectGUID="{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}"
RootNamespace="jtest"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
WholeProgramOptimization="false"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="2"
WarningLevel="4"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
LinkTimeCodeGeneration="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath="..\jtest.cpp"
>
</File>
<File
RelativePath="..\stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\stdafx.h"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,43 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jtest", "jtest.vcproj", "{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rrd", "..\..\test\msvc9\rrd.vcproj", "{D4F501D0-382D-4CBC-86F4-56181F383444}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Debug64|Win32 = Debug64|Win32
Debug64|x64 = Debug64|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug|Win32.ActiveCfg = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug|Win32.Build.0 = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug|x64.ActiveCfg = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug64|Win32.ActiveCfg = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug64|Win32.Build.0 = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Debug64|x64.ActiveCfg = Debug|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Release|Win32.ActiveCfg = Release|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Release|Win32.Build.0 = Release|Win32
{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}.Release|x64.ActiveCfg = Release|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug|Win32.ActiveCfg = Debug|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug|Win32.Build.0 = Debug|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug|x64.ActiveCfg = Debug|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug|x64.Build.0 = Debug|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug64|Win32.ActiveCfg = Debug64|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug64|Win32.Build.0 = Debug64|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug64|x64.ActiveCfg = Debug64|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Debug64|x64.Build.0 = Debug64|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Release|Win32.ActiveCfg = Release|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Release|Win32.Build.0 = Release|Win32
{D4F501D0-382D-4CBC-86F4-56181F383444}.Release|x64.ActiveCfg = Release|x64
{D4F501D0-382D-4CBC-86F4-56181F383444}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,200 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="jtest"
ProjectGUID="{1889E8F4-47F7-48B6-9FC7-61FD7CD000C8}"
RootNamespace="jtest"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
WarningLevel="4"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
UsePrecompiledHeader="2"
WarningLevel="4"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath="..\jtest.cpp"
>
</File>
<File
RelativePath="..\stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\stdafx.h"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
@@ -0,0 +1,2 @@
#include "stdafx.h"
@@ -0,0 +1,6 @@
#pragma once
#define RL_JAVA_MODE
#include "../../relacy/pch.hpp"