Skip to content

Commit 95482bb

Browse files
Removed lock on the stopping of the precompute. (#267)
* Removed lock on the stopping of the precompute. Added benchmark to time the stopPrecompute functionality. * Update version numbers for nuget release
1 parent 8d1f234 commit 95482bb

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set(META_PROJECT_EXPORT "ElectionGuard")
77
set(META_PROJECT_TARGET "electionguard")
88
set(META_VERSION_MAJOR "0")
99
set(META_VERSION_MINOR "1")
10-
set(META_VERSION_PATCH "6")
10+
set(META_VERSION_PATCH "10")
1111
set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}")
1212

1313
set(LIBRARY_PUBLIC_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Bench/BenchEncrypt.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Linq;
55
using System.Text;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using ElectionGuard.Encryption.Utils;
89

@@ -11,6 +12,7 @@ namespace ElectionGuard.Encryption.Bench
1112

1213
public class BenchEncrypt : Fixture
1314
{
15+
readonly int MAX_COMPLETE_DELAY = 7000;
1416
ElementModQ nonce;
1517
ElGamalKeyPair keypair;
1618
Manifest manifest;
@@ -41,6 +43,9 @@ public override void Run()
4143
Bench_Encrypt_BallotFull_NoProofCheck();
4244
Bench_Encrypt_BallotFull_WithProofCheck();
4345
Bench_Encrypt_Ballot_Compact_NoProofCheck();
46+
47+
Setup_Precompute_Buffers();
48+
Bench_Encrypt_BallotFull_NoProofCheck();
4449
// TODO: Bench_Encrypt_Ballot_Compact_WithProofCheck();
4550
}
4651

@@ -79,5 +84,24 @@ public void Bench_Encrypt_Ballot_Compact_WithProofCheck()
7984
var ciphertext = Encrypt.CompactBallot(ballot, internalManifest, context, device.GetHash(), nonce, true);
8085
});
8186
}
87+
88+
public void Setup_Precompute_Buffers()
89+
{
90+
Console.WriteLine("Setup_Precompute_Buffers");
91+
var waitHandle = new AutoResetEvent(false);
92+
93+
Precompute precompute = new Precompute();
94+
precompute.CompletedEvent += (PrecomputeStatus completedStatus) =>
95+
{
96+
waitHandle.Set();
97+
};
98+
precompute.StartPrecomputeAsync(keypair.PublicKey, 1000);
99+
var waitReturn = waitHandle.WaitOne(MAX_COMPLETE_DELAY);
100+
Run(() =>
101+
{
102+
precompute.StopPrecompute();
103+
});
104+
}
105+
82106
}
83107
}

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption/ElectionGuard.Encryption.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<!-- Project -->
88
<RootNamespace>ElectionGuard</RootNamespace>
99
<AssemblyName>ElectionGuard.Encryption</AssemblyName>
10-
<Version>0.1.9</Version>
11-
<AssemblyVersion>0.1.9.0</AssemblyVersion>
12-
<AssemblyFileVersion>0.1.9.0</AssemblyFileVersion>
10+
<Version>0.1.10</Version>
11+
<AssemblyVersion>0.1.10.0</AssemblyVersion>
12+
<AssemblyFileVersion>0.1.10.0</AssemblyFileVersion>
1313
</PropertyGroup>
1414

1515
<PropertyGroup>
@@ -19,7 +19,7 @@
1919
<Title>ElectionGuard Encryption</Title>
2020
<Description>Open source implementation of ElectionGuard's ballot encryption.</Description>
2121
<Authors>Microsoft</Authors>
22-
<PackageVersion>0.1.9</PackageVersion>
22+
<PackageVersion>0.1.10</PackageVersion>
2323
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2424
<PackageProjectUrl>https://github.com/microsoft/electionguard-cpp</PackageProjectUrl>
2525
<RepositoryUrl>https://github.com/microsoft/electionguard-cpp</RepositoryUrl>

src/electionguard/precompute_buffers.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,7 @@ namespace electionguard
232232
} while (getInstance().quadruple_queue.size() < getInstance().max);
233233
}
234234

235-
void PrecomputeBufferContext::stop_populate()
236-
{
237-
std::lock_guard<std::mutex> lock(queue_lock);
238-
getInstance().populate_OK = false;
239-
}
235+
void PrecomputeBufferContext::stop_populate() { getInstance().populate_OK = false; }
240236

241237
uint32_t PrecomputeBufferContext::get_max_queue_size() { return getInstance().max; }
242238

0 commit comments

Comments
 (0)