C# Class HikariThreading.Hikari

Never put Hikari on a GameObject! Hikari will spawn one for you. Hikari is the entry point to the threading system. It is fully threadsafe and designed to be accessed statically. To schedule a task in Hikari use the following code: Hikari.Schedule( ( ActionTask task ) => YourWorkHere(); ) To schedule a task in Unity use the following code: Hikari.ScheduleUnity( ( ActionTask task ) => YourWorkHere(); ) You may also schedule tasks using enumerators, similar to coroutines in Unity.
Inheritance: UnityEngine.MonoBehaviour
显示文件 Open project: ReinAkane/Hikari Class Usage Examples

Private Properties

Property Type Description
RequeueTask void
Start void
StartSpawn UnityEngine.GameObject
Update void

Public Methods

Method Description
Schedule ( Action to_schedule, bool cancel_extensions_on_abort = true ) : ActionTask

Schedules a task to be run in Hikari.

Schedule ( System to_schedule, bool cancel_extensions_on_abort = true ) : EnumeratorTask

Schedules a task to be run in Hikari. Enumerator tasks may yield null to allow napping, or yield another Task to nap until that task finishes, then start up again.

ScheduleUnity ( Action to_schedule, bool cancel_extensions_on_abort = true ) : ActionTask

Schedules a task to be run on Unity's thread.

ScheduleUnity ( System to_schedule, bool cancel_extensions_on_abort = true ) : EnumeratorTask

Schedules a task to be run on Unity's thread. Enumerator tasks may yield null to allow napping, or yield another Task to nap until that task finishes, then start up again.

Spawn ( ) : UnityEngine.GameObject

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.

Spawn ( int max_tasks_per_frame ) : UnityEngine.GameObject

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.

Spawn ( int min_threads, int max_threads ) : UnityEngine.GameObject

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.

Spawn ( int max_tasks_per_frame, int min_threads, int max_threads ) : UnityEngine.GameObject

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.

Spawn ( int max_tasks_per_frame, int min_threads, int max_threads, System.TimeSpan min_ms_between_thread_spawn, System.TimeSpan max_ms_task_waiting_before_thread_spawn, uint max_queue_length_before_thread_spawn, System.TimeSpan max_boredom_time_before_thread_despawn ) : UnityEngine.GameObject

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.

Spawn ( ) : void
SpawnDedicatedTask ( Action task, bool cancel_extensions_on_abort = true ) : ActionTask

Creates a dedicated task and a thread for it. Dedicated tasks will not relinquish control of their thread while napping, allowing them to restart immediately after napping. Once the task has completed, its thread will be recycled in Hikari and may be used for other tasks.

SpawnDedicatedTask ( System task, bool cancel_extensions_on_abort = true ) : EnumeratorTask

Creates a dedicated task and a thread for it. Dedicated tasks will not relinquish control of their thread while napping, allowing them to restart immediately after napping. Once the task has completed, its thread will be recycled in Hikari and may be used for other tasks. Enumerator tasks may yield null to allow napping, or yield another Task to nap until that task finishes, then start up again.

Private Methods

Method Description
RequeueTask ( ITask task ) : void

Re-enters the passed Task into the Thread- or UnityManager (based on which it started in). This should only be called when the Task is already completed.

Start ( ) : void

Failsafe so that no one accidentally creates a Hikari object.

StartSpawn ( ) : UnityEngine.GameObject

This does the reusable parts of the overloaded Spawn() method.

Update ( ) : void

Unity's update loop. All we need to do is update the managers.

Method Details

Schedule() public static method

Schedules a task to be run in Hikari.
public static Schedule ( Action to_schedule, bool cancel_extensions_on_abort = true ) : ActionTask
to_schedule Action The method to run in the task.
cancel_extensions_on_abort bool Whether or not to cancel extensions automatically when the Task is aborted. Defaults to true.
return ActionTask

Schedule() public static method

Schedules a task to be run in Hikari. Enumerator tasks may yield null to allow napping, or yield another Task to nap until that task finishes, then start up again.
public static Schedule ( System to_schedule, bool cancel_extensions_on_abort = true ) : EnumeratorTask
to_schedule System The enumerator to run in the task.
cancel_extensions_on_abort bool Whether or not to cancel extensions automatically when the Task is aborted. Defaults to true.
return EnumeratorTask

ScheduleUnity() public static method

