-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32a2e56
commit 94bd20c
Showing
9 changed files
with
192 additions
and
114 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 was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/FSharp.Control.Futures/Scheduling/GlobalThreadPoolScheduler.fs
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,23 @@ | ||
namespace rec FSharp.Control.Futures.Scheduling | ||
|
||
open System.Threading | ||
open FSharp.Control.Futures | ||
open FSharp.Control.Futures.Scheduling.RunnerScheduler.RunnerScheduler | ||
|
||
|
||
type GlobalThreadPoolTaskRunner() = | ||
interface ITaskRunner with | ||
member _.RunTask(task) = | ||
ThreadPool.QueueUserWorkItem(fun _ -> do task.Run()) |> ignore | ||
|
||
type GlobalThreadPoolScheduler internal () = | ||
interface IScheduler with | ||
member this.Spawn(fut: Future<'a>) = | ||
let task = RunnerTask<'a>(fut, GlobalThreadPoolScheduler.globalThreadPoolTaskRunner) | ||
task.InitialRun() | ||
task :> IFutureTask<'a> | ||
member _.Dispose() = () | ||
|
||
module GlobalThreadPoolScheduler = | ||
let internal globalThreadPoolTaskRunner = GlobalThreadPoolTaskRunner() | ||
let globalThreadPoolScheduler: IScheduler = upcast new GlobalThreadPoolScheduler() |
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,25 @@ | ||
namespace FSharp.Control.Futures.Scheduling | ||
|
||
open System.Threading | ||
|
||
open FSharp.Control.Futures | ||
open FSharp.Control.Futures.Internals | ||
open FSharp.Control.Futures.Scheduling.GlobalThreadPoolScheduler | ||
open FSharp.Control.Futures.Sync | ||
|
||
|
||
[<RequireQualifiedAccess>] | ||
module Schedulers = | ||
let threadPool: IScheduler = GlobalThreadPoolScheduler.globalThreadPoolScheduler | ||
|
||
|
||
[<RequireQualifiedAccess>] | ||
module Scheduler = | ||
|
||
/// <summary> Run Future on passed scheduler </summary> | ||
/// <returns> Return Future waited result passed Future </returns> | ||
let spawnOn (scheduler: IScheduler) (fut: Future<'a>) = scheduler.Spawn(fut) | ||
|
||
/// <summary> Run Future on thread pool scheduler </summary> | ||
/// <returns> Return Future waited result passed Future </returns> | ||
let spawnOnThreadPool fut = spawnOn Schedulers.threadPool fut |
63 changes: 63 additions & 0 deletions
63
src/FSharp.Control.Futures/Scheduling/SingleThreadScheduler.fs
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,63 @@ | ||
namespace FSharp.Control.Futures.Scheduling | ||
|
||
open System.Collections.Generic | ||
open System.Linq.Expressions | ||
open System.Runtime.CompilerServices | ||
open System.Threading | ||
open FSharp.Control.Futures | ||
open FSharp.Control.Futures.Internals | ||
|
||
|
||
module Constants = | ||
let [<Literal>] MinimalTrimDelta : int = 1024 // 4кб для int | ||
|
||
|
||
type ISchedulerTask = | ||
abstract Poll: IContext -> bool | ||
abstract Drop: unit -> unit | ||
|
||
type SchedulerTask<'a> = | ||
val mutable currentState: NaiveFuture<'a> | ||
val mutable isWaiting: bool // runtime safety checks for onceCell | ||
val mutable onceCell: PrimaryOnceCell<'a> | ||
|
||
new (fut: Future<'a>) = { | ||
currentState = NaiveFuture(fut) | ||
isWaiting = false | ||
onceCell = PrimaryOnceCell.Empty() | ||
} | ||
|
||
override this.Equals(other: obj): bool = | ||
refEq this other | ||
|
||
override this.GetHashCode(): int = | ||
RuntimeHelpers.GetHashCode(this) | ||
|
||
interface IFutureTask<'a> with | ||
member this.Cancel() : unit = failwith "todo" | ||
member this.Await() : Future<'a> = failwith "todo" | ||
member this.WaitBlocking() : 'a = (this:> IFutureTask<'a>).Await() |> Future.runSync | ||
|
||
interface Future<'a> with | ||
member this.Poll(ctx: IContext) : Poll<'a> = | ||
this.onceCell.PollGet(ctx) |> NaivePoll.toPoll | ||
|
||
member _.Drop() : unit = | ||
failwith "TODO" | ||
|
||
|
||
[<Struct; NoComparison; StructuralEquality>] | ||
type TaskId = TaskId of int | ||
with member this.Inner() : int = let (TaskId x) = this in x | ||
|
||
type SingleThreadScheduler() = | ||
let syncObj = obj | ||
let mutable disposeCancellationToken = CancellationToken() | ||
|
||
let mutable tasks = List<ISchedulerTask>() | ||
let mutable pollingQueue = Queue<ISchedulerTask>() | ||
|
||
|
||
|
||
module SingleThreadScheduler = | ||
() |
Oops, something went wrong.