-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into remove-ios-ci-workaround
- Loading branch information
Showing
19 changed files
with
518 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Extensions; | ||
|
||
namespace osu.Framework.Tests.Graphics | ||
{ | ||
[TestFixture] | ||
public class TripleBufferTest | ||
{ | ||
[Test] | ||
public void TestWriteOnly() | ||
{ | ||
var tripleBuffer = new TripleBuffer<TestObject>(); | ||
|
||
for (int i = 0; i < 1000; i++) | ||
{ | ||
using (tripleBuffer.GetForWrite()) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestReadOnly() | ||
{ | ||
var tripleBuffer = new TripleBuffer<TestObject>(); | ||
|
||
using (var buffer = tripleBuffer.GetForRead()) | ||
Assert.That(buffer, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void TestWriteThenRead() | ||
{ | ||
var tripleBuffer = new TripleBuffer<TestObject>(); | ||
|
||
for (int i = 0; i < 1000; i++) | ||
{ | ||
var obj = new TestObject(i); | ||
|
||
using (var buffer = tripleBuffer.GetForWrite()) | ||
buffer.Object = obj; | ||
|
||
using (var buffer = tripleBuffer.GetForRead()) | ||
Assert.That(buffer?.Object, Is.EqualTo(obj)); | ||
} | ||
|
||
using (var buffer = tripleBuffer.GetForRead()) | ||
Assert.That(buffer, Is.Null); | ||
} | ||
|
||
[Test] | ||
public void TestReadSaturated() | ||
{ | ||
var tripleBuffer = new TripleBuffer<TestObject>(); | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
var obj = new TestObject(i); | ||
ManualResetEventSlim resetEventSlim = new ManualResetEventSlim(); | ||
|
||
var readTask = Task.Factory.StartNew(() => | ||
{ | ||
resetEventSlim.Set(); | ||
using (var buffer = tripleBuffer.GetForRead()) | ||
Assert.That(buffer?.Object, Is.EqualTo(obj)); | ||
}, TaskCreationOptions.LongRunning); | ||
|
||
Task.Factory.StartNew(() => | ||
{ | ||
resetEventSlim.Wait(1000); | ||
Thread.Sleep(10); | ||
|
||
using (var buffer = tripleBuffer.GetForWrite()) | ||
buffer.Object = obj; | ||
}, TaskCreationOptions.LongRunning); | ||
|
||
readTask.WaitSafely(); | ||
} | ||
} | ||
|
||
private class TestObject | ||
{ | ||
private readonly int i; | ||
|
||
public TestObject(int i) | ||
{ | ||
this.i = i; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"{base.ToString()} {i}"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.