WorkQueue.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. // WARNING - AUTOGENERATED - DO NOT EDIT
  2. //
  3. // Generated using `sharpie urho`
  4. //
  5. // WorkQueue.cs
  6. //
  7. // Copyright 2015 Xamarin Inc. All rights reserved.
  8. using System;
  9. using System.Runtime.InteropServices;
  10. using System.Collections.Generic;
  11. using Urho.Urho2D;
  12. using Urho.Gui;
  13. using Urho.Resources;
  14. using Urho.IO;
  15. using Urho.Navigation;
  16. using Urho.Network;
  17. namespace Urho
  18. {
  19. /// <summary>
  20. /// Work queue subsystem for multithreading.
  21. /// </summary>
  22. public unsafe partial class WorkQueue : UrhoObject
  23. {
  24. unsafe partial void OnWorkQueueCreated ();
  25. [Preserve]
  26. public WorkQueue (IntPtr handle) : base (handle)
  27. {
  28. OnWorkQueueCreated ();
  29. }
  30. [Preserve]
  31. protected WorkQueue (UrhoObjectFlag emptyFlag) : base (emptyFlag)
  32. {
  33. OnWorkQueueCreated ();
  34. }
  35. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  36. internal static extern int WorkQueue_GetType (IntPtr handle);
  37. private StringHash UrhoGetType ()
  38. {
  39. Runtime.ValidateRefCounted (this);
  40. return new StringHash (WorkQueue_GetType (handle));
  41. }
  42. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  43. internal static extern IntPtr WorkQueue_GetTypeName (IntPtr handle);
  44. private string GetTypeName ()
  45. {
  46. Runtime.ValidateRefCounted (this);
  47. return Marshal.PtrToStringAnsi (WorkQueue_GetTypeName (handle));
  48. }
  49. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  50. internal static extern int WorkQueue_GetTypeStatic ();
  51. private static StringHash GetTypeStatic ()
  52. {
  53. Runtime.Validate (typeof(WorkQueue));
  54. return new StringHash (WorkQueue_GetTypeStatic ());
  55. }
  56. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  57. internal static extern IntPtr WorkQueue_GetTypeNameStatic ();
  58. private static string GetTypeNameStatic ()
  59. {
  60. Runtime.Validate (typeof(WorkQueue));
  61. return Marshal.PtrToStringAnsi (WorkQueue_GetTypeNameStatic ());
  62. }
  63. [Preserve]
  64. public WorkQueue () : this (Application.CurrentContext)
  65. {
  66. }
  67. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  68. internal static extern IntPtr WorkQueue_WorkQueue (IntPtr context);
  69. [Preserve]
  70. public WorkQueue (Context context) : base (UrhoObjectFlag.Empty)
  71. {
  72. Runtime.Validate (typeof(WorkQueue));
  73. handle = WorkQueue_WorkQueue ((object)context == null ? IntPtr.Zero : context.Handle);
  74. Runtime.RegisterObject (this);
  75. OnWorkQueueCreated ();
  76. }
  77. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  78. internal static extern void WorkQueue_CreateThreads (IntPtr handle, uint numThreads);
  79. /// <summary>
  80. /// Create worker threads. Can only be called once.
  81. /// </summary>
  82. public void CreateThreads (uint numThreads)
  83. {
  84. Runtime.ValidateRefCounted (this);
  85. WorkQueue_CreateThreads (handle, numThreads);
  86. }
  87. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  88. internal static extern WorkItem WorkQueue_GetFreeItem (IntPtr handle);
  89. /// <summary>
  90. /// Get pointer to an usable WorkItem from the item pool. Allocate one if no more free items.
  91. /// </summary>
  92. private WorkItem GetFreeItem ()
  93. {
  94. Runtime.ValidateRefCounted (this);
  95. return WorkQueue_GetFreeItem (handle);
  96. }
  97. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  98. internal static extern void WorkQueue_Pause (IntPtr handle);
  99. /// <summary>
  100. /// Pause worker threads.
  101. /// </summary>
  102. public void Pause ()
  103. {
  104. Runtime.ValidateRefCounted (this);
  105. WorkQueue_Pause (handle);
  106. }
  107. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  108. internal static extern void WorkQueue_Resume (IntPtr handle);
  109. /// <summary>
  110. /// Resume worker threads.
  111. /// </summary>
  112. public void Resume ()
  113. {
  114. Runtime.ValidateRefCounted (this);
  115. WorkQueue_Resume (handle);
  116. }
  117. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  118. internal static extern void WorkQueue_Complete (IntPtr handle, uint priority);
  119. /// <summary>
  120. /// Finish all queued work which has at least the specified priority. Main thread will also execute priority work. Pause worker threads if no more work remains.
  121. /// </summary>
  122. public void Complete (uint priority)
  123. {
  124. Runtime.ValidateRefCounted (this);
  125. WorkQueue_Complete (handle, priority);
  126. }
  127. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  128. internal static extern void WorkQueue_SetTolerance (IntPtr handle, int tolerance);
  129. /// <summary>
  130. /// Set the pool telerance before it starts deleting pool items.
  131. /// </summary>
  132. private void SetTolerance (int tolerance)
  133. {
  134. Runtime.ValidateRefCounted (this);
  135. WorkQueue_SetTolerance (handle, tolerance);
  136. }
  137. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  138. internal static extern void WorkQueue_SetNonThreadedWorkMs (IntPtr handle, int ms);
  139. /// <summary>
  140. /// Set how many milliseconds maximum per frame to spend on low-priority work, when there are no worker threads.
  141. /// </summary>
  142. private void SetNonThreadedWorkMs (int ms)
  143. {
  144. Runtime.ValidateRefCounted (this);
  145. WorkQueue_SetNonThreadedWorkMs (handle, ms);
  146. }
  147. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  148. internal static extern uint WorkQueue_GetNumThreads (IntPtr handle);
  149. /// <summary>
  150. /// Return number of worker threads.
  151. /// </summary>
  152. private uint GetNumThreads ()
  153. {
  154. Runtime.ValidateRefCounted (this);
  155. return WorkQueue_GetNumThreads (handle);
  156. }
  157. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  158. internal static extern bool WorkQueue_IsCompleted (IntPtr handle, uint priority);
  159. /// <summary>
  160. /// Return whether all work with at least the specified priority is finished.
  161. /// </summary>
  162. public bool IsCompleted (uint priority)
  163. {
  164. Runtime.ValidateRefCounted (this);
  165. return WorkQueue_IsCompleted (handle, priority);
  166. }
  167. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  168. internal static extern bool WorkQueue_IsCompleting (IntPtr handle);
  169. /// <summary>
  170. /// Return whether the queue is currently completing work in the main thread.
  171. /// </summary>
  172. private bool IsCompleting ()
  173. {
  174. Runtime.ValidateRefCounted (this);
  175. return WorkQueue_IsCompleting (handle);
  176. }
  177. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  178. internal static extern int WorkQueue_GetTolerance (IntPtr handle);
  179. /// <summary>
  180. /// Return the pool tolerance.
  181. /// </summary>
  182. private int GetTolerance ()
  183. {
  184. Runtime.ValidateRefCounted (this);
  185. return WorkQueue_GetTolerance (handle);
  186. }
  187. [DllImport (Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  188. internal static extern int WorkQueue_GetNonThreadedWorkMs (IntPtr handle);
  189. /// <summary>
  190. /// Return how many milliseconds maximum to spend on non-threaded low-priority work.
  191. /// </summary>
  192. private int GetNonThreadedWorkMs ()
  193. {
  194. Runtime.ValidateRefCounted (this);
  195. return WorkQueue_GetNonThreadedWorkMs (handle);
  196. }
  197. public override StringHash Type {
  198. get {
  199. return UrhoGetType ();
  200. }
  201. }
  202. public override string TypeName {
  203. get {
  204. return GetTypeName ();
  205. }
  206. }
  207. [Preserve]
  208. public static StringHash TypeStatic {
  209. get {
  210. return GetTypeStatic ();
  211. }
  212. }
  213. public static string TypeNameStatic {
  214. get {
  215. return GetTypeNameStatic ();
  216. }
  217. }
  218. /// <summary>
  219. /// Get pointer to an usable WorkItem from the item pool. Allocate one if no more free items.
  220. /// </summary>
  221. public WorkItem FreeItem {
  222. get {
  223. return GetFreeItem ();
  224. }
  225. }
  226. /// <summary>
  227. /// Return the pool tolerance.
  228. /// Or
  229. /// Set the pool telerance before it starts deleting pool items.
  230. /// </summary>
  231. public int Tolerance {
  232. get {
  233. return GetTolerance ();
  234. }
  235. set {
  236. SetTolerance (value);
  237. }
  238. }
  239. /// <summary>
  240. /// Return how many milliseconds maximum to spend on non-threaded low-priority work.
  241. /// Or
  242. /// Set how many milliseconds maximum per frame to spend on low-priority work, when there are no worker threads.
  243. /// </summary>
  244. public int NonThreadedWorkMs {
  245. get {
  246. return GetNonThreadedWorkMs ();
  247. }
  248. set {
  249. SetNonThreadedWorkMs (value);
  250. }
  251. }
  252. /// <summary>
  253. /// Return number of worker threads.
  254. /// </summary>
  255. public uint NumThreads {
  256. get {
  257. return GetNumThreads ();
  258. }
  259. }
  260. /// <summary>
  261. /// Return whether the queue is currently completing work in the main thread.
  262. /// </summary>
  263. public bool Completing {
  264. get {
  265. return IsCompleting ();
  266. }
  267. }
  268. }
  269. }