-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathos_qt.cpp
56 lines (50 loc) · 1.03 KB
/
os_qt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* os_qt.cpp
*
* (C) Copyright 2014 Ulrich Hecht
*
* This file is part of CASCADE. CASCADE is almost free software; you can
* redistribute it and/or modify it under the terms of the Cascade Public
* License 1.0. Read the file "LICENSE" for details.
*/
#include "os.h"
#include <QtConcurrentRun>
class OsThread : public QThread
{
public:
OsThread(int (*fun)(void *), void *data) : QThread() {
this->fun = fun;
this->data = data;
}
void run() {
res = fun(data);
}
int result() {
return res;
}
private:
int (*fun)(void *);
void *data;
int res;
};
void *os_create_thread(int (*fn)(void *), void *data)
{
OsThread *thr = new OsThread(fn, data);
thr->start();
return (void *)thr;
}
void os_wait_thread(void *thread, int *status)
{
OsThread *thr = (OsThread *)thread;
thr->wait();
if (status)
*status = thr->result();
}
void os_kill_thread(void *thread, int *status)
{
OsThread *thr = (OsThread *)thread;
thr->terminate();
thr->wait();
if (status)
*status = thr->result();
}