Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.5 KiB

  1. #include <process.h>
  2. #include "PassportThread.hpp"
  3. #include "PassportAssert.hpp"
  4. static DWORD WINAPI threadRunner(void* lpvThreadParam)
  5. {
  6. ((PassportThread*) lpvThreadParam)->run();
  7. return 0; // is this right/okay??
  8. }
  9. bool PassportThread::start()
  10. {
  11. // mHandle = (HANDLE) _beginthreadex(NULL, 0, &threadRunner, (void*) this,
  12. // 0, &mThreadID);
  13. mHandle = CreateThread(NULL,
  14. 0,
  15. threadRunner,
  16. (void*)this,
  17. 0,
  18. &mThreadID);
  19. if (mHandle == NULL)
  20. return false;
  21. else
  22. return true;
  23. }
  24. PassportThread::PassportThread()
  25. :mThreadID(0), mHandle(NULL)
  26. {
  27. //empty
  28. }
  29. DWORD PassportThread::threadID()
  30. {
  31. return mThreadID;
  32. }
  33. PassportThread::~PassportThread()
  34. {
  35. if (mHandle)
  36. CloseHandle(mHandle);
  37. }
  38. bool PassportThread::join(PassportThread* threads[], int size)
  39. {
  40. HANDLE* handles = new HANDLE[size];
  41. if (handles == NULL)
  42. {
  43. return false;
  44. }
  45. for (int i = 0 ; i < size ; i++)
  46. {
  47. PassportAssert(threads[i] != NULL);
  48. handles[i] = threads[i]->mHandle;
  49. }
  50. bool success = (WaitForMultipleObjects(size, handles, TRUE, INFINITE) != WAIT_FAILED);
  51. delete[] handles;
  52. return success;
  53. }
  54. void PassportThread::sleep(long milliseconds)
  55. {
  56. Sleep(milliseconds);
  57. }
  58. DWORD PassportThread::currentThreadID()
  59. {
  60. return GetCurrentThreadId();
  61. }