GlistEngine
Loading...
Searching...
No Matches
gThread.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Nitra Games Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef UTILS_GTHREAD_H_
18#define UTILS_GTHREAD_H_
19
20#include <thread>
21#include <mutex>
22#include <functional>
23#include <condition_variable>
24#include <chrono>
25#include "gObject.h"
26
27
28class gThread: public gObject {
29public:
31 virtual ~gThread();
32
33 std::thread::id getId() const;
34 bool isRunning();
35 bool isCurrent();
36 bool isDone();
37 std::thread& getThread();
38
39 void start();
40 void stop();
41
42 bool lock();
43 bool tryLock();
44 void unlock();
45
46 void wait();
47 void sleep(std::chrono::duration<double, std::milli> milliseconds);
48 void sleep(double milliseconds);
49 void yield();
50 void detach();
51
52 virtual void threadFunction();
53
54protected:
55 std::condition_variable conditionvariable;
56 mutable std::mutex mutex;
57 bool isdone;
59
60private:
61 std::thread thread;
62 std::chrono::high_resolution_clock::time_point starttime;
63 std::chrono::duration<double, std::milli> timediff;
64
65 void run();
66};
67
68#endif /* UTILS_GTHREAD_H_ */
Definition gObject.h:33
Definition gThread.h:28
bool isrunning
Definition gThread.h:58
virtual ~gThread()
void unlock()
std::thread::id getId() const
bool isdone
Definition gThread.h:57
void start()
virtual void threadFunction()
std::mutex mutex
Definition gThread.h:56
bool isDone()
void wait()
bool isCurrent()
std::thread & getThread()
void stop()
void yield()
bool lock()
void detach()
void sleep(std::chrono::duration< double, std::milli > milliseconds)
bool isRunning()
bool tryLock()
std::condition_variable conditionvariable
Definition gThread.h:55
void sleep(double milliseconds)