thread.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  4. */
  5. #ifndef BX_THREAD_H_HEADER_GUARD
  6. #define BX_THREAD_H_HEADER_GUARD
  7. #include "bx.h"
  8. #include "semaphore.h"
  9. namespace bx
  10. {
  11. ///
  12. typedef int32_t (*ThreadFn)(void* _userData);
  13. ///
  14. class Thread
  15. {
  16. BX_CLASS(Thread
  17. , NO_COPY
  18. , NO_ASSIGNMENT
  19. );
  20. public:
  21. ///
  22. Thread();
  23. ///
  24. virtual ~Thread();
  25. ///
  26. void init(ThreadFn _fn, void* _userData = NULL, uint32_t _stackSize = 0, const char* _name = NULL);
  27. ///
  28. void shutdown();
  29. ///
  30. bool isRunning() const;
  31. ///
  32. int32_t getExitCode() const;
  33. ///
  34. void setThreadName(const char* _name);
  35. private:
  36. friend struct ThreadInternal;
  37. int32_t entry();
  38. BX_ALIGN_DECL(16, uint8_t) m_internal[64];
  39. ThreadFn m_fn;
  40. void* m_userData;
  41. Semaphore m_sem;
  42. uint32_t m_stackSize;
  43. int32_t m_exitCode;
  44. bool m_running;
  45. };
  46. ///
  47. class TlsData
  48. {
  49. public:
  50. ///
  51. TlsData();
  52. ///
  53. ~TlsData();
  54. ///
  55. void* get() const;
  56. ///
  57. void set(void* _ptr);
  58. private:
  59. BX_ALIGN_DECL(16, uint8_t) m_internal[64];
  60. };
  61. } // namespace bx
  62. #endif // BX_THREAD_H_HEADER_GUARD