NvThreadConfig.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef NV_THREAD_CONFIG_H
  2. #define NV_THREAD_CONFIG_H
  3. #include "NvUserMemAlloc.h"
  4. /*
  5. NvThreadConfig.h : A simple wrapper class to define threading and mutex locks.
  6. */
  7. /*!
  8. **
  9. ** Copyright (c) 2009 by John W. Ratcliff mailto:[email protected]
  10. **
  11. ** Portions of this source has been released with the PhysXViewer application, as well as
  12. ** Rocket, CreateDynamics, ODF, and as a number of sample code snippets.
  13. **
  14. ** If you find this code useful or you are feeling particularily generous I would
  15. ** ask that you please go to http://www.amillionpixels.us and make a donation
  16. ** to Troy DeMolay.
  17. **
  18. ** DeMolay is a youth group for young men between the ages of 12 and 21.
  19. ** It teaches strong moral principles, as well as leadership skills and
  20. ** public speaking. The donations page uses the 'pay for pixels' paradigm
  21. ** where, in this case, a pixel is only a single penny. Donations can be
  22. ** made for as small as $4 or as high as a $100 block. Each person who donates
  23. ** will get a link to their own site as well as acknowledgement on the
  24. ** donations blog located here http://www.amillionpixels.blogspot.com/
  25. **
  26. ** If you wish to contact me you can use the following methods:
  27. **
  28. ** Skype ID: jratcliff63367
  29. ** Yahoo: jratcliff63367
  30. ** AOL: jratcliff1961
  31. ** email: [email protected]
  32. **
  33. **
  34. ** The MIT license:
  35. **
  36. ** Permission is hereby granted, free of charge, to any person obtaining a copy
  37. ** of this software and associated documentation files (the "Software"), to deal
  38. ** in the Software without restriction, including without limitation the rights
  39. ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  40. ** copies of the Software, and to permit persons to whom the Software is furnished
  41. ** to do so, subject to the following conditions:
  42. **
  43. ** The above copyright notice and this permission notice shall be included in all
  44. ** copies or substantial portions of the Software.
  45. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  46. ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  47. ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  48. ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  49. ** WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  50. ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  51. */
  52. #ifdef _MSC_VER
  53. typedef __int64 int64_t;
  54. #else
  55. #include <stdint.h>
  56. #endif
  57. namespace CONVEX_DECOMPOSITION
  58. {
  59. NxU32 tc_timeGetTime(void);
  60. void tc_sleep(NxU32 ms);
  61. void tc_spinloop();
  62. void tc_interlockedExchange(void *dest, const int64_t exchange);
  63. NxI32 tc_interlockedCompareExchange(void *dest, NxI32 exchange, NxI32 compare);
  64. NxI32 tc_interlockedCompareExchange(void *dest, const NxI32 exchange1, const NxI32 exchange2, const NxI32 compare1, const NxI32 compare2);
  65. class ThreadMutex
  66. {
  67. public:
  68. virtual void lock(void) = 0;
  69. virtual void unlock(void) = 0;
  70. virtual bool tryLock(void) = 0;
  71. };
  72. ThreadMutex * tc_createThreadMutex(void);
  73. void tc_releaseThreadMutex(ThreadMutex *tm);
  74. class ThreadInterface
  75. {
  76. public:
  77. virtual void threadMain(void) = 0;
  78. };
  79. class Thread
  80. {
  81. public:
  82. };
  83. Thread * tc_createThread(ThreadInterface *tinterface);
  84. void tc_releaseThread(Thread *t);
  85. class ThreadEvent
  86. {
  87. public:
  88. virtual void setEvent(void) = 0; // signal the event
  89. virtual void resetEvent(void) = 0;
  90. virtual void waitForSingleObject(NxU32 ms) = 0;
  91. };
  92. ThreadEvent * tc_createThreadEvent(void);
  93. void tc_releaseThreadEvent(ThreadEvent *t);
  94. }; // end of namespace
  95. #endif