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.

Thread.h 1.3KB

11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright (C) 2006-2011 Nasca Octavian Paul
  3. Author: Nasca Octavian Paul
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License
  6. as published by the Free Software Foundation.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License (version 2) for more details.
  11. You should have received a copy of the GNU General Public License (version 2)
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #ifndef THREAD_H
  16. #define THREAD_H
  17. #ifdef WINDOWS
  18. #include <windows.h>
  19. #include <winbase.h>
  20. #else
  21. #include <pthread.h>
  22. #endif
  23. class Thread{
  24. public:
  25. Thread();
  26. ~Thread();
  27. bool start();
  28. void stop();
  29. bool is_running();
  30. virtual void run()=0;
  31. protected:
  32. bool stopnow;//daca dau stop, atunci stop-now este true
  33. private:
  34. #ifdef WINDOWS
  35. friend DWORD WINAPI thread_function( LPVOID arg );
  36. #else
  37. friend void *thread_function(void *arg);
  38. #endif
  39. bool running;
  40. bool stopped;
  41. #ifdef WINDOWS
  42. HANDLE hThread;
  43. #else
  44. pthread_t thread;
  45. #endif
  46. };
  47. #endif