Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Logic
- open System.Collections
- open System.Threading
- type Blocking_Queue () =
- let mutable local_queue = Queue()
- let resetEvent = new AutoResetEvent(true)
- member this.add element =
- lock this (fun () -> if (Interlocked.CompareExchange(ref local_queue.Count, 0, 0) = 0)
- then resetEvent.Set() |> ignore
- local_queue.Enqueue(element))
- member this.getFirstElement =
- if (Interlocked.CompareExchange(ref local_queue.Count, 0, 0) = 0)
- then resetEvent.WaitOne() |> ignore
- local_queue.Dequeue()
- else lock this (fun () -> local_queue.Dequeue())
- member this.getSize =
- lock this (fun () -> local_queue.Count)
- member this.firstElement =
- lock this (fun () -> local_queue.Peek)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement