@@ -4,55 +4,14 @@ namespace Microsoft.FSharp.Control
44
55 open System
66 open System.Threading
7+ open System.Collections .Generic
78 open Microsoft.FSharp .Core
89 open Microsoft.FSharp .Core .LanguagePrimitives .IntrinsicOperators
910 open Microsoft.FSharp .Control
1011 open Microsoft.FSharp .Control .AsyncBuilderImpl
1112 open Microsoft.FSharp .Control .AsyncPrimitives
1213 open Microsoft.FSharp .Collections
1314
14- /// We use our own internal implementation of queues to avoid a dependency on System.dll
15- type Queue < 'T >() =
16-
17- let mutable array = [| |]
18- let mutable head = 0
19- let mutable size = 0
20- let mutable tail = 0
21-
22- let SetCapacity capacity =
23- let destinationArray = Array.zeroCreate capacity
24- if ( size > 0 ) then
25- if ( head < tail) then
26- Array.Copy( array, head, destinationArray, 0 , size)
27-
28- else
29- Array.Copy( array, head, destinationArray, 0 , array.Length - head)
30- Array.Copy( array, 0 , destinationArray, array.Length - head, tail)
31- array <- destinationArray
32- head <- 0
33- tail <- if ( size = capacity) then 0 else size
34-
35- member x.Dequeue () =
36- if ( size = 0 ) then
37- failwith " Dequeue"
38- let local = array.[ head]
39- array.[ head] <- Unchecked.defaultof< 'T>
40- head <- ( head + 1 ) % array.Length
41- size <- size - 1
42- local
43-
44- member this.Enqueue item =
45- if ( size = array.Length) then
46- let capacity = int (( int64 array.Length * 200 L) / 100 L)
47- let capacity = max capacity ( array.Length + 4 )
48- SetCapacity capacity
49- array.[ tail] <- item
50- tail <- ( tail + 1 ) % array.Length
51- size <- size + 1
52-
53- member x.Count = size
54-
55-
5615 module AsyncHelpers =
5716
5817 let awaitEither a1 a2 =
@@ -93,7 +52,7 @@ namespace Microsoft.FSharp.Control
9352 [<AutoSerializable( false ) >]
9453 type Mailbox < 'Msg >( cancellationSupported : bool ) =
9554 let mutable inboxStore = null
96- let mutable arrivals = new Queue< 'Msg>()
55+ let arrivals = Queue< 'Msg>()
9756 let syncRoot = arrivals
9857
9958 // Control elements indicating the state of the reader. When the reader is "blocked" at an
0 commit comments