ThreadPool.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. struct Il2CppObject;
  4. struct Il2CppDelegate;
  5. struct Il2CppAsyncResult;
  6. #if NET_4_0
  7. /* Keep in sync with System.IOOperation in mcs/class/System/System/IOSelector.cs */
  8. enum Il2CppIOOperation
  9. {
  10. EVENT_IN = 1 << 0,
  11. EVENT_OUT = 1 << 1,
  12. EVENT_ERR = 1 << 2, /* not in managed */
  13. };
  14. #endif
  15. namespace il2cpp
  16. {
  17. namespace vm
  18. {
  19. class LIBIL2CPP_CODEGEN_API ThreadPool
  20. {
  21. public:
  22. struct Configuration
  23. {
  24. int minThreads;
  25. int maxThreads;
  26. int minAsyncIOThreads;
  27. int maxAsyncIOThreads;
  28. // These are read-only.
  29. int availableThreads;
  30. int availableAsyncIOThreads;
  31. };
  32. #if NET_4_0
  33. typedef struct
  34. {
  35. bool(*init)(int wakeup_pipe_fd);
  36. void(*register_fd)(int fd, int events, bool is_new);
  37. void(*remove_fd)(int fd);
  38. int(*event_wait)(void(*callback)(int fd, int events, void* user_data), void* user_data);
  39. } ThreadPoolIOBackend;
  40. #endif
  41. static void Initialize();
  42. static void Shutdown();
  43. /// On a thread, call the given delegate with 'params' as arguments. Upon completion,
  44. /// call 'asyncCallback'.
  45. static Il2CppAsyncResult* Queue(Il2CppDelegate* delegate, void** params, Il2CppDelegate* asyncCallback, Il2CppObject* state);
  46. /// Wait for the execution of the given asynchronous call to have completed and return
  47. /// the value returned by the delegate wrapped in the call (or null if the delegate has
  48. /// a void return type).
  49. /// NOTE: Any AsyncResult can only be waited on once! Repeated or concurrent calls to Wait() on the same AsyncResult
  50. /// will throw InvalidOperationExceptions.
  51. static Il2CppObject* Wait(Il2CppAsyncResult* asyncResult, void** outArgs);
  52. static Configuration GetConfiguration();
  53. static void SetConfiguration(const Configuration& configuration);
  54. };
  55. } /* namespace vm */
  56. } /* namespace il2cpp */