win_thread.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // win_thread.h
  3. // threadpp
  4. //
  5. // Created by Melo Yao on 1/15/15.
  6. // Copyright (c) 2015 Melo Yao. All rights reserved.
  7. //
  8. #ifndef __threadpp__win_thread__
  9. #define __threadpp__win_thread__
  10. #include <windows.h>
  11. namespace threadpp
  12. {
  13. class win_thread
  14. {
  15. struct win_context
  16. {
  17. void(*fp)(void*);
  18. void* context;
  19. } _context;
  20. #if NO_CRT
  21. typedef DWORD handle_t;
  22. #else
  23. typedef unsigned handle_t;
  24. #endif
  25. static handle_t __stdcall win_fp_delegate(void* context);
  26. handle_t _thread_id;
  27. HANDLE _handle;
  28. win_thread(){};
  29. void operator=(const win_thread& t){};
  30. win_thread(const win_thread& t){};
  31. public:
  32. typedef void (*runnable)(void* ctx);
  33. typedef unsigned int id_type;
  34. static id_type null_id();
  35. win_thread(runnable r,void* t);
  36. ~win_thread();
  37. void join();
  38. void detach();
  39. bool is_equal(const win_thread& t) const;
  40. id_type get_id() const;
  41. static id_type current_thread_id();
  42. static void sleep(unsigned long millisecs);
  43. };
  44. }
  45. #include "win_thread.hpp"
  46. #endif /* defined(__threadpp__win_thread__) */