Schedules a task to be run on Unity's thread.
public static ScheduleUnity ( Action to_schedule, bool cancel_extensions_on_abort = true ) : ActionTask
to_schedule Action The method to run in the task.
cancel_extensions_on_abort bool Whether or not to cancel extensions automatically when the Task is aborted. Defaults to true.
return ActionTask

ScheduleUnity() public static method

Schedules a task to be run on Unity's thread. Enumerator tasks may yield null to allow napping, or yield another Task to nap until that task finishes, then start up again.
public static ScheduleUnity ( System to_schedule, bool cancel_extensions_on_abort = true ) : EnumeratorTask
to_schedule System The enumerator to run in the task.
cancel_extensions_on_abort bool Whether or not to cancel extensions automatically when the Task is aborted. Defaults to true.
return EnumeratorTask

Spawn() public static method

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.
public static Spawn ( ) : UnityEngine.GameObject
return UnityEngine.GameObject

Spawn() public static method

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.
public static Spawn ( int max_tasks_per_frame ) : UnityEngine.GameObject
max_tasks_per_frame int The maximum number of Tasks for Hikari to run in Unity per frame.
return UnityEngine.GameObject

Spawn() public static method

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.
public static Spawn ( int min_threads, int max_threads ) : UnityEngine.GameObject
min_threads int The minimum number of Threads for Hikari to have spawned at once.
max_threads int The maximum number of Threads for Hikari to have spawned at once. Dedicated Tasks may cause Hikari to go over this maximum.
return UnityEngine.GameObject

Spawn() public static method

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.
public static Spawn ( int max_tasks_per_frame, int min_threads, int max_threads ) : UnityEngine.GameObject
max_tasks_per_frame int The maximum number of Tasks for Hikari to run in Unity per frame.
min_threads int The minimum number of Threads for Hikari to have spawned at once.
max_threads int The maximum number of Threads for Hikari to have spawned at once. Dedicated Tasks may cause Hikari to go over this maximum.
return UnityEngine.GameObject

Spawn() public static method

Starts up Hikari with all the default options. Not necessary to call, but if you don't a GameObject will be spawned the first time you call Hikari. The spawned GameObject will be set to not destroy on load. Spawn is not threadsafe.
public static Spawn ( int max_tasks_per_frame, int min_threads, int max_threads, System.TimeSpan min_ms_between_thread_spawn, System.TimeSpan max_ms_task_waiting_before_thread_spawn, uint max_queue_length_before_thread_spawn, System.TimeSpan max_boredom_time_before_thread_despawn ) : UnityEngine.GameObject
max_tasks_per_frame int The maximum number of Tasks for Hikari to run in Unity per frame.
min_threads int The minimum number of Threads for Hikari to have spawned at once.
max_threads int The maximum number of Threads for Hikari to have spawned at once. Dedicated Tasks may cause Hikari to go over this maximum.
min_ms_between_thread_spawn System.TimeSpan The minimum amount of time to wait before spawning a new thread.
max_ms_task_waiting_before_thread_spawn System.TimeSpan The maximum time that a Task can be waiting in the queue before we spawn a new thread.
max_queue_length_before_thread_spawn uint The maximum number of Tasks waiting in queue before we spawn a new thread.
max_boredom_time_before_thread_despawn System.TimeSpan The maximum amount of time a thread can be idle before despawning the thread.
return UnityEngine.GameObject

Spawn() public static method

public static Spawn ( ) : void
return void

SpawnDedicatedTask() public static method

Creates a dedicated task and a thread for it. Dedicated tasks will not relinquish control of their thread while napping, allowing them to restart immediately after napping. Once the task has completed, its thread will be recycled in Hikari and may be used for other tasks.
public static SpawnDedicatedTask ( Action task, bool cancel_extensions_on_abort = true ) : ActionTask
task Action The action to run on the new dedicated task.
cancel_extensions_on_abort bool Whether or not to cancel extensions automatically when the Task is aborted. Defaults to true.
return ActionTask

SpawnDedicatedTask() public static method

Creates a dedicated task and a thread for it. Dedicated tasks will not relinquish control of their thread while napping, allowing them to restart immediately after napping. Once the task has completed, its thread will be recycled in Hikari and may be used for other tasks. Enumerator tasks may yield null to allow napping, or yield another Task to nap until that task finishes, then start up again.
public static SpawnDedicatedTask ( System task, bool cancel_extensions_on_abort = true ) : EnumeratorTask
task System The enumerator to run on the new dedicated task.
cancel_extensions_on_abort bool Whether or not to cancel extensions automatically when the Task is aborted. Defaults to true.
return EnumeratorTask