pthread_thread.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // pthread_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__pthread_thread__
  9. #define __threadpp__pthread_thread__
  10. #include <pthread.h>
  11. namespace threadpp
  12. {
  13. class pthread_thread
  14. {
  15. struct pthread_context
  16. {
  17. void(*fp)(void* context);
  18. void* context;
  19. } _context;
  20. pthread_t _thread;
  21. pthread_thread(){};
  22. void operator=(const pthread_thread& t){};
  23. pthread_thread(const pthread_thread& t){};
  24. static void* pthread_fp_delegate(void*);
  25. public:
  26. typedef void (*runnable)(void* ctx);
  27. typedef unsigned long long id_type;
  28. static id_type null_id();
  29. pthread_thread(runnable r,void* t);
  30. ~pthread_thread();
  31. void join();
  32. void detach();
  33. bool is_equal(const pthread_thread& t) const;
  34. id_type get_id() const;
  35. static id_type current_thread_id();
  36. static void sleep(unsigned long millisecs);
  37. };
  38. }
  39. #include "pthread_thread.hpp"
  40. #endif /* defined(__threadpp__pthread_thread__) */