ThreadPool.h 2.0 KB

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