Thread_VX.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // Thread_VX.h
  3. //
  4. // Library: Foundation
  5. // Package: Threading
  6. // Module: Thread
  7. //
  8. // Definition of the ThreadImpl class for VxWorks tasks.
  9. //
  10. // Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_Thread_VX_INCLUDED
  16. #define Foundation_Thread_VX_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include "Poco/Runnable.h"
  19. #include "Poco/SignalHandler.h"
  20. #include "Poco/Event.h"
  21. #include "Poco/RefCountedObject.h"
  22. #include "Poco/AutoPtr.h"
  23. #include <taskLib.h>
  24. #include <taskVarLib.h>
  25. namespace Poco {
  26. class Foundation_API ThreadImpl
  27. {
  28. public:
  29. typedef int TIDImpl;
  30. typedef void (*Callable)(void*);
  31. enum Priority
  32. {
  33. PRIO_LOWEST_IMPL,
  34. PRIO_LOW_IMPL,
  35. PRIO_NORMAL_IMPL,
  36. PRIO_HIGH_IMPL,
  37. PRIO_HIGHEST_IMPL
  38. };
  39. enum Policy
  40. {
  41. POLICY_DEFAULT_IMPL = 0
  42. };
  43. enum
  44. {
  45. DEFAULT_THREAD_STACK_SIZE = 65536
  46. };
  47. struct CallbackData: public RefCountedObject
  48. {
  49. CallbackData(): callback(0), pData(0)
  50. {
  51. }
  52. Callable callback;
  53. void* pData;
  54. };
  55. ThreadImpl();
  56. ~ThreadImpl();
  57. TIDImpl tidImpl() const;
  58. void setPriorityImpl(int prio);
  59. int getPriorityImpl() const;
  60. void setOSPriorityImpl(int prio, int policy = 0);
  61. int getOSPriorityImpl() const;
  62. static int getMinOSPriorityImpl(int policy);
  63. static int getMaxOSPriorityImpl(int policy);
  64. void setStackSizeImpl(int size);
  65. int getStackSizeImpl() const;
  66. void startImpl(Runnable& target);
  67. void startImpl(Callable target, void* pData = 0);
  68. void joinImpl();
  69. bool joinImpl(long milliseconds);
  70. bool isRunningImpl() const;
  71. static void sleepImpl(long milliseconds);
  72. static void yieldImpl();
  73. static ThreadImpl* currentImpl();
  74. static TIDImpl currentTidImpl();
  75. protected:
  76. static void runnableEntry(void* pThread, int, int, int, int, int, int, int, int, int);
  77. static void callableEntry(void* pThread, int, int, int, int, int, int, int, int, int);
  78. static int mapPrio(int prio);
  79. static int reverseMapPrio(int osPrio);
  80. struct ThreadData: public RefCountedObject
  81. {
  82. ThreadData():
  83. pRunnableTarget(0),
  84. pCallbackTarget(0),
  85. task(0),
  86. prio(PRIO_NORMAL_IMPL),
  87. osPrio(127),
  88. done(false),
  89. stackSize(POCO_THREAD_STACK_SIZE)
  90. {
  91. }
  92. Runnable* pRunnableTarget;
  93. AutoPtr<CallbackData> pCallbackTarget;
  94. int task;
  95. int prio;
  96. int osPrio;
  97. Event done;
  98. int stackSize;
  99. };
  100. private:
  101. AutoPtr<ThreadData> _pData;
  102. static ThreadImpl* _pCurrent;
  103. };
  104. //
  105. // inlines
  106. //
  107. inline int ThreadImpl::getPriorityImpl() const
  108. {
  109. return _pData->prio;
  110. }
  111. inline int ThreadImpl::getOSPriorityImpl() const
  112. {
  113. return _pData->osPrio;
  114. }
  115. inline bool ThreadImpl::isRunningImpl() const
  116. {
  117. return _pData->pRunnableTarget != 0 ||
  118. (_pData->pCallbackTarget.get() != 0 && _pData->pCallbackTarget->callback != 0);
  119. }
  120. inline void ThreadImpl::yieldImpl()
  121. {
  122. taskDelay(0);
  123. }
  124. inline int ThreadImpl::getStackSizeImpl() const
  125. {
  126. return _pData->stackSize;
  127. }
  128. inline ThreadImpl::TIDImpl ThreadImpl::tidImpl() const
  129. {
  130. return _pData->task;
  131. }
  132. } // namespace Poco
  133. #endif // Foundation_Thread_VX_INCLUDED