Pierre Ossman | 687d52c | 2015-11-12 12:16:08 +0100 | [diff] [blame] | 1 | /* Copyright 2015 Pierre Ossman for Cendio AB |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __OS_THREAD_H__ |
Pierre Ossman | f081268 | 2016-07-07 15:35:45 +0200 | [diff] [blame] | 20 | #define __OS_THREAD_H__ |
Pierre Ossman | 687d52c | 2015-11-12 12:16:08 +0100 | [diff] [blame] | 21 | |
Pierre Ossman | ff87261 | 2016-07-07 15:35:57 +0200 | [diff] [blame^] | 22 | #include <stddef.h> |
| 23 | |
Pierre Ossman | 687d52c | 2015-11-12 12:16:08 +0100 | [diff] [blame] | 24 | namespace os { |
| 25 | class Mutex; |
| 26 | |
| 27 | class Thread { |
| 28 | public: |
| 29 | Thread(); |
| 30 | virtual ~Thread(); |
| 31 | |
| 32 | void start(); |
| 33 | void wait(); |
| 34 | |
| 35 | bool isRunning(); |
| 36 | |
Pierre Ossman | 7b63a7c | 2015-11-13 14:07:52 +0100 | [diff] [blame] | 37 | public: |
| 38 | static size_t getSystemCPUCount(); |
| 39 | |
Pierre Ossman | 687d52c | 2015-11-12 12:16:08 +0100 | [diff] [blame] | 40 | protected: |
| 41 | virtual void worker() = 0; |
| 42 | |
| 43 | private: |
| 44 | #ifdef WIN32 |
| 45 | static long unsigned __stdcall startRoutine(void* data); |
| 46 | #else |
| 47 | static void* startRoutine(void* data); |
| 48 | #endif |
| 49 | |
| 50 | private: |
| 51 | Mutex *mutex; |
| 52 | bool running; |
| 53 | |
| 54 | void *threadId; |
| 55 | }; |
| 56 | } |
| 57 | |
| 58 | #endif |