blob: 4c39884b4fe0aa00e20523c177092d24724679f4 [file] [log] [blame]
Pierre Ossman687d52c2015-11-12 12:16:08 +01001/* 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 Ossmanf0812682016-07-07 15:35:45 +020020#define __OS_THREAD_H__
Pierre Ossman687d52c2015-11-12 12:16:08 +010021
Pierre Ossmanff872612016-07-07 15:35:57 +020022#include <stddef.h>
23
Pierre Ossman687d52c2015-11-12 12:16:08 +010024namespace 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 Ossman7b63a7c2015-11-13 14:07:52 +010037 public:
38 static size_t getSystemCPUCount();
39
Pierre Ossman687d52c2015-11-12 12:16:08 +010040 